|
Java example source code file (Provider.java)
The Provider.java Java example source code
/*
* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.ws.spi;
import java.net.URL;
import java.util.List;
import java.util.Iterator;
import java.util.Map;
import java.lang.reflect.Method;
import javax.xml.namespace.QName;
import javax.xml.ws.*;
import javax.xml.ws.wsaddressing.W3CEndpointReference;
import org.w3c.dom.Element;
/**
* Service provider for <code>ServiceDelegate and
* <code>Endpoint objects.
* <p>
*
* @since JAX-WS 2.0
*/
public abstract class Provider {
/**
* A constant representing the property used to lookup the
* name of a <code>Provider implementation
* class.
*/
static public final String JAXWSPROVIDER_PROPERTY
= "javax.xml.ws.spi.Provider";
/**
* A constant representing the name of the default
* <code>Provider implementation class.
**/
// Using two strings so that package renaming doesn't change it
static final String DEFAULT_JAXWSPROVIDER
= "com.sun"+".xml.internal.ws.spi.ProviderImpl";
/**
* Take advantage of Java SE 6's java.util.ServiceLoader API.
* Using reflection so that there is no compile-time dependency on SE 6.
*/
static private final Method loadMethod;
static private final Method iteratorMethod;
static {
Method tLoadMethod = null;
Method tIteratorMethod = null;
try {
Class<?> clazz = Class.forName("java.util.ServiceLoader");
tLoadMethod = clazz.getMethod("load", Class.class);
tIteratorMethod = clazz.getMethod("iterator");
} catch(ClassNotFoundException ce) {
// Running on Java SE 5
} catch(NoSuchMethodException ne) {
// Shouldn't happen
}
loadMethod = tLoadMethod;
iteratorMethod = tIteratorMethod;
}
/**
* Creates a new instance of Provider
*/
protected Provider() {
}
/**
*
* Creates a new provider object.
* <p>
* The algorithm used to locate the provider subclass to use consists
* of the following steps:
* <p>
* <ul>
* <li>
* If a resource with the name of
* <code>META-INF/services/javax.xml.ws.spi.Provider
* exists, then its first line, if present, is used as the UTF-8 encoded
* name of the implementation class.
* </li>
* <li>
* If the $java.home/lib/jaxws.properties file exists and it is readable by
* the <code>java.util.Properties.load(InputStream) method and it contains
* an entry whose key is <code>javax.xml.ws.spi.Provider, then the value of
* that entry is used as the name of the implementation class.
* </li>
* <li>
* If a system property with the name <code>javax.xml.ws.spi.Provider
* is defined, then its value is used as the name of the implementation class.
* </li>
* <li>
* Finally, a default implementation class name is used.
* </li>
* </ul>
*
*/
public static Provider provider() {
try {
Object provider = getProviderUsingServiceLoader();
if (provider == null) {
provider = FactoryFinder.find(JAXWSPROVIDER_PROPERTY, DEFAULT_JAXWSPROVIDER);
}
if (!(provider instanceof Provider)) {
Class pClass = Provider.class;
String classnameAsResource = pClass.getName().replace('.', '/') + ".class";
ClassLoader loader = pClass.getClassLoader();
if(loader == null) {
loader = ClassLoader.getSystemClassLoader();
}
URL targetTypeURL = loader.getResource(classnameAsResource);
throw new LinkageError("ClassCastException: attempting to cast" +
provider.getClass().getClassLoader().getResource(classnameAsResource) +
"to" + targetTypeURL.toString() );
}
return (Provider) provider;
} catch (WebServiceException ex) {
throw ex;
} catch (Exception ex) {
throw new WebServiceException("Unable to createEndpointReference Provider", ex);
}
}
private static Provider getProviderUsingServiceLoader() {
if (loadMethod != null) {
Object loader;
try {
loader = loadMethod.invoke(null, Provider.class);
} catch (Exception e) {
throw new WebServiceException("Cannot invoke java.util.ServiceLoader#load()", e);
}
Iterator<Provider> it;
try {
it = (Iterator<Provider>)iteratorMethod.invoke(loader);
} catch(Exception e) {
throw new WebServiceException("Cannot invoke java.util.ServiceLoader#iterator()", e);
}
return it.hasNext() ? it.next() : null;
}
return null;
}
/**
* Creates a service delegate object.
* <p>
* @param wsdlDocumentLocation A URL pointing to the WSDL document
* for the service, or <code>null if there isn't one.
* @param serviceName The qualified name of the service.
* @param serviceClass The service class, which MUST be either
* <code>javax.xml.ws.Service or a subclass thereof.
* @return The newly created service delegate.
*/
public abstract ServiceDelegate createServiceDelegate(
java.net.URL wsdlDocumentLocation,
QName serviceName, Class<? extends Service> serviceClass);
/**
* Creates a service delegate object.
* <p>
* @param wsdlDocumentLocation A URL pointing to the WSDL document
* for the service, or <code>null if there isn't one.
* @param serviceName The qualified name of the service.
* @param serviceClass The service class, which MUST be either
* <code>javax.xml.ws.Service or a subclass thereof.
* @param features Web Service features that must be configured on
* the service. If the provider doesn't understand a feature,
* it must throw a WebServiceException.
* @return The newly created service delegate.
*
* @since JAX-WS 2.2
*/
public ServiceDelegate createServiceDelegate(
java.net.URL wsdlDocumentLocation,
QName serviceName, Class<? extends Service> serviceClass, WebServiceFeature ... features) {
throw new UnsupportedOperationException("JAX-WS 2.2 implementation must override this default behaviour.");
}
/**
*
* Creates an endpoint object with the provided binding and implementation
* object.
*
* @param bindingId A URI specifying the desired binding (e.g. SOAP/HTTP)
* @param implementor A service implementation object to which
* incoming requests will be dispatched. The corresponding
* class MUST be annotated with all the necessary Web service
* annotations.
* @return The newly created endpoint.
*/
public abstract Endpoint createEndpoint(String bindingId,
Object implementor);
/**
* Creates and publishes an endpoint object with the specified
* address and implementation object.
*
* @param address A URI specifying the address and transport/protocol
* to use. A http: URI MUST result in the SOAP 1.1/HTTP
* binding being used. Implementations may support other
* URI schemes.
* @param implementor A service implementation object to which
* incoming requests will be dispatched. The corresponding
* class MUST be annotated with all the necessary Web service
* annotations.
* @return The newly created endpoint.
*/
public abstract Endpoint createAndPublishEndpoint(String address,
Object implementor);
/**
* read an EndpointReference from the infoset contained in
* <code>eprInfoset.
*
* @param eprInfoset infoset for EndpointReference
*
* @return the <code>EndpointReference unmarshalled from
* <code>eprInfoset. This method never returns
Other Java examples (source code examples)Here is a short list of links related to this Java Provider.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.