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

📄 javabeanwriter.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.utils.JavaUtils;import org.apache.axis.utils.Messages;import org.apache.axis.wsdl.symbolTable.ContainedAttribute;import org.apache.axis.wsdl.symbolTable.ElementDecl;import org.apache.axis.wsdl.symbolTable.SchemaUtils;import org.apache.axis.wsdl.symbolTable.TypeEntry;import org.w3c.dom.DOMException;import org.w3c.dom.Node;import java.io.IOException;import java.io.PrintWriter;import java.util.ArrayList;import java.util.HashSet;import java.util.Iterator;import java.util.Set;import java.util.Vector;/** * This is Wsdl2java's Complex Type Writer.  It writes the <typeName>.java file. */public class JavaBeanWriter extends JavaClassWriter {    /** Field type */    private TypeEntry type;    /** Field elements */    private Vector elements;    /** Field attributes */    private Vector attributes;    /** Field extendType */    private TypeEntry extendType;    /** Field helper */    protected JavaBeanHelperWriter helper;    /** Field names */    protected Vector names = new Vector();    // even indices: types, odd: vars    /** Field simpleValueTypes */    protected ArrayList simpleValueTypes =            new ArrayList();                      // name of type of simple value    /** Field enumerationTypes */    protected Set enumerationTypes = new HashSet();    // name of enumerated types    /** Field pw */    protected PrintWriter pw;    // The following fields can be set by extended classes    // to control processing    /** Field enableDefaultConstructor */    protected boolean enableDefaultConstructor = true;    /** Field enableFullConstructor */    protected boolean enableFullConstructor = false;    /** Field enableSimpleConstructors */    protected boolean enableSimpleConstructors = false;    /** Field enableToString */    protected boolean enableToString = false;    /** Field enableSetters */    protected boolean enableSetters = true;    /** Field enableGetters */    protected boolean enableGetters = true;    /** Field enableEquals */    protected boolean enableEquals = true;    /** Field enableHashCode */    protected boolean enableHashCode = true;    /** Field enableMemberFields */    protected boolean enableMemberFields = true;    /** Field isAny */    protected boolean isAny = false;    /** Field isMixed */    protected boolean isMixed = false;        /** Field parentIsAny */    protected boolean parentIsAny = false;    /** Field parentIsMixed */    protected boolean parentIsMixed = false;        /**     * Constructor.     *      * @param emitter         * @param type       The type representing this class     * @param elements   Vector containing the Type and name of each property     * @param extendType The type representing the extended class (or null)     * @param attributes Vector containing the attribute types and names     * @param helper     Helper class writer     */    protected JavaBeanWriter(Emitter emitter, TypeEntry type, Vector elements,                             TypeEntry extendType, Vector attributes,                             JavaWriter helper) {        super(emitter, type.getName(), "complexType");        this.type = type;        this.elements = elements;        this.attributes = attributes;        this.extendType = extendType;        this.helper = (JavaBeanHelperWriter) helper;        if (type.isSimpleType()) {            enableSimpleConstructors = true;            enableToString = true;        } else {            // is this a complex type that is derived from other types            // by restriction?  if so, do not emit instance variables            // or accessor/mutator pairs as those are inherited from            // the super type, which must be non-null.            if (null != extendType) {            	if (null != SchemaUtils.getComplexElementRestrictionBase(                        type.getNode(), emitter.getSymbolTable())) {	                enableMemberFields = false;	                enableGetters = false;	                enableSetters = false;	                enableEquals = false;	                enableHashCode = false;            	} else {            		// derived by extension.            		// Write full constructor, so that instance variables            		// in super class are intialized.        			enableFullConstructor = true;            	}            }        }        preprocess();    }    // ctor    /**     * Write a common header, including the package name, the class     * declaration, and the opening curly brace.       * Prints javadoc from WSDL documentation.  (Cannot pull up, type DOM not avail)     */    protected void writeFileHeader(PrintWriter pw) throws IOException {        writeHeaderComments(pw);        writePackage(pw);            try        {            String comments = SchemaUtils.getAnnotationDocumentation(type.getNode());            comments = getJavadocDescriptionPart(comments, false);            if (comments != null && comments.trim().length() > 0)            {                pw.println();                pw.println("/**");                pw.println(comments);                pw.println(" */");            }        }        catch (DOMException e)        {            // no comment        }                // print class declaration        pw.println(getClassModifiers() + getClassText() + getClassName() + ' ' + getExtendsText() + getImplementsText() + "{");    } // writeFileHeader    /**     * Generate the binding for the given complex type.     *      * @param pw      * @throws IOException      */    protected void writeFileBody(PrintWriter pw) throws IOException {        this.pw = pw;        // Populate Names Vector with the names and types of the members.        // The write methods use the names vector whenever they need to get        // a member name or type. Moved to implements callback in order        // to set any interface        // preprocess();        // Write Member Fields        if (enableMemberFields) {            writeMemberFields();        }        // Write the default constructor        if (enableDefaultConstructor) {            writeDefaultConstructor();        }        // Write Full Constructor        if (enableFullConstructor) {            writeFullConstructor();        }         // Write SimpleConstructors        if (enableSimpleConstructors) {            writeSimpleConstructors();        }                if(!enableFullConstructor && !enableSimpleConstructors && enableMemberFields) {            writeMinimalConstructor();        }        // Write ToString method        if (enableToString) {            writeToStringMethod();        }        // Write accessor methods        writeAccessMethods();        // Write general purpose equals and hashCode methods        if (enableEquals) {            writeEqualsMethod();        }        if (enableHashCode) {            writeHashCodeMethod();        }        // Write the meta data into a Helper class or        // embed it in the bean class        if (!emitter.isHelperWanted()) {            // Write the helper info into the bean class            helper.setPrintWriter(pw);        }        helper.generate();    }    // writeFileBody    /**     * Builds the names String vector.     * The even indices are the java class names of the     * member fields.  The odd indices are the member variable     * names.     * Also sets the simpleValueType variable to the     * java class name of the simple value if this bean represents     * a simple type     */    protected void preprocess() {                // Add element names        if (elements != null) {            // Check the inheritance chain for xs:any and xs:mixed            TypeEntry parent = extendType;            while ((!parentIsAny || !parentIsMixed) && parent != null) {                if (SchemaUtils.isMixed(parent.getNode())) {                    parentIsMixed = true;                }                Vector hisElements = parent.getContainedElements();                for (int i = 0; hisElements != null && i < hisElements.size(); i++) {                    ElementDecl elem = (ElementDecl) hisElements.get(i);                    if (elem.getAnyElement()) {                        parentIsAny = true;                    }                }                parent =                    SchemaUtils.getComplexElementExtensionBase(parent.getNode(),                            emitter.getSymbolTable());            }            for (int i = 0; i < elements.size(); i++) {                ElementDecl elem = (ElementDecl) elements.get(i);                String typeName = elem.getType().getName();                String variableName = null;                if (elem.getAnyElement()) {                    if (!parentIsAny && !parentIsMixed) {                        typeName = "org.apache.axis.message.MessageElement []";                        variableName = Constants.ANYCONTENT;                    }                    isAny = true;                } else {                    variableName = elem.getName();                    typeName = processTypeName(elem, typeName);                }                if (variableName == null) {                    continue;                }                // Make sure the property name is not reserved.                variableName = JavaUtils.getUniqueValue(                        helper.reservedPropNames, variableName);                names.add(typeName);                names.add(variableName);                if (type.isSimpleType()                        && (variableName.endsWith("Value")                        || variableName.equals("_value"))) {                    simpleValueTypes.add(typeName);                }                // bug 19069: need to generate code that access member variables that                // are enum types through the class interface, not the constructor                // this util method returns non-null if the type at node is an enum                if (null != Utils.getEnumerationBaseAndValues(                        elem.getType().getNode(), emitter.getSymbolTable())) {                    enumerationTypes.add(typeName);                }            }        }        if (enableMemberFields && SchemaUtils.isMixed(type.getNode())) {            isMixed = true;            if (!isAny && !parentIsAny && !parentIsMixed) {                names.add("org.apache.axis.message.MessageElement []");                names.add(Constants.ANYCONTENT);            }        }        // Add attribute names        if (attributes != null) {            for (int i = 0; i < attributes.size(); i++) {                ContainedAttribute attr = (ContainedAttribute) attributes.get(i);                String typeName = attr.getType().getName();                String variableName = getAttributeName(attr);                // TODO - What about MinOccurs and Nillable?                // Do they make sense here?                if (attr.getOptional()) {

⌨️ 快捷键说明

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