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

📄 types.java

📁 Java有关XML编程需要用到axis 的源代码 把里面bin下的包导入相应的Java工程 进行使用
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    /**     * Write out a type referenced by a part type attribute.     *     * @param type  <code>Class</code> to generate the XML Schema info for     * @param qname <code>QName</code> of the type.  If null, qname is     *              defaulted from the class.     * @return the QName of the generated Schema type, null if void,     *         if the Class type cannot be converted to a schema type     *         then xsd:anytype is returned.     * @throws AxisFault     */    public QName writeTypeForPart(Class type, QName qname) throws AxisFault {        // patch by costin to fix an NPE; commented out till we find out what the problem is        // if you get NullPointerExceptions in this class, turn it on and submit some        // replicable test data to the Axis team via bugzilla        /*        * if( type==null ) {        *   return null;        * }        */        if (type.getName().equals("void")) {            return null;        }        if (Holder.class.isAssignableFrom(type)) {            type = JavaUtils.getHolderValueType(type);        }        // Get the qname        if ((qname == null)                || (Constants.isSOAP_ENC(qname.getNamespaceURI())                && "Array".equals(qname.getLocalPart()))) {            qname = getTypeQName(type);            if (qname == null) {                throw new AxisFault("Class:" + type.getName());            }        }        if (!makeTypeElement(type, qname, null)) {            qname = Constants.XSD_ANYTYPE;        }        return qname;    }    /**     * Write out a type (and its subtypes) referenced by a part type attribute.     *     * @param type <code>Class</code> to generate the XML Schema info for     * @param qname <code>QName</code> of the type.  If null, qname is     *             defaulted from the class.     * @return the QName of the generated Schema type, null if void,     *         if the Class type cannot be converted to a schema type     *         then xsd:anytype is returned.     */    public QName writeTypeAndSubTypeForPart(Class type, QName qname)            throws AxisFault {        // Write out type in parameter        QName qNameRet = writeTypeForPart(type, qname);        // If mappedTypesexists         // Will write subTypes of the type in parameters        if (mappedTypes != null) {            for (int i = 0; i < mappedTypes.length; i++) {                Class tempMappedType = mappedTypes[i];                QName name;                // If tempMappedType is subtype of the "type" parameter                // and type is not Object (Object superclass of all Java class...)                  // write the subtype                if (tempMappedType != null &&                        type != Object.class &&                        tempMappedType != type &&                        type.isAssignableFrom(tempMappedType)) {                    name = tm.getTypeQName(tempMappedType);                    if (!isAnonymousType(name)) {                        writeTypeForPart(tempMappedType, name);                    }                    // Only do each one once.  This is OK to do because each                    // Types instance is for generating a single WSDL.                    mappedTypes[i] = null;                }            }        } //if (mappedTyped != null) {        return qNameRet;    }    /**     * Write out an element referenced by a part element attribute.     *     * @param type  <code>Class</code> to generate the XML Schema info for     * @param qname <code>QName</code> of the element.  If null, qname is     *              defaulted from the class.     * @return the QName of the generated Schema type, null if no element     * @throws AxisFault     */    public QName writeElementForPart(Class type, QName qname) throws AxisFault {        // patch by costin to fix an NPE; commented out till we find out what the problem is        // if you get NullPointerExceptions in this class, turn it on and submit some        // replicable test data to the Axis team via bugzilla        /*        * if( type==null ) {        *   return null;        * }        */        if (type.getName().equals("void")) {            return null;        }        if (Holder.class.isAssignableFrom(type)) {            type = JavaUtils.getHolderValueType(type);        }        // Get the qname        if ((qname == null)                || (Constants.isSOAP_ENC(qname.getNamespaceURI())                && "Array".equals(qname.getLocalPart()))) {            qname = getTypeQName(type);            if (qname == null) {                throw new AxisFault("Class:" + type.getName());            }        }        // Return null it a simple type (not an element)        String nsURI = qname.getNamespaceURI();        if (Constants.isSchemaXSD(nsURI)                || (Constants.isSOAP_ENC(nsURI)                && !"Array".equals(qname.getLocalPart()))) {            return null;        }        // Make sure a types section is present        if (wsdlTypesElem == null) {            writeWsdlTypesElement();        }        // Write Element, if problems occur return null.        if (writeTypeAsElement(type, qname) == null) {            qname = null;        }        return qname;    }    /**     * Write the element definition for a WRAPPED operation.  This will     * write out any necessary namespace/schema declarations, an an element     * definition with an internal (anonymous) complexType.  The name of the     * element will be *foo*Request or *foo*Response depending on whether the     * request boolean is true.  If the operation contains parameters, then     * we also generate a &gt;sequence&lt; node underneath the complexType,     * and return it for later use by writeWrappedParameter() below.     *     * @param qname     the desired element QName     * @param request   true if we're writing the request wrapper, false if     *                  writing the response.     * @param hasParams true if there are parameters, and thus a sequence     *                  node is needed     * @return a DOM Element for the sequence, inside which we'll write the     *         parameters as elements, or null if there are no parameters     * @throws AxisFault     */    public Element writeWrapperElement(            QName qname, boolean request, boolean hasParams) throws AxisFault {        // Make sure a types section is present        if (wsdlTypesElem == null) {            writeWsdlTypesElement();        }        // Write the namespace definition for the wrapper        writeTypeNamespace(qname.getNamespaceURI());        // Create an <element> for the wrapper        Element wrapperElement = docHolder.createElement("element");        writeSchemaElementDecl(qname, wrapperElement);        wrapperElement.setAttribute("name", qname.getLocalPart());        // Create an anonymous <complexType> for the wrapper        Element complexType = docHolder.createElement("complexType");        wrapperElement.appendChild(complexType);        // If we have parameters in the operation, create a <sequence>        // under the complexType and return it.        if (hasParams) {            Element sequence = docHolder.createElement("sequence");            complexType.appendChild(sequence);            return sequence;        }        return null;    }    /**     * Write a parameter (a sub-element) into a sequence generated by     * writeWrapperElement() above.     *     * @param sequence the &lt;sequence&gt; in which we're writing     * @param name     is the name of an element to add to the wrapper element.     * @param type     is the QName of the type of the element.     * @param javaType     * @throws AxisFault     */    public void writeWrappedParameter(            Element sequence, String name, QName type, Class javaType)            throws AxisFault {        if (javaType == void.class) {            return;        }        // JAX-RPC 1.1 says that byte[] should always be a Base64Binary        // This (rather strange) hack will ensure that we don't map it        // in to an maxoccurs=unbounded array.        if (javaType.isArray() && !javaType.equals(byte[].class)) {            type = writeTypeForPart(javaType.getComponentType(), null);        } else {            type = writeTypeForPart(javaType, type);        }        if (type == null) {            // TODO: throw an Exception!!            return;        }        Element childElem;        if (isAnonymousType(type)) {            childElem = createElementWithAnonymousType(name, javaType, false,                    docHolder);        } else {            // Create the child <element> and add it to the wrapper <sequence>            childElem = docHolder.createElement("element");            childElem.setAttribute("name", name);            String prefix =                    namespaces.getCreatePrefix(type.getNamespaceURI());            String prefixedName = prefix + ":" + type.getLocalPart();            childElem.setAttribute("type", prefixedName);            // JAX-RPC 1.1 says that byte[] should always be a Base64Binary            // This (rather strange) hack will ensure that we don't map it            // in to an maxoccurs=unbounded array.            if (javaType.isArray() && !javaType.equals(byte[].class)) {                childElem.setAttribute("maxOccurs", "unbounded");            }        }        sequence.appendChild(childElem);    }    /**     * Method isAnonymousType     *     * @param type     * @return     */    private boolean isAnonymousType(QName type) {        return type.getLocalPart().indexOf(SymbolTable.ANON_TOKEN) != -1;    }    /**     * Create a schema element for the given type     *     * @param type  the class type     * @param qName     * @return the QName of the generated Element or problems occur     * @throws AxisFault     */    private QName writeTypeAsElement(Class type, QName qName) throws AxisFault {        if ((qName == null) || Constants.equals(Constants.SOAP_ARRAY, qName)) {            qName = getTypeQName(type);        }        writeTypeNamespace(type, qName);        String elementType = writeType(type, qName);        if (elementType != null) {            // Element element = createElementDecl(qName.getLocalPart(), type, qName, isNullable(type), false);            // if (element != null)            // writeSchemaElement(typeQName,element);            return qName;        }        return null;    }    /**     * write out the namespace declaration and return the type QName for the     * given <code>Class</code>     *     * @param type  input Class     * @param qName qname of the Class     * @return QName for the schema type representing the class     */    private QName writeTypeNamespace(Class type, QName qName) {        if (qName == null) {            qName = getTypeQName(type);        }        writeTypeNamespace(qName.getNamespaceURI());        return qName;    }    /**     * write out the namespace declaration.     *     * @param namespaceURI qname of the type     */    private void writeTypeNamespace(String namespaceURI) {        if ((namespaceURI != null) && !namespaceURI.equals("")) {            String pref = def.getPrefix(namespaceURI);            if (pref == null) {                def.addNamespace(namespaces.getCreatePrefix(namespaceURI),                        namespaceURI);            }        }    }    /**     * Return the QName of the specified javaType     *     * @param javaType input javaType Class     * @return QName     */    public QName getTypeQName(Class javaType) {        QName qName = null;        // Use the typeMapping information to lookup the qName.        qName = tm.getTypeQName(javaType);        // If the javaType is an array and the qName is        // SOAP_ARRAY, construct the QName using the        // QName of the component type        if (isArray(javaType) &&                Constants.equals(Constants.SOAP_ARRAY, qName)) {            Class componentType = getComponentType(javaType);            // For WS-I BP compliance, we can't use "ArrayOf" as a type prefix             // instead use "MyArrayOf" (gag)             String arrayTypePrefix = "ArrayOf";            boolean isWSICompliant = JavaUtils.isTrue(                    AxisProperties.getProperty(Constants.WSIBP11_COMPAT_PROPERTY));            if (isWSICompliant) {                arrayTypePrefix = "MyArrayOf";            }            // If component namespace uri == targetNamespace            // Construct ArrayOf<componentLocalPart>            // Else            // Construct ArrayOf_<componentPrefix>_<componentLocalPart>            QName cqName = getTypeQName(componentType);            if (targetNamespace.equals(cqName.getNamespaceURI())) {

⌨️ 快捷键说明

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