119 * instantiated. The cause will be set to actual Exception
120 *
121 * @see ServiceLoader
122 * @since 1.7
123 */
124 public static RowSetFactory newFactory()
125 throws SQLException {
126 // Use the system property first
127 RowSetFactory factory = null;
128 String factoryClassName = null;
129 try {
130 trace("Checking for Rowset System Property...");
131 factoryClassName = getSystemProperty(ROWSET_FACTORY_NAME);
132 if (factoryClassName != null) {
133 trace("Found system property, value=" + factoryClassName);
134 if (factoryClassName.equals(ROWSET_FACTORY_IMPL)) {
135 return defaultRowSetFactory();
136 }
137 // getFactoryClass takes care of adding the read edge if
138 // necessary
139 Class<?> c = getFactoryClass(factoryClassName, null, false);
140 factory = (RowSetFactory) c.newInstance();
141 }
142 } catch (Exception e) {
143 throw new SQLException( "RowSetFactory: " + factoryClassName +
144 " could not be instantiated: ", e);
145 }
146
147 // Check to see if we found the RowSetFactory via a System property
148 if (factory == null) {
149 // If the RowSetFactory is not found via a System Property, now
150 // look it up via the ServiceLoader API and if not found, use the
151 // Java SE default.
152 factory = loadViaServiceLoader();
153 }
154 return factory == null ? defaultRowSetFactory() : factory;
155 }
156
157 private static RowSetFactory defaultRowSetFactory() {
158 return new com.sun.rowset.RowSetFactoryImpl();
159 }
160
185 * @since 1.7
186 */
187 public static RowSetFactory newFactory(String factoryClassName, ClassLoader cl)
188 throws SQLException {
189
190 trace("***In newInstance()");
191
192 if(factoryClassName == null) {
193 throw new SQLException("Error: factoryClassName cannot be null");
194 }
195 try {
196 ReflectUtil.checkPackageAccess(factoryClassName);
197 } catch (java.security.AccessControlException e) {
198 throw new SQLException("Access Exception",e);
199 }
200
201 try {
202 // getFactoryClass takes care of adding the read edge if
203 // necessary
204 Class<?> providerClass = getFactoryClass(factoryClassName, cl, false);
205 RowSetFactory instance = (RowSetFactory) providerClass.newInstance();
206 if (debug) {
207 trace("Created new instance of " + providerClass +
208 " using ClassLoader: " + cl);
209 }
210 return instance;
211 } catch (ClassNotFoundException x) {
212 throw new SQLException(
213 "Provider " + factoryClassName + " not found", x);
214 } catch (Exception x) {
215 throw new SQLException(
216 "Provider " + factoryClassName + " could not be instantiated: " + x,
217 x);
218 }
219 }
220
221 /*
222 * Returns the class loader to be used.
223 * @return The ClassLoader to use.
224 *
|
119 * instantiated. The cause will be set to actual Exception
120 *
121 * @see ServiceLoader
122 * @since 1.7
123 */
124 public static RowSetFactory newFactory()
125 throws SQLException {
126 // Use the system property first
127 RowSetFactory factory = null;
128 String factoryClassName = null;
129 try {
130 trace("Checking for Rowset System Property...");
131 factoryClassName = getSystemProperty(ROWSET_FACTORY_NAME);
132 if (factoryClassName != null) {
133 trace("Found system property, value=" + factoryClassName);
134 if (factoryClassName.equals(ROWSET_FACTORY_IMPL)) {
135 return defaultRowSetFactory();
136 }
137 // getFactoryClass takes care of adding the read edge if
138 // necessary
139 @SuppressWarnings("deprecation")
140 Object o = getFactoryClass(factoryClassName, null, false).newInstance();
141 factory = (RowSetFactory) o;
142 }
143 } catch (Exception e) {
144 throw new SQLException( "RowSetFactory: " + factoryClassName +
145 " could not be instantiated: ", e);
146 }
147
148 // Check to see if we found the RowSetFactory via a System property
149 if (factory == null) {
150 // If the RowSetFactory is not found via a System Property, now
151 // look it up via the ServiceLoader API and if not found, use the
152 // Java SE default.
153 factory = loadViaServiceLoader();
154 }
155 return factory == null ? defaultRowSetFactory() : factory;
156 }
157
158 private static RowSetFactory defaultRowSetFactory() {
159 return new com.sun.rowset.RowSetFactoryImpl();
160 }
161
186 * @since 1.7
187 */
188 public static RowSetFactory newFactory(String factoryClassName, ClassLoader cl)
189 throws SQLException {
190
191 trace("***In newInstance()");
192
193 if(factoryClassName == null) {
194 throw new SQLException("Error: factoryClassName cannot be null");
195 }
196 try {
197 ReflectUtil.checkPackageAccess(factoryClassName);
198 } catch (java.security.AccessControlException e) {
199 throw new SQLException("Access Exception",e);
200 }
201
202 try {
203 // getFactoryClass takes care of adding the read edge if
204 // necessary
205 Class<?> providerClass = getFactoryClass(factoryClassName, cl, false);
206 @SuppressWarnings("deprecation")
207 RowSetFactory instance = (RowSetFactory) providerClass.newInstance();
208 if (debug) {
209 trace("Created new instance of " + providerClass +
210 " using ClassLoader: " + cl);
211 }
212 return instance;
213 } catch (ClassNotFoundException x) {
214 throw new SQLException(
215 "Provider " + factoryClassName + " not found", x);
216 } catch (Exception x) {
217 throw new SQLException(
218 "Provider " + factoryClassName + " could not be instantiated: " + x,
219 x);
220 }
221 }
222
223 /*
224 * Returns the class loader to be used.
225 * @return The ClassLoader to use.
226 *
|