< prev index next >

src/java.xml.ws/share/classes/javax/xml/ws/spi/FactoryFinder.java

Print this page


   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


 120             String JAVA_HOME = System.getProperty("java.home");
 121             path = Paths.get(JAVA_HOME, "conf", "jaxws.properties");
 122 
 123             // to ensure backwards compatibility
 124             if (!Files.exists(path)) {
 125                 path = Paths.get(JAVA_HOME, "lib", "jaxws.properties");
 126             }
 127 
 128             if (Files.exists(path)) {
 129                 Properties props = new Properties();
 130                 try (InputStream inStream = Files.newInputStream(path)) {
 131                     props.load(inStream);
 132                 }
 133                 String factoryClassName = props.getProperty(factoryId);
 134                 return ServiceLoaderUtil.newInstance(factoryClassName,
 135                         fallbackClassName, classLoader, EXCEPTION_HANDLER);
 136             }
 137         } catch (Exception ignored) {
 138             logger.log(Level.SEVERE, "Error reading JAX-WS configuration from ["  + path +
 139                     "] file. Check it is accessible and has correct format.", ignored);
 140         }        return null;

 141     }
 142 
 143     private static final String OSGI_SERVICE_LOADER_CLASS_NAME = "com.sun.org.glassfish.hk2.osgiresourcelocator.ServiceLoader";
 144 
 145     private static boolean isOsgi() {
 146         try {
 147             Class.forName(OSGI_SERVICE_LOADER_CLASS_NAME);
 148             return true;
 149         } catch (ClassNotFoundException ignored) {
 150         }
 151         return false;
 152     }
 153 
 154     private static Object lookupUsingOSGiServiceLoader(String factoryId) {
 155         try {
 156             // Use reflection to avoid having any dependendcy on ServiceLoader class
 157             Class serviceClass = Class.forName(factoryId);
 158             Class[] args = new Class[]{serviceClass};
 159             Class target = Class.forName(OSGI_SERVICE_LOADER_CLASS_NAME);
 160             java.lang.reflect.Method m = target.getMethod("lookupProviderInstances", Class.class);
   1 /*
   2  * Copyright (c) 2005, 2016, 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


 120             String JAVA_HOME = System.getProperty("java.home");
 121             path = Paths.get(JAVA_HOME, "conf", "jaxws.properties");
 122 
 123             // to ensure backwards compatibility
 124             if (!Files.exists(path)) {
 125                 path = Paths.get(JAVA_HOME, "lib", "jaxws.properties");
 126             }
 127 
 128             if (Files.exists(path)) {
 129                 Properties props = new Properties();
 130                 try (InputStream inStream = Files.newInputStream(path)) {
 131                     props.load(inStream);
 132                 }
 133                 String factoryClassName = props.getProperty(factoryId);
 134                 return ServiceLoaderUtil.newInstance(factoryClassName,
 135                         fallbackClassName, classLoader, EXCEPTION_HANDLER);
 136             }
 137         } catch (Exception ignored) {
 138             logger.log(Level.SEVERE, "Error reading JAX-WS configuration from ["  + path +
 139                     "] file. Check it is accessible and has correct format.", ignored);
 140         }
 141         return null;
 142     }
 143 
 144     private static final String OSGI_SERVICE_LOADER_CLASS_NAME = "com.sun.org.glassfish.hk2.osgiresourcelocator.ServiceLoader";
 145 
 146     private static boolean isOsgi() {
 147         try {
 148             Class.forName(OSGI_SERVICE_LOADER_CLASS_NAME);
 149             return true;
 150         } catch (ClassNotFoundException ignored) {
 151         }
 152         return false;
 153     }
 154 
 155     private static Object lookupUsingOSGiServiceLoader(String factoryId) {
 156         try {
 157             // Use reflection to avoid having any dependendcy on ServiceLoader class
 158             Class serviceClass = Class.forName(factoryId);
 159             Class[] args = new Class[]{serviceClass};
 160             Class target = Class.forName(OSGI_SERVICE_LOADER_CLASS_NAME);
 161             java.lang.reflect.Method m = target.getMethod("lookupProviderInstances", Class.class);
< prev index next >