28 import java.net.URL; 29 import java.util.List; 30 import java.util.Iterator; 31 import java.util.Map; 32 import java.util.ServiceLoader; 33 import javax.xml.namespace.QName; 34 import javax.xml.ws.*; 35 import javax.xml.ws.wsaddressing.W3CEndpointReference; 36 37 import org.w3c.dom.Element; 38 39 /** 40 * Service provider for {@code ServiceDelegate} and 41 * {@code Endpoint} objects. 42 * 43 * @since 1.6, JAX-WS 2.0 44 */ 45 public abstract class Provider { 46 47 /** 48 * A constant representing the property used to lookup the 49 * name of a {@code Provider} implementation 50 * class. 51 */ 52 static public final String JAXWSPROVIDER_PROPERTY = "javax.xml.ws.spi.Provider"; 53 54 /** 55 * A constant representing the name of the default 56 * {@code Provider} implementation class. 57 **/ 58 // Using two strings so that package renaming doesn't change it 59 static final String DEFAULT_JAXWSPROVIDER 60 = "com.sun"+".xml.internal.ws.spi.ProviderImpl"; 61 62 /** 63 * Creates a new instance of Provider 64 */ 65 protected Provider() { 66 } 67 68 /** 69 * 70 * Creates a new provider object. 71 * <p> 72 * The algorithm used to locate the provider subclass to use consists 73 * of the following steps: 74 * <ul> 75 * <li> 76 * If a resource with the name of 77 * {@code META-INF/services/javax.xml.ws.spi.Provider} 78 * exists, then its first line, if present, is used as the UTF-8 encoded 79 * name of the implementation class. 80 * </li> 81 * <li> 82 * If the $java.home/lib/jaxws.properties file exists and it is readable by 83 * the {@code java.util.Properties.load(InputStream)} method and it contains 84 * an entry whose key is {@code javax.xml.ws.spi.Provider}, then the value of 85 * that entry is used as the name of the implementation class. 86 * </li> 87 * <li> 88 * If a system property with the name {@code javax.xml.ws.spi.Provider} 89 * is defined, then its value is used as the name of the implementation class. 90 * </li> 91 * <li> 92 * Finally, a default implementation class name is used. 93 * </li> 94 * </ul> 95 * 96 */ 97 public static Provider provider() { 98 try { 99 Object provider = getProviderUsingServiceLoader(); 100 if (provider == null) { 101 provider = FactoryFinder.find(JAXWSPROVIDER_PROPERTY, DEFAULT_JAXWSPROVIDER); 102 } 103 if (!(provider instanceof Provider)) { 104 Class pClass = Provider.class; 105 String classnameAsResource = pClass.getName().replace('.', '/') + ".class"; 106 ClassLoader loader = pClass.getClassLoader(); 107 if(loader == null) { 108 loader = ClassLoader.getSystemClassLoader(); 109 } 110 URL targetTypeURL = loader.getResource(classnameAsResource); 111 throw new LinkageError("ClassCastException: attempting to cast" + 112 provider.getClass().getClassLoader().getResource(classnameAsResource) + 113 "to" + targetTypeURL.toString() ); 114 } 115 return (Provider) provider; 116 } catch (WebServiceException ex) { 117 throw ex; 118 } catch (Exception ex) { 119 throw new WebServiceException("Unable to createEndpointReference Provider", ex); 120 } 121 } 122 123 private static Provider getProviderUsingServiceLoader() { 124 ServiceLoader<Provider> sl; 125 Iterator<Provider> it; 126 try { 127 sl = ServiceLoader.load(Provider.class); 128 it = (Iterator<Provider>)sl.iterator(); 129 } catch (Exception e) { 130 throw new WebServiceException("Cannot invoke java.util.ServiceLoader#iterator()", e); 131 } 132 return ((it != null) && it.hasNext()) ? it.next() : null; 133 } 134 135 /** 136 * Creates a service delegate object. 137 * 138 * @param wsdlDocumentLocation A URL pointing to the WSDL document 139 * for the service, or {@code null} if there isn't one. 140 * @param serviceName The qualified name of the service. 141 * @param serviceClass The service class, which MUST be either 142 * {@code javax.xml.ws.Service} or a subclass thereof. 143 * @return The newly created service delegate. 144 */ 145 public abstract ServiceDelegate createServiceDelegate( 146 java.net.URL wsdlDocumentLocation, 147 QName serviceName, Class<? extends Service> serviceClass); 148 149 /** 150 * Creates a service delegate object. 151 * 152 * @param wsdlDocumentLocation A URL pointing to the WSDL document 153 * for the service, or {@code null} if there isn't one. 154 * @param serviceName The qualified name of the service. | 28 import java.net.URL; 29 import java.util.List; 30 import java.util.Iterator; 31 import java.util.Map; 32 import java.util.ServiceLoader; 33 import javax.xml.namespace.QName; 34 import javax.xml.ws.*; 35 import javax.xml.ws.wsaddressing.W3CEndpointReference; 36 37 import org.w3c.dom.Element; 38 39 /** 40 * Service provider for {@code ServiceDelegate} and 41 * {@code Endpoint} objects. 42 * 43 * @since 1.6, JAX-WS 2.0 44 */ 45 public abstract class Provider { 46 47 /** 48 * A constant representing the name of the default 49 * {@code Provider} implementation class. 50 **/ 51 // Using two strings so that package renaming doesn't change it 52 private static final String DEFAULT_JAXWSPROVIDER = 53 "com.sun"+".xml.internal.ws.spi.ProviderImpl"; 54 55 /** 56 * Creates a new instance of Provider 57 */ 58 protected Provider() { 59 } 60 61 /** 62 * 63 * Creates a new provider object. 64 * <p> 65 * The algorithm used to locate the provider subclass to use consists 66 * of the following steps: 67 * <ul> 68 * <li> Use the service-provider loading facilities, defined by the {@link java.util.ServiceLoader} class, 69 * to attempt to locate and load an implementation of {@link javax.xml.ws.spi.Provider} service using 70 * the {@linkplain java.util.ServiceLoader#load(java.lang.Class) default loading mechanism}. 71 * <li>Use the configuration file "jaxws.properties". The file is in standard 72 * {@link java.util.Properties} format and typically located in the 73 * {@code conf} directory of the Java installation. It contains the fully qualified 74 * name of the implementation class with the key {@code javax.xml.ws.spi.Provider}. 75 * <li> If a system property with the name {@code javax.xml.ws.spi.Provider} 76 * is defined, then its value is used as the name of the implementation class. 77 * <li> Finally, a platform default implementation is used. 78 * </ul> 79 * 80 */ 81 public static Provider provider() { 82 try { 83 return FactoryFinder.find(Provider.class, DEFAULT_JAXWSPROVIDER); 84 } catch (WebServiceException ex) { 85 throw ex; 86 } catch (Exception ex) { 87 throw new WebServiceException("Unable to createEndpointReference Provider", ex); 88 } 89 } 90 91 /** 92 * Creates a service delegate object. 93 * 94 * @param wsdlDocumentLocation A URL pointing to the WSDL document 95 * for the service, or {@code null} if there isn't one. 96 * @param serviceName The qualified name of the service. 97 * @param serviceClass The service class, which MUST be either 98 * {@code javax.xml.ws.Service} or a subclass thereof. 99 * @return The newly created service delegate. 100 */ 101 public abstract ServiceDelegate createServiceDelegate( 102 java.net.URL wsdlDocumentLocation, 103 QName serviceName, Class<? extends Service> serviceClass); 104 105 /** 106 * Creates a service delegate object. 107 * 108 * @param wsdlDocumentLocation A URL pointing to the WSDL document 109 * for the service, or {@code null} if there isn't one. 110 * @param serviceName The qualified name of the service. |