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

📄 javadeploywriter.java

📁 Java有关XML编程需要用到axis 的源代码 把里面bin下的包导入相应的Java工程 进行使用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright 2001-2005 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.deployment.wsdd.WSDDConstants;import org.apache.axis.description.OperationDesc;import org.apache.axis.description.ServiceDesc;import org.apache.axis.components.logger.LogFactory;import org.apache.axis.constants.Scope;import org.apache.axis.constants.Style;import org.apache.axis.constants.Use;import org.apache.axis.utils.JavaUtils;import org.apache.axis.utils.Messages;import org.apache.axis.wsdl.symbolTable.BindingEntry;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.commons.logging.Log;import javax.wsdl.Binding;import javax.wsdl.BindingOperation;import javax.wsdl.Definition;import javax.wsdl.Operation;import javax.wsdl.OperationType;import javax.wsdl.Port;import javax.wsdl.Service;import javax.wsdl.extensions.UnknownExtensibilityElement;import javax.wsdl.extensions.soap.SOAPBinding;import javax.xml.namespace.QName;import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import java.io.OutputStreamWriter;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.Map;import java.util.Vector;/** * This is Wsdl2java's deploy Writer.  It writes the deploy.wsdd file. */public class JavaDeployWriter extends JavaWriter {    /** Field log */    protected static Log log = LogFactory.getLog(JavaDeployWriter.class.getName());    /** Field definition */    protected Definition definition;    /** Field symbolTable */    protected SymbolTable symbolTable;    /** Field emitter */    protected Emitter emitter;    /** Field use */    Use use = Use.DEFAULT;    /**     * Constructor.     *     * @param emitter     * @param definition     * @param symbolTable     */    public JavaDeployWriter(Emitter emitter, Definition definition,                            SymbolTable symbolTable) {        super(emitter, "deploy");        this.emitter = emitter;        this.definition = definition;        this.symbolTable = symbolTable;    }    // ctor    /**     * Generate deploy.wsdd.  Only generate it if the emitter     * is generating server-side mappings.     *     * @throws IOException     */    public void generate() throws IOException {        if (emitter.isServerSide()) {            super.generate();        }    }    // generate    /**     * Return the fully-qualified name of the deploy.wsdd file     * to be generated.     *     * @return     */    protected String getFileName() {        String dir =                emitter.getNamespaces().getAsDir(definition.getTargetNamespace());        return dir + "deploy.wsdd";    }    // getFileName    /**     * Replace the default file header with the deployment doc file header.     *     * @param pw     * @throws IOException     */    protected void writeFileHeader(PrintWriter pw) throws IOException {        pw.println(Messages.getMessage("deploy00"));        pw.println(Messages.getMessage("deploy02"));        pw.println(Messages.getMessage("deploy03"));        pw.println(Messages.getMessage("deploy05"));        pw.println(Messages.getMessage("deploy06"));        pw.println(Messages.getMessage("deploy07"));        pw.println(Messages.getMessage("deploy09"));        pw.println();        pw.println("<deployment");        pw.println("    xmlns=\"" + WSDDConstants.URI_WSDD + "\"");        pw.println("    xmlns:" + WSDDConstants.NS_PREFIX_WSDD_JAVA + "=\""                + WSDDConstants.URI_WSDD_JAVA + "\">");    }    // writeFileHeader    /**     * Write the body of the deploy.wsdd file.     *     * @param pw     * @throws IOException     */    protected void writeFileBody(PrintWriter pw) throws IOException {        writeDeployServices(pw);        pw.println("</deployment>");    }    // writeFileBody    /**     * Write out deployment and undeployment instructions for each WSDL service     *     * @param pw     * @throws IOException     */    protected void writeDeployServices(PrintWriter pw) throws IOException {        // deploy the ports on each service        Map serviceMap = definition.getServices();        for (Iterator mapIterator = serviceMap.values().iterator();             mapIterator.hasNext();) {            Service myService = (Service) mapIterator.next();            pw.println();            pw.println(                    "  <!-- "                    + Messages.getMessage(                            "wsdlService00", myService.getQName().getLocalPart()) + " -->");            pw.println();            for (Iterator portIterator = myService.getPorts().values().iterator();                 portIterator.hasNext();) {                Port myPort = (Port) portIterator.next();                BindingEntry bEntry =                        symbolTable.getBindingEntry(myPort.getBinding().getQName());                // If this isn't an SOAP binding, skip it                if (bEntry.getBindingType() != BindingEntry.TYPE_SOAP) {                    continue;                }                writeDeployPort(pw, myPort, myService, bEntry);            }        }    }    // writeDeployServices    /**     * Write out bean mappings for each type     *     * @param pw     * @param binding     * @param hasLiteral     * @param hasMIME     * @param use     * @throws IOException     */    protected void writeDeployTypes(            PrintWriter pw, Binding binding, boolean hasLiteral, boolean hasMIME, Use use)            throws IOException {        pw.println();        if (hasMIME) {            QName bQName = binding.getQName();            writeTypeMapping(                    pw, bQName.getNamespaceURI(), "DataHandler",                    "javax.activation.DataHandler",                    "org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory",                    "org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory",                    use.getEncoding());        }        Map types = symbolTable.getTypeIndex();        Collection typeCollection = types.values();        for (Iterator i = typeCollection.iterator(); i.hasNext(); ) {            TypeEntry type = (TypeEntry) i.next();            // Note this same check is repeated in JavaStubWriter.            boolean process = true;            // Don't register types we shouldn't (see Utils.shouldEmit for            // details)            if (!Utils.shouldEmit(type)) {                process = false;            }            if (process) {                String namespaceURI = type.getQName().getNamespaceURI();                String localPart = type.getQName().getLocalPart();                String javaType = type.getName();                String serializerFactory;                String deserializerFactory;                String encodingStyle = "";                QName innerType = null;                if (!hasLiteral) {                    encodingStyle = use.getEncoding();                }                if (javaType.endsWith("[]")) {                    if (SchemaUtils.isListWithItemType(type.getNode())) {                        serializerFactory =                        "org.apache.axis.encoding.ser.SimpleListSerializerFactory";                        deserializerFactory =                        "org.apache.axis.encoding.ser.SimpleListDeserializerFactory";                    } else {                        serializerFactory =                        "org.apache.axis.encoding.ser.ArraySerializerFactory";                        deserializerFactory =                        "org.apache.axis.encoding.ser.ArrayDeserializerFactory";                        innerType = type.getComponentType();                    }                } else if ((type.getNode() != null) && (Utils.getEnumerationBaseAndValues(                        type.getNode(), symbolTable) != null)) {                    serializerFactory =                            "org.apache.axis.encoding.ser.EnumSerializerFactory";                    deserializerFactory =                            "org.apache.axis.encoding.ser.EnumDeserializerFactory";                } else if (type.isSimpleType()) {                    serializerFactory =                            "org.apache.axis.encoding.ser.SimpleSerializerFactory";                    deserializerFactory =                            "org.apache.axis.encoding.ser.SimpleDeserializerFactory";                } else if (type.getBaseType() != null) {                    serializerFactory =                            "org.apache.axis.encoding.ser.SimpleSerializerFactory";                    deserializerFactory =                            "org.apache.axis.encoding.ser.SimpleDeserializerFactory";                } else {                    serializerFactory =                            "org.apache.axis.encoding.ser.BeanSerializerFactory";                    deserializerFactory =                            "org.apache.axis.encoding.ser.BeanDeserializerFactory";                }                if (innerType == null) {                    // no arrays                    writeTypeMapping(pw, namespaceURI, localPart, javaType,                        serializerFactory, deserializerFactory,                        encodingStyle);                } else {                    // arrays                    writeArrayTypeMapping(pw, namespaceURI, localPart, javaType,                            encodingStyle, innerType);                }            }        }    }    // writeDeployTypes    /**     * Raw routine that writes out the typeMapping.     *     * @param pw     * @param namespaceURI     * @param localPart     * @param javaType     * @param serializerFactory     * @param deserializerFactory     * @param encodingStyle     * @throws IOException     */    protected void writeArrayTypeMapping(            PrintWriter pw, String namespaceURI, String localPart, String javaType, String encodingStyle, QName innerType)            throws IOException {        pw.println("      <arrayMapping");        pw.println("        xmlns:ns=\"" + namespaceURI + "\"");        pw.println("        qname=\"ns:" + localPart + '"');        pw.println("        type=\"java:" + javaType + '"');        pw.println("        innerType=\"" + Utils.genQNameAttributeString(innerType, "cmp-ns") + '"');        pw.println("        encodingStyle=\"" + encodingStyle + "\"");        pw.println("      />");    }    /**     * Raw routine that writes out the typeMapping.     *     * @param pw     * @param namespaceURI     * @param localPart     * @param javaType     * @param serializerFactory     * @param deserializerFactory     * @param encodingStyle     * @throws IOException     */    protected void writeTypeMapping(            PrintWriter pw, String namespaceURI, String localPart, String javaType, String serializerFactory, String deserializerFactory, String encodingStyle)            throws IOException {        pw.println("      <typeMapping");        pw.println("        xmlns:ns=\"" + namespaceURI + "\"");        pw.println("        qname=\"ns:" + localPart + '"');        pw.println("        type=\"java:" + javaType + '"');        pw.println("        serializer=\"" + serializerFactory + "\"");        pw.println("        deserializer=\"" + deserializerFactory + "\"");        pw.println("        encodingStyle=\"" + encodingStyle + "\"");        pw.println("      />");    }    /**     * Write out deployment and undeployment instructions for given WSDL port     *     * @param pw     * @param port     * @param service     * @param bEntry     * @throws IOException     */    protected void writeDeployPort(            PrintWriter pw, Port port, Service service, BindingEntry bEntry)            throws IOException {        String serviceName = port.getName();        boolean hasLiteral = bEntry.hasLiteral();        boolean hasMIME = Utils.hasMIME(bEntry);        String prefix = WSDDConstants.NS_PREFIX_WSDD_JAVA;        String styleStr = "";        Iterator iterator =                bEntry.getBinding().getExtensibilityElements().iterator();        while (iterator.hasNext()) {            Object obj = iterator.next();            if (obj instanceof SOAPBinding) {                use = Use.ENCODED;            } else if (obj instanceof UnknownExtensibilityElement) {                // TODO: After WSDL4J supports soap12, change this code                UnknownExtensibilityElement unkElement =                        (UnknownExtensibilityElement) obj;                QName name =                        unkElement.getElementType();                if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP)                        && name.getLocalPart().equals("binding")) {                    use = Use.ENCODED;                }            }        }        if (symbolTable.isWrapped()) {            styleStr = " style=\"" + Style.WRAPPED + "\"";            use = Use.LITERAL;        } else {            styleStr = " style=\"" + bEntry.getBindingStyle().getName() + "\"";            if (hasLiteral) {                use = Use.LITERAL;            }        }

⌨️ 快捷键说明

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