1 /* |
1 /* |
2 * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
3 * @LastModified: Sep 2017 |
3 * @LastModified: Oct 2017 |
4 */ |
4 */ |
5 /* |
5 /* |
6 * Licensed to the Apache Software Foundation (ASF) under one or more |
6 * Licensed to the Apache Software Foundation (ASF) under one or more |
7 * contributor license agreements. See the NOTICE file distributed with |
7 * contributor license agreements. See the NOTICE file distributed with |
8 * this work for additional information regarding copyright ownership. |
8 * this work for additional information regarding copyright ownership. |
155 boolean doFallback) |
155 boolean doFallback) |
156 throws ConfigurationError |
156 throws ConfigurationError |
157 { |
157 { |
158 // assert(className != null); |
158 // assert(className != null); |
159 try{ |
159 try{ |
160 Class providerClass = findProviderClass(className, cl, doFallback); |
160 Class<?> providerClass = findProviderClass(className, cl, doFallback); |
161 Object instance = providerClass.getConstructor().newInstance(); |
161 Object instance = providerClass.getConstructor().newInstance(); |
162 debugPrintln(()->"created new instance of " + providerClass + |
162 debugPrintln(()->"created new instance of " + providerClass + |
163 " using ClassLoader: " + cl); |
163 " using ClassLoader: " + cl); |
164 return instance; |
164 return instance; |
165 } catch (ClassNotFoundException x) { |
165 } catch (ClassNotFoundException x) { |
174 |
174 |
175 /** |
175 /** |
176 * Find a Class using the same classloader for the ObjectFactory by default |
176 * Find a Class using the same classloader for the ObjectFactory by default |
177 * or bootclassloader when Security Manager is in place |
177 * or bootclassloader when Security Manager is in place |
178 */ |
178 */ |
179 public static Class findProviderClass(String className, boolean doFallback) |
179 public static Class<?> findProviderClass(String className, boolean doFallback) |
180 throws ClassNotFoundException, ConfigurationError |
180 throws ClassNotFoundException, ConfigurationError |
181 { |
181 { |
182 return findProviderClass (className, |
182 return findProviderClass (className, |
183 findClassLoader (), doFallback); |
183 findClassLoader (), doFallback); |
184 } |
184 } |
185 /** |
185 /** |
186 * Find a Class using the specified ClassLoader |
186 * Find a Class using the specified ClassLoader |
187 */ |
187 */ |
188 public static Class findProviderClass(String className, ClassLoader cl, |
188 public static Class<?> findProviderClass(String className, ClassLoader cl, |
189 boolean doFallback) |
189 boolean doFallback) |
190 throws ClassNotFoundException, ConfigurationError |
190 throws ClassNotFoundException, ConfigurationError |
191 { |
191 { |
192 //throw security exception if the calling thread is not allowed to access the package |
192 //throw security exception if the calling thread is not allowed to access the package |
193 //restrict the access to package as speicified in java.security policy |
193 //restrict the access to package as speicified in java.security policy |
201 String packageName = className; |
201 String packageName = className; |
202 if (lastDot != -1) packageName = className.substring(0, lastDot); |
202 if (lastDot != -1) packageName = className.substring(0, lastDot); |
203 security.checkPackageAccess(packageName); |
203 security.checkPackageAccess(packageName); |
204 } |
204 } |
205 } |
205 } |
206 Class providerClass; |
206 Class<?> providerClass; |
207 if (cl == null) { |
207 if (cl == null) { |
208 //use the bootstrap ClassLoader. |
208 //use the bootstrap ClassLoader. |
209 providerClass = Class.forName(className, false, ObjectFactory.class.getClassLoader()); |
209 providerClass = Class.forName(className, false, ObjectFactory.class.getClassLoader()); |
210 } else { |
210 } else { |
211 try { |
211 try { |