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

📄 objectservicefactory.java

📁 Xfire文件 用于开发web service 的一个开源工具 很好用的
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    {        String theName = (name != null) ? name : makeServiceNameFromClassName(clazz);        String theNamespace = (namespace != null) ? namespace : getTargetNamespace(clazz);        QName qName = new QName(theNamespace, theName);        String theStyle = null;        String theUse = null;        QName portType = null;        Collection s11Bindings = null;        Collection s12Bindings = null;        String theScope="";                        if (properties != null)        {            theStyle = (String) properties.get(STYLE);            theUse = (String) properties.get(USE);            portType = (QName) properties.get(PORT_TYPE);            s11Bindings = (List) properties.get(SOAP11_TRANSPORTS);            s12Bindings = (List) properties.get(SOAP12_TRANSPORTS);            theScope = (String) properties.get(SCOPE);        }                if (theStyle == null) theStyle = style;        if (theUse == null) theUse = use;        if (portType == null) portType = new QName(theNamespace, theName + "PortType");        if (theScope == null) theScope = "";                ServiceInfo serviceInfo = new ServiceInfo(portType, clazz);        createDocumentationProvider(serviceInfo);                        serviceInfo.setDocumentation(getDocumentationProvider().getServiceDoc());                if (theStyle.equals(SoapConstants.STYLE_WRAPPED))            serviceInfo.setWrapped(true);                Service endpoint = new Service(serviceInfo);        endpoint.setName(qName);        setProperties(endpoint, properties);        final ObjectInvoker invoker = new ObjectInvoker(ScopePolicyEditor.toScopePolicy(theScope));                endpoint.setInvoker(invoker);        endpoint.setFaultSerializer(new SoapFaultSerializer());        endpoint.setWSDLWriter(new WSDLBuilderAdapter(getWsdlBuilderFactory(), endpoint, transportManager));         initializeOperations(endpoint, theStyle);        endpoint.setProperty(STYLE, theStyle);        endpoint.setProperty(USE, theUse);                boolean buildBindings = bindingCreationEnabled;        if (properties != null && properties.containsKey(CREATE_DEFAULT_BINDINGS))        {            buildBindings = ((Boolean) properties.get(CREATE_DEFAULT_BINDINGS)).booleanValue();        }                if (s11Bindings == null) s11Bindings = new HashSet();        if (s12Bindings == null) s12Bindings = new HashSet();                if (buildBindings)        {            s11Bindings.addAll(getSoap11Transports());            s12Bindings.addAll(getSoap12Transports());        }                createBindings(endpoint, s11Bindings, s12Bindings);                try        {            BindingProvider provider = getBindingProvider();            provider.initialize(endpoint);            endpoint.setBindingProvider(provider);        }        catch (Exception e)        {            if(e instanceof XFireRuntimeException) throw (XFireRuntimeException)e;            throw new XFireRuntimeException("Couldn't load provider.", e);        }        registerHandlers(endpoint);        return endpoint;    }    /**     * @param serviceInfo     */    protected void createDocumentationProvider(ServiceInfo serviceInfo)    {        XMLDocumentationBuilder docBuilder = new XMLDocumentationBuilder();        setDocumentationProvider(EMPTY_DOC_PROVIDER);        DocumentationProvider docProvider = docBuilder.build(serviceInfo);        if( docProvider != null ){            setDocumentationProvider( docProvider);            }                    }    protected String getTargetNamespace(Class clazz)    {        return NamespaceHelper.makeNamespaceFromClassName(                clazz.getName(), "http");    }    /**     * Get a list of Transports which are enabled over SOAP 1.1.     * @return     */    public Collection getSoap11Transports()    {        return soap11Transports;    }        public void addSoap11Transport(String id)    {        soap11Transports.add(id);    }    /**     * Get a list of Transports which are enabled over SOAP 1.2.     * @return     */    public Collection getSoap12Transports()    {        return soap12Transports;    }        public void addSoap12Transport(String id)    {        soap12Transports.add(id);    }        protected void createBindings(Service service, Collection s11, Collection s12)    {        for (Iterator itr = s11.iterator(); itr.hasNext();)        {            String bindingId = (String) itr.next();            Transport t = transportManager.getTransport(bindingId);            if (t instanceof SoapTransport)            {                createSoap11Binding(service, null, bindingId);            }            else if (t == null)            {                throw new XFireRuntimeException("Could not find binding " + bindingId );               }            else            {                throw new XFireRuntimeException("Binding " + bindingId + " is not a SoapTransport!");                        }        }                for (Iterator itr = s12.iterator(); itr.hasNext();)        {            String bindingId = (String) itr.next();            Transport t = transportManager.getTransport(bindingId);            if (t instanceof SoapTransport)            {                createSoap12Binding(service, null, bindingId);            }            else if (t == null)            {                throw new XFireRuntimeException("Could not find binding " + bindingId );               }            else            {                throw new XFireRuntimeException("Binding " + bindingId + " is not a SoapTransport!");                        }        }    }    /**     * Creates an endpoint for a service.  Additionally it opens a channel for this endpoint     * as well.     *      * @param service     * @param name     * @param url     * @param binding     * @return     * @throws Exception      */    public Endpoint createEndpoint(Service service, QName name, String url, Binding binding)         throws Exception    {        Endpoint endpoint = service.addEndpoint(name, binding, url);                getTransportManager().getTransport(binding.getBindingId()).createChannel(url);                return endpoint;    }        /**     * Create a SOAP 1.2 binding for the specified binding id.     *      * @param service     * @param bindingName The name of the binding. If null, one will be created.     * @param bindingId     * @return     */    public Soap12Binding createSoap12Binding(Service service, QName bindingName, String bindingId)    {        if (bindingName == null)        {            SoapTransport st = (SoapTransport) transportManager.getTransport(bindingId);            bindingName = new QName(service.getTargetNamespace(),                                     service.getSimpleName() + st.getName() + "12Binding");        }                Soap12Binding binding = new Soap12Binding(bindingName, bindingId, service);                createSoapBinding(service, binding);                   return binding;    }    /**    * Create a SOAP 1.1 binding for the specified binding id.    *     * @param service    * @param bindingName The name of the binding. If null, one will be created.    * @param bindingId    * @return    */    public Soap11Binding createSoap11Binding(Service service, QName bindingName, String bindingId)    {        if (bindingName == null)        {            SoapTransport st = (SoapTransport) transportManager.getTransport(bindingId);            bindingName = new QName(service.getTargetNamespace(),                                     service.getSimpleName() + st.getName() + "Binding");        }        Soap11Binding binding = new Soap11Binding(bindingName, bindingId, service);             createSoapBinding(service, binding);                return binding;    }    protected void createSoapBinding(Service service, AbstractSoapBinding binding)    {        ServiceInfo serviceInfo = service.getServiceInfo();        String style = (String) service.getProperty(STYLE);        String use = (String) service.getProperty(USE);        binding.setStyle(style);        binding.setUse(use);        binding.setSerializer(getSerializer(binding));        // Create SOAP metadata for the binding operation        for (Iterator itr = serviceInfo.getOperations().iterator(); itr.hasNext();)        {            OperationInfo op = (OperationInfo) itr.next();                        createBindingOperation(service, binding, op);        }            service.addBinding(binding);                getBindingProvider().initialize(service, binding);    }    protected MessageSerializer getSerializer(AbstractSoapBinding binding)    {        return AbstractSoapBinding.getSerializer(binding.getStyle(),                                                 binding.getUse());    }        protected void createBindingOperation(Service service, AbstractSoapBinding binding, OperationInfo op)    {        binding.setSoapAction(op, getAction(op));        createMessageBinding(binding, op);        /*        for (Iterator fitr = op.getFaults().iterator(); fitr.hasNext();)        {            FaultInfo fault = (FaultInfo) fitr.next();                        // we don't support fault headers yet...        }*/    }    private void createMessageBinding(AbstractSoapBinding binding, OperationInfo op)    {        Method method = op.getMethod();        Class[] paramClasses = method.getParameterTypes();        boolean isDoc = binding.getStyle().equals(SoapConstants.STYLE_DOCUMENT);                MessagePartContainer inParts = binding.getHeaders(op.getInputMessage());        MessagePartContainer outParts = null;        if (op.hasOutput()) outParts = binding.getHeaders(op.getOutputMessage());        for (int j = 0; j < paramClasses.length; j++)        {            if (!paramClasses[j].equals(MessageContext.class) && isHeader(method, j))            {                if (isOutParam(method, j))                {                    QName q = getOutParameterName(binding.getService(), op, method, j, isDoc);                    outParts.addMessagePart(q, paramClasses[j]).setIndex(j);                }                                if (isInParam(method, j))                {                    QName q  = getInParameterName(binding.getService(), op, method, j, isDoc);                    inParts.addMessagePart(q, paramClasses[j]).setIndex(j);                }            }        }                Class returnType = method.getReturnType();        if (isHeader(method, -1))        {            if (isOutParam(method, -1))            {                QName q = getOutParameterName(binding.getService(), op, method, -1, isDoc);                outParts.addMessagePart(q, returnType).setIndex(-1);            }                        if (isInParam(method, -1))            {                QName q  = getInParameterName(binding.getService(), op, method, -1, isDoc);                inParts.addMessagePart(q, returnType).setIndex(-1);            }        }    }    protected void registerHandlers(Service service)    {        service.addInHandler(new ServiceInvocationHandler());        service.addInHandler(new PostInvocationHandler());        service.addOutHandler(new OutMessageSender());        service.addFaultHandler(new FaultSender());        service.addFaultHandler(new CustomFaultHandler());    }    private void setProperties(Service service, Map properties)    {        if (properties == null) return;        for (Iterator itr = properties.entrySet().iterator(); itr.hasNext();)        {            Map.Entry entry = (Map.Entry) itr.next();            service.setProperty((String) entry.getKey(), entry.getValue());        }    }    protected void initializeOperations(Service endpoint, String style)    {        final Method[] methods = endpoint.getServiceInfo().getServiceClass().getMethods();        Arrays.sort(methods, new MethodComparator());                for (int i = 0; i < methods.length; i++)        {            final Method method = methods[i];            if (isValidMethod(method))            {                addOperation(endpoint, method, style);            }        }    }    /**     * Ignore the specified class' declared methods.      * This can be used to not expose certain interfaces as a service.     * By default, the methods specified by the following interfaces/classes are ignored:     * <li><code>java.lang.Object</code>     * <li><code>org.omg.CORBA_2_3.portable.ObjectImpl</code>     * <li><code>org.omg.CORBA.portable.ObjectImpl</code>     * <li><code>javax.ejb.EJBObject</code>     * <li><code>javax.ejb.EJBLocalObject</code>     * <li><code>javax.rmi.CORBA.Stub</code>     *      * @param className the fully qualified class name     */    public void addIgnoredMethods(String className)    {        ignoredClasses.add(className);    }    protected boolean isValidMethod(final Method method)    {        for (Iterator itr = serviceConfigurations.iterator(); itr.hasNext();)        {            ServiceConfiguration c = (ServiceConfiguration) itr.next();            Boolean b = c.isOperation(method);            if (b != null) return b.booleanValue();        }        return true;

⌨️ 快捷键说明

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