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

📄 javastubwriter.java

📁 Java有关XML编程需要用到axis 的源代码 把里面bin下的包导入相应的Java工程 进行使用
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/* * 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.Constants;import org.apache.axis.components.logger.LogFactory;import org.apache.axis.constants.Style;import org.apache.axis.constants.Use;import org.apache.axis.utils.Messages;import org.apache.axis.utils.JavaUtils;import org.apache.axis.utils.StringUtils;import org.apache.axis.wsdl.symbolTable.BindingEntry;import org.apache.axis.wsdl.symbolTable.CollectionType;import org.apache.axis.wsdl.symbolTable.DefinedType;import org.apache.axis.wsdl.symbolTable.FaultInfo;import org.apache.axis.wsdl.symbolTable.Parameter;import org.apache.axis.wsdl.symbolTable.Parameters;import org.apache.axis.wsdl.symbolTable.SchemaUtils;import org.apache.axis.wsdl.symbolTable.SymbolTable;import org.apache.axis.wsdl.symbolTable.TypeEntry;import org.apache.axis.wsdl.symbolTable.DefinedElement;import org.apache.commons.logging.Log;import javax.wsdl.Binding;import javax.wsdl.BindingOperation;import javax.wsdl.Fault;import javax.wsdl.Message;import javax.wsdl.Operation;import javax.wsdl.OperationType;import javax.wsdl.Part;import javax.wsdl.PortType;import javax.wsdl.extensions.UnknownExtensibilityElement;import javax.wsdl.extensions.soap.SOAPBinding;import javax.wsdl.extensions.soap.SOAPOperation;import javax.xml.namespace.QName;import java.io.IOException;import java.io.PrintWriter;import java.util.ArrayList;import java.util.Collection;import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Vector;import java.util.Arrays;import java.util.Comparator;import java.util.Collections;/** * This is Wsdl2java's stub writer.  It writes the <BindingName>Stub.java * file which contains the <bindingName>Stub class. */public class JavaStubWriter extends JavaClassWriter {    /** Field log */    protected static Log log = LogFactory.getLog(JavaStubWriter.class.getName());        /** Field bEntry */    private BindingEntry bEntry;    /** Field binding */    private Binding binding;    /** Field symbolTable */    private SymbolTable symbolTable;    // the maximum number of java type <-> qname binding instructions we'll    // emit in a single method.  This is important for stubs that handle    // a large number of schema types, as the generated source can exceed    // the size in a single method by the VM.    /** Field MAXIMUM_BINDINGS_PER_METHOD */    private static final int MAXIMUM_BINDINGS_PER_METHOD = 100;    /** Field modeStrings */    static String[] modeStrings = new String[]{"",                                               "org.apache.axis.description.ParameterDesc.IN",                                               "org.apache.axis.description.ParameterDesc.OUT",                                               "org.apache.axis.description.ParameterDesc.INOUT"};    /** Field styles */    static Map styles = new HashMap();    /** Field uses */    static Map uses = new HashMap();    static {        styles.put(Style.DOCUMENT, "org.apache.axis.constants.Style.DOCUMENT");        styles.put(Style.RPC, "org.apache.axis.constants.Style.RPC");        styles.put(Style.MESSAGE, "org.apache.axis.constants.Style.MESSAGE");        styles.put(Style.WRAPPED, "org.apache.axis.constants.Style.WRAPPED");        uses.put(Use.ENCODED, "org.apache.axis.constants.Use.ENCODED");        uses.put(Use.LITERAL, "org.apache.axis.constants.Use.LITERAL");    }    /** Field OPERDESC_PER_BLOCK */    static int OPERDESC_PER_BLOCK = 10;    /**     * Constructor.     *      * @param emitter          * @param bEntry           * @param symbolTable      */    public JavaStubWriter(Emitter emitter, BindingEntry bEntry,                             SymbolTable symbolTable) {        super(emitter, bEntry.getName() + "Stub", "stub");        this.bEntry = bEntry;        this.binding = bEntry.getBinding();        this.symbolTable = symbolTable;    }    // ctor    /**     * Returns "extends org.apache.axis.client.Stub ".     *      * @return      */    protected String getExtendsText() {        return "extends org.apache.axis.client.Stub ";    }    // getExtendsText    /**     * Returns "implements <SEI> ".     *      * @return      */    protected String getImplementsText() {        return "implements "                + bEntry.getDynamicVar(JavaBindingWriter.INTERFACE_NAME) + " ";    }    // getImplementsText    /**     * Write the body of the binding's stub file.     *      * @param pw      * @throws IOException      */    protected void writeFileBody(PrintWriter pw) throws IOException {        PortType portType = binding.getPortType();        HashSet types = getTypesInPortType(portType);        boolean hasMIME = Utils.hasMIME(bEntry);        if ((types.size() > 0) || hasMIME) {            pw.println(                    "    private java.util.Vector cachedSerClasses = new java.util.Vector();");            pw.println(                    "    private java.util.Vector cachedSerQNames = new java.util.Vector();");            pw.println(                    "    private java.util.Vector cachedSerFactories = new java.util.Vector();");            pw.println(                    "    private java.util.Vector cachedDeserFactories = new java.util.Vector();");        }        pw.println();        pw.println(                "    static org.apache.axis.description.OperationDesc [] _operations;");        pw.println();        writeOperationMap(pw);        pw.println();        pw.println("    public " + className                + "() throws org.apache.axis.AxisFault {");        pw.println("         this(null);");        pw.println("    }");        pw.println();        pw.println(                "    public " + className                + "(java.net.URL endpointURL, javax.xml.rpc.Service service) throws org.apache.axis.AxisFault {");        pw.println("         this(service);");        pw.println("         super.cachedEndpoint = endpointURL;");        pw.println("    }");        pw.println();        pw.println(                "    public " + className                + "(javax.xml.rpc.Service service) throws org.apache.axis.AxisFault {");        pw.println("        if (service == null) {");        pw.println(                "            super.service = new org.apache.axis.client.Service();");        pw.println("        } else {");        pw.println("            super.service = service;");        pw.println("        }");        pw.println("        ((org.apache.axis.client.Service)super.service).setTypeMappingVersion(\"" + emitter.getTypeMappingVersion() + "\");");        List deferredBindings = new ArrayList();        // keep track of how many type mappings we write out        int typeMappingCount = 0;        if (types.size() > 0) {            Iterator it = types.iterator();            while (it.hasNext()) {                TypeEntry type = (TypeEntry) it.next();                if (!Utils.shouldEmit(type)) {                    continue;                }                // Write out serializer declarations                if (typeMappingCount == 0) {                    writeSerializationDecls(                            pw, hasMIME, binding.getQName().getNamespaceURI());                }                // write the type mapping for this type                // writeSerializationInit(pw, type);                deferredBindings.add(type);                // increase the number of type mappings count                typeMappingCount++;            }        }        // Sort the TypeEntry's by their qname.        Collections.sort(deferredBindings, new Comparator() {            public int compare(Object a, Object b) {                TypeEntry type1 = (TypeEntry)a;                TypeEntry type2 = (TypeEntry)b;                return type1.getQName().toString().compareToIgnoreCase(type2.getQName().toString());            }        });        // We need to write out the MIME mapping, even if we don't have        // any type mappings        if ((typeMappingCount == 0) && hasMIME) {            writeSerializationDecls(pw, hasMIME,                    binding.getQName().getNamespaceURI());            typeMappingCount++;        }        // track whether the number of bindings exceeds the threshold        // that we allow per method.        boolean needsMultipleBindingMethods = false;        if (deferredBindings.size() < MAXIMUM_BINDINGS_PER_METHOD) {            // small number of bindings, just inline them:            for (Iterator it = deferredBindings.iterator(); it.hasNext();) {                writeSerializationInit(pw, (TypeEntry) it.next());            }        } else {            needsMultipleBindingMethods = true;            int methodCount = calculateBindingMethodCount(deferredBindings);            // invoke each of the soon-to-be generated addBindings methods            // from the constructor.            for (int i = 0; i < methodCount; i++) {                pw.println("        addBindings" + i + "();");            }        }        pw.println("    }");        pw.println();        // emit any necessary methods for assembling binding metadata.        if (needsMultipleBindingMethods) {            writeBindingMethods(pw, deferredBindings);            pw.println();        }        pw.println(                "    protected org.apache.axis.client.Call createCall() throws java.rmi.RemoteException {");        pw.println("        try {");        pw.println("            org.apache.axis.client.Call _call = super._createCall();");        pw.println("            if (super.maintainSessionSet) {");        pw.println(                "                _call.setMaintainSession(super.maintainSession);");        pw.println("            }");        pw.println("            if (super.cachedUsername != null) {");        pw.println("                _call.setUsername(super.cachedUsername);");        pw.println("            }");        pw.println("            if (super.cachedPassword != null) {");        pw.println("                _call.setPassword(super.cachedPassword);");        pw.println("            }");        pw.println("            if (super.cachedEndpoint != null) {");        pw.println(                "                _call.setTargetEndpointAddress(super.cachedEndpoint);");        pw.println("            }");        pw.println("            if (super.cachedTimeout != null) {");        pw.println("                _call.setTimeout(super.cachedTimeout);");        pw.println("            }");        pw.println("            if (super.cachedPortName != null) {");        pw.println("                _call.setPortName(super.cachedPortName);");        pw.println("            }");        pw.println(                "            java.util.Enumeration keys = super.cachedProperties.keys();");        pw.println("            while (keys.hasMoreElements()) {");        pw.println(                "                java.lang.String key = (java.lang.String) keys.nextElement();");        pw.println(                "                _call.setProperty(key, super.cachedProperties.get(key));");        pw.println("            }");        if (typeMappingCount > 0) {            pw.println("            // " + Messages.getMessage("typeMap00"));            pw.println("            // " + Messages.getMessage("typeMap01"));            pw.println("            // " + Messages.getMessage("typeMap02"));            pw.println("            // " + Messages.getMessage("typeMap03"));            pw.println("            // " + Messages.getMessage("typeMap04"));            pw.println("            synchronized (this) {");            pw.println("                if (firstCall()) {");            // Hack alert - we need to establish the encoding style before we register type mappings due            // to the fact that TypeMappings key off of encoding style            pw.println("                    // "                    + Messages.getMessage("mustSetStyle"));            if (bEntry.hasLiteral()) {                pw.println("                    _call.setEncodingStyle(null);");            } else {                Iterator iterator =                        bEntry.getBinding().getExtensibilityElements().iterator();                while (iterator.hasNext()) {                    Object obj = iterator.next();                    if (obj instanceof SOAPBinding) {                        pw.println(                                "                    _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);");                        pw.println(                                "                    _call.setEncodingStyle(org.apache.axis.Constants.URI_SOAP11_ENC);");                    } else if (obj instanceof UnknownExtensibilityElement) {

⌨️ 快捷键说明

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