⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 annotationservicefactory.java

📁 Xfire文件 用于开发web service 的一个开源工具 很好用的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package org.codehaus.xfire.annotations;import java.io.IOException;import java.lang.reflect.Method;import java.lang.reflect.Modifier;import java.net.URL;import java.util.ArrayList;import java.util.Collection;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import javax.xml.namespace.QName;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.codehaus.xfire.XFireFactory;import org.codehaus.xfire.XFireRuntimeException;import org.codehaus.xfire.aegis.AegisBindingProvider;import org.codehaus.xfire.aegis.type.Configuration;import org.codehaus.xfire.annotations.soap.SOAPBindingAnnotation;import org.codehaus.xfire.service.Service;import org.codehaus.xfire.service.ServiceFactory;import org.codehaus.xfire.service.binding.BindingProvider;import org.codehaus.xfire.service.binding.ObjectServiceFactory;import org.codehaus.xfire.service.invoker.ObjectInvoker;import org.codehaus.xfire.transport.TransportManager;import org.codehaus.xfire.util.ClassLoaderUtils;import org.codehaus.xfire.util.NamespaceHelper;import org.codehaus.xfire.wsdl.ResourceWSDL;/** * Annotations-bases implementation of the {@link ServiceFactory} interface. * * @author Arjen Poutsma */public class AnnotationServiceFactory        extends ObjectServiceFactory        implements ServiceFactory{    private Log log = LogFactory.getLog(AnnotationServiceFactory.class);        private WebAnnotations webAnnotations;    private AnnotationsValidator validator = new AnnotationsValidatorImpl();    public static final String ALLOW_INTERFACE = "annotations.allow.interface";        /**     * Creates an AnnotationServiceFactory which uses the most appropriate     * annotations implementation - commons-attributes on Java 1.4 and     * Java 5 attributes on Java 5 JVMs.     * <p>     * The {@link TransportManager} is retrieved from the {@link XFireFactory}.     */    public AnnotationServiceFactory()    {        this(XFireFactory.newInstance().getXFire().getTransportManager());    }        /**     * Creates an AnnotationServiceFactory which uses the most appropriate     * annotations implementation - commons-attributes on Java 1.4 and     * Java 5 attributes on Java 5 JVMs.     */    public AnnotationServiceFactory(final TransportManager transportManager)    {        super(transportManager, new AegisBindingProvider());        this.webAnnotations = getAnnotations();                AnnotationServiceConfiguration annotationConfig = new AnnotationServiceConfiguration();        annotationConfig.setWebAnnotations(webAnnotations);        annotationConfig.setServiceFactory(this);        getServiceConfigurations().add(0, annotationConfig);            }        public AnnotationServiceFactory(final TransportManager transportManager,Configuration config)    {        super(transportManager, new AegisBindingProvider(null,config));        this.webAnnotations = getAnnotations();                AnnotationServiceConfiguration annotationConfig = new AnnotationServiceConfiguration();        annotationConfig.setWebAnnotations(webAnnotations);        annotationConfig.setServiceFactory(this);        getServiceConfigurations().add(0, annotationConfig);            }        public AnnotationServiceFactory(WebAnnotations webAnnotations,                                    final TransportManager transportManager)    {        super(transportManager, new AegisBindingProvider());        this.webAnnotations = webAnnotations;        AnnotationServiceConfiguration annotationConfig = new AnnotationServiceConfiguration();        annotationConfig.setWebAnnotations(webAnnotations);        annotationConfig.setServiceFactory(this);        getServiceConfigurations().add(0, annotationConfig);    }        /**     * Initializes a new instance of the <code>AnnotationServiceFactory</code> with the given annotations facade,     * transport manager and type mapping registry.     *     * @param webAnnotations   the annotations facade     * @param transportManager the transport manager     * @param provider         the registry     */    public AnnotationServiceFactory(WebAnnotations webAnnotations,                                    final TransportManager transportManager,                                    final BindingProvider provider)    {        super(transportManager, provider);        this.webAnnotations = webAnnotations;        AnnotationServiceConfiguration annotationConfig = new AnnotationServiceConfiguration();        annotationConfig.setWebAnnotations(webAnnotations);        annotationConfig.setServiceFactory(this);        getServiceConfigurations().add(0, annotationConfig);    }    protected WebAnnotations getAnnotations()    {        if (!isJDK5andAbove())            return loadCommonsAttributesAnnotations();                try        {            WebAnnotations wa = (WebAnnotations)                ClassLoaderUtils.loadClass("org.codehaus.xfire.annotations.jsr181.Jsr181WebAnnotations",                                            getClass()).newInstance();                        return wa;        }        catch (Exception e)        {            return loadCommonsAttributesAnnotations();        }    }    private WebAnnotations loadCommonsAttributesAnnotations()    {        try        {            WebAnnotations wa = (WebAnnotations)                ClassLoaderUtils.loadClass("org.codehaus.xfire.annotations.commons.CommonsWebAttributes",                                            getClass()).newInstance();                        return wa;        }        catch (Exception e1)        {            throw new XFireRuntimeException("No WebAnnotation implementation was found!", e1);        }    }        boolean isJDK5andAbove()    {      String v = System.getProperty("java.class.version","44.0");      return ("49.0".compareTo(v) <= 0);    }        /**     * Creates a service from the specified class. If the class has a     * {@link SOAPBindingAnnotation}, it will be used to define the style and     * use of the service. If the class has a {@link WebServiceAnnotation}, it will be used to     * define the name, service name, target namespace. If the annotation     * defines an endpoint interface, all methods of that interface are exposed     * as operations. If no endpoint interface is defined, all methods that have     * the {@link WebMethodAnnotation} are exposed.     *      * @param clazz     *            The service class used to populate the operations and     *            parameters.     * @return The service.     */    public Service create(final Class clazz, String name, String namespace, Map properties)    {        String style = null;        String use = null;                if (properties == null) properties = new HashMap();        if (webAnnotations.hasWebServiceAnnotation(clazz))        {        	        	validator.validate(webAnnotations, clazz);        	            WebServiceAnnotation webServiceAnnotation = webAnnotations.getWebServiceAnnotation(clazz);                                             assertValidImplementationClass(clazz, webAnnotations, properties);                        name = createServiceName(clazz, webServiceAnnotation, name);                     /* Attempt to load the endpoint interface if there is one. If there is an endpoint             * interface the attribute WebService.serviceName is the only valid one for the             * implementing bean class.             */            String portType = null;            Class endpointInterface = clazz;            if (webServiceAnnotation.getEndpointInterface() != null &&                    webServiceAnnotation.getEndpointInterface().length() != 0)            {                try                {                    endpointInterface = loadClass(webServiceAnnotation.getEndpointInterface());                    if (!webAnnotations.hasWebServiceAnnotation(endpointInterface))                    {                        throw new AnnotationException("Endpoint interface " + endpointInterface.getName() +                                                      " does not have a WebService annotation");                    }                    WebServiceAnnotation endpointWSAnnotation =                            webAnnotations.getWebServiceAnnotation(endpointInterface);                    namespace = createServiceNamespace(endpointInterface, endpointWSAnnotation, namespace);                    portType = createPortType(name, endpointWSAnnotation);                }                catch (ClassNotFoundException e)                {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -