1 /* 2 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package javax.xml.ws.spi; 27 28 import java.io.*; 29 30 import java.util.Properties; 31 import javax.xml.ws.WebServiceException; 32 33 class FactoryFinder { 34 35 /** 36 * Creates an instance of the specified class using the specified 37 * <code>ClassLoader</code> object. 38 * 39 * @exception WebServiceException if the given class could not be found 40 * or could not be instantiated 41 */ 42 private static Object newInstance(String className, 43 ClassLoader classLoader) 44 { 45 try { 46 Class spiClass = safeLoadClass(className, classLoader); 47 return spiClass.newInstance(); 48 } catch (ClassNotFoundException x) { 49 throw new WebServiceException( 50 "Provider " + className + " not found", x); 51 } catch (Exception x) { 52 throw new WebServiceException( 53 "Provider " + className + " could not be instantiated: " + x, 54 x); 55 } 56 } 57 58 /** 59 * Finds the implementation <code>Class</code> object for the given 60 * factory name, or if that fails, finds the <code>Class</code> object 61 * for the given fallback class name. The arguments supplied MUST be 62 * used in order. If using the first argument is successful, the second 63 * one will not be used. 64 * <P> 65 * This method is package private so that this code can be shared. 66 * 67 * @return the <code>Class</code> object of the specified message factory; 68 * may not be <code>null</code> 69 * 70 * @param factoryId the name of the factory to find, which is 71 * a system property 72 * @param fallbackClassName the implementation class name, which is 73 * to be used only if nothing else 74 * is found; <code>null</code> to indicate that 75 * there is no fallback class name 76 * @exception WebServiceException if there is an error 77 */ 78 static Object find(String factoryId, String fallbackClassName) 79 { 80 if (isOsgi()) { 81 return lookupUsingOSGiServiceLoader(factoryId); 82 } 83 ClassLoader classLoader; 84 try { 85 classLoader = Thread.currentThread().getContextClassLoader(); 86 } catch (Exception x) { 87 throw new WebServiceException(x.toString(), x); 88 } 89 90 String serviceId = "META-INF/services/" + factoryId; 91 // try to find services in CLASSPATH 92 BufferedReader rd = null; 93 try { 94 InputStream is; | 1 /* 2 * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package javax.xml.ws.spi; 27 28 import java.io.*; 29 30 import java.util.Properties; 31 import javax.xml.ws.WebServiceException; 32 33 class FactoryFinder { 34 35 /** 36 * Creates an instance of the specified class using the specified 37 * {@code ClassLoader} object. 38 * 39 * @exception WebServiceException if the given class could not be found 40 * or could not be instantiated 41 */ 42 private static Object newInstance(String className, 43 ClassLoader classLoader) 44 { 45 try { 46 Class spiClass = safeLoadClass(className, classLoader); 47 return spiClass.newInstance(); 48 } catch (ClassNotFoundException x) { 49 throw new WebServiceException( 50 "Provider " + className + " not found", x); 51 } catch (Exception x) { 52 throw new WebServiceException( 53 "Provider " + className + " could not be instantiated: " + x, 54 x); 55 } 56 } 57 58 /** 59 * Finds the implementation {@code Class} object for the given 60 * factory name, or if that fails, finds the {@code Class} object 61 * for the given fallback class name. The arguments supplied MUST be 62 * used in order. If using the first argument is successful, the second 63 * one will not be used. 64 * <P> 65 * This method is package private so that this code can be shared. 66 * 67 * @return the {@code Class} object of the specified message factory; 68 * may not be {@code null} 69 * 70 * @param factoryId the name of the factory to find, which is 71 * a system property 72 * @param fallbackClassName the implementation class name, which is 73 * to be used only if nothing else 74 * is found; {@code null} to indicate that 75 * there is no fallback class name 76 * @exception WebServiceException if there is an error 77 */ 78 static Object find(String factoryId, String fallbackClassName) 79 { 80 if (isOsgi()) { 81 return lookupUsingOSGiServiceLoader(factoryId); 82 } 83 ClassLoader classLoader; 84 try { 85 classLoader = Thread.currentThread().getContextClassLoader(); 86 } catch (Exception x) { 87 throw new WebServiceException(x.toString(), x); 88 } 89 90 String serviceId = "META-INF/services/" + factoryId; 91 // try to find services in CLASSPATH 92 BufferedReader rd = null; 93 try { 94 InputStream is; |