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

📄 javaserviceimplwriter.java

📁 Java有关XML编程需要用到axis 的源代码 把里面bin下的包导入相应的Java工程 进行使用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright 2001-2004 The Apache Software Foundation. *  * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at *  *      http://www.apache.org/licenses/LICENSE-2.0 *  * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.axis.wsdl.toJava;import org.apache.axis.utils.JavaUtils;import org.apache.axis.utils.Messages;import org.apache.axis.utils.WSDLUtils;import org.apache.axis.wsdl.symbolTable.BindingEntry;import org.apache.axis.wsdl.symbolTable.PortTypeEntry;import org.apache.axis.wsdl.symbolTable.ServiceEntry;import org.apache.axis.wsdl.symbolTable.SymbolTable;import org.apache.axis.wsdl.symbolTable.BackslashUtil;import javax.wsdl.Binding;import javax.wsdl.Port;import javax.wsdl.Service;import javax.xml.namespace.QName;import java.io.IOException;import java.io.PrintWriter;import java.net.MalformedURLException;import java.util.Iterator;import java.util.Map;import java.util.StringTokenizer;import java.util.Vector;/** * This is Wsdl2java's service implementation writer. * It writes the <serviceName>Locator.java file. */public class JavaServiceImplWriter extends JavaClassWriter {    /** Field sEntry */    private ServiceEntry sEntry;    /** Field symbolTable */    private SymbolTable symbolTable;    /**     * Constructor.     *      * @param emitter          * @param sEntry           * @param symbolTable      */    protected JavaServiceImplWriter(Emitter emitter, ServiceEntry sEntry,                                    SymbolTable symbolTable) {        super(emitter, sEntry.getName() + "Locator", "service");        this.sEntry = sEntry;        this.symbolTable = symbolTable;    }    // ctor    /**     * Returns "extends org.apache.axis.client.Service ".     *      * @return      */    protected String getExtendsText() {        return "extends org.apache.axis.client.Service ";    }    // getExtendsText    /**     * Returns "implements <serviceInterface>".     *      * @return      */    protected String getImplementsText() {        return "implements " + sEntry.getName() + ' ';    }    // getImplementsText    /**     * Write the body of the service file.     *      * @param pw      * @throws IOException      */    protected void writeFileBody(PrintWriter pw) throws IOException {        Service service = sEntry.getService();        // output comments        writeComment(pw, service.getDocumentationElement(), false);        // Used to construct the getPort(Class) method.        Vector getPortIfaces = new Vector();        Vector getPortStubClasses = new Vector();        Vector getPortPortNames = new Vector();        Vector getPortPortXmlNames = new Vector();        boolean printGetPortNotice = false;        // get ports        Map portMap = service.getPorts();        Iterator portIterator = portMap.values().iterator();        //Write the constructor for <servicename>Locator        writeConstructors(pw);                // write a get method for each of the ports with a SOAP binding        while (portIterator.hasNext()) {            Port p = (Port) portIterator.next();            Binding binding = p.getBinding();            if (binding == null) {                throw new IOException(Messages.getMessage("emitFailNoBinding01",                        new String[]{                            p.getName()}));            }            BindingEntry bEntry =                    symbolTable.getBindingEntry(binding.getQName());            if (bEntry == null) {                throw new IOException(                        Messages.getMessage(                                "emitFailNoBindingEntry01",                                new String[]{binding.getQName().toString()}));            }            PortTypeEntry ptEntry =                    symbolTable.getPortTypeEntry(binding.getPortType().getQName());            if (ptEntry == null) {                throw new IOException(                        Messages.getMessage(                                "emitFailNoPortType01",                                new String[]{                                    binding.getPortType().getQName().toString()}));            }            // If this isn't an SOAP binding, skip it            if (bEntry.getBindingType() != BindingEntry.TYPE_SOAP) {                continue;            }            // JSR 101 indicates that the name of the port used            // in the java code is the name of the wsdl:port.  It            // does not indicate what should occur if the            // wsdl:port name is not a java identifier.  The            // TCK depends on the case-sensitivity being preserved,            // and the interop tests have port names that are not            // valid java identifiers.  Thus the following code.            // java port <--> wsdl port mapping            String portXmlName = p.getName();            String portName = (String) bEntry.getDynamicVar(JavaServiceWriter.PORT_NAME + ":" + p.getName());            if (portName == null) {                portName = p.getName();            }            if (!JavaUtils.isJavaId(portName)) {                portName = Utils.xmlNameToJavaClass(portName);            }            String stubClass = bEntry.getName() + "Stub";            String bindingType =                    (String) bEntry.getDynamicVar(JavaBindingWriter.INTERFACE_NAME);            // getPort(Class) must return a stub for an interface.  Collect all            // the port interfaces so the getPort(Class) method can be constructed.            if (getPortIfaces.contains(bindingType)) {                printGetPortNotice = true;            }            getPortIfaces.add(bindingType);            getPortPortXmlNames.add(portXmlName);            getPortStubClasses.add(stubClass);            getPortPortNames.add(portName);            // Get endpoint address and validate it            String address = WSDLUtils.getAddressFromPort(p);            if (address == null) {                // now what?                throw new IOException(Messages.getMessage("emitFail02",                        portName, className));            }            try {                new java.net.URL(address);            } catch (MalformedURLException e) {                // this exception may be due to an unrecognized protocol                // so try to instantiate the protocol handler directly                // and use that to create the URL                java.net.URL url = null;                java.net.URLStreamHandler handler = null;                String handlerPkgs =                        System.getProperty("java.protocol.handler.pkgs");                if (handlerPkgs != null) {                    int protIndex = address.indexOf(":");                    if (protIndex > 0) {                        String protocol = address.substring(0,                                protIndex);                        StringTokenizer st =                                new StringTokenizer(handlerPkgs, "|");                        while (st.hasMoreTokens()) {                            String pkg = st.nextToken();                            String handlerClass = pkg + "." + protocol                                    + ".Handler";                            try {                                Class c = Class.forName(handlerClass);                                handler =                                        (java.net.URLStreamHandler) c.newInstance();                                url = new java.net.URL(null, address,                                        handler);                                break;                            } catch (Exception e2) {                                url = null;                            }                        }                    }                }                if (url == null) {                    if (emitter.isAllowInvalidURL()) {                        // Unchecked URL mode                        System.err.println(Messages.getMessage("emitWarnInvalidURL01", new String[] {portName, className, address}));                    } else {                        // Checked URL mode :                        // URL invalid -> Exception                        throw new IOException(Messages.getMessage("emitFail03",                                new String[]{                                    portName,                                    className,                                    address}));                                            }                }            }            writeAddressInfo(pw, portName, address, p);            String wsddServiceName = portName + "WSDDServiceName";            writeWSDDServiceNameInfo(pw, wsddServiceName, portName, portXmlName);            writeGetPortName(pw, bindingType, portName);            writeGetPortNameURL(pw, bindingType, portName, stubClass,                    wsddServiceName);            writeSetPortEndpointAddress(pw, portName);        }        writeGetPortClass(pw, getPortIfaces, getPortStubClasses,                getPortPortNames, printGetPortNotice);        writeGetPortQNameClass(pw, getPortPortNames, getPortPortXmlNames);        writeGetServiceName(pw, sEntry.getQName());        writeGetPorts(pw, sEntry.getQName().getNamespaceURI(), getPortPortXmlNames);        writeSetEndpointAddress(pw, getPortPortNames);    }    // writeFileBody    /**     * write Constructors     *     * @param pw     */    protected void writeConstructors(PrintWriter pw) {        //Write the default constructor        pw.println();        pw.println("    public " + Utils.getJavaLocalName(sEntry.getName())                + "Locator() {");        pw.println("    }");        pw.println();    	        //Write a constructor that accepts an Engine Configuration         pw.println();        pw.println("    public " + Utils.getJavaLocalName(sEntry.getName())                + "Locator(org.apache.axis.EngineConfiguration config) {");        pw.println("        super(config);");        pw.println("    }");        //Write a constructor that accepts String wsdl location + Service QName        pw.println();        pw.println("    public " + Utils.getJavaLocalName(sEntry.getName())                + "Locator(java.lang.String wsdlLoc, javax.xml.namespace.QName sName) "                + "throws " + javax.xml.rpc.ServiceException.class.getName() + " {");        pw.println("        super(wsdlLoc, sName);");        pw.println("    }");    }    /**     * Write the private address field for this port and the public getter for it.     *      * @param pw            * @param portName      * @param address       * @param p             */    protected void writeAddressInfo(PrintWriter pw, String portName,                                    String address, Port p) {        // Write the private address field for this port        pw.println();        pw.println("    // " + Messages.getMessage("getProxy00", portName));        writeComment(pw, p.getDocumentationElement(), true);        pw.println("    private java.lang.String " + portName + "_address = \""                + address + "\";");        // Write the public address getter for this field        pw.println();        pw.println("    public java.lang.String get" + portName                + "Address() {");        pw.println("        return " + portName + "_address;");        pw.println("    }");        pw.println();

⌨️ 快捷键说明

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