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

📄 arrayserializer.java

📁 Java有关XML编程需要用到axis 的源代码 把里面bin下的包导入相应的Java工程 进行使用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            // Vidyanand : added this check            if( msgContext != null ) {               enable2Dim = JavaUtils.isTrueExplicitly(msgContext.getProperty(                       AxisEngine.PROP_TWOD_ARRAY_ENCODING));            }            if (enable2Dim && !dims.equals("")) {                if (cls.isArray() && len > 0) {                    boolean okay = true;                    // Make sure all of the component arrays are the same size                    for (int i=0; i < len && okay; i++) {                        Object elementValue = Array.get(value, i);                        if (elementValue == null)                            okay = false;                        else if (dim2Len < 0) {                            dim2Len = Array.getLength(elementValue);                            if (dim2Len <= 0) {                                okay = false;                            }                        } else if (dim2Len != Array.getLength(elementValue)) {                            okay = false;                        }                    }                    // Update the arrayType to use mult-dim array encoding                    if (okay) {                        dims = dims.substring(0, dims.length()-2);                        if (soap == SOAPConstants.SOAP12_CONSTANTS)                            arrayType = dims + len + " " + dim2Len;                        else                            arrayType = dims + "[" + len + "," + dim2Len + "]";                    } else {                        dim2Len = -1;                    }                }            }        }        // Need to distinguish if this is array processing for an        // actual schema array or for a maxOccurs usage.        // For the maxOccurs case, the currentXMLType of the context is        // the same as the componentTypeQName.        QName itemQName = context.getItemQName();        boolean maxOccursUsage = !encoded && itemQName == null &&                componentTypeQName.equals(context.getCurrentXMLType());        if (encoded) {            AttributesImpl attrs;            if (attributes == null) {                attrs = new AttributesImpl();            } else if (attributes instanceof AttributesImpl) {                attrs = (AttributesImpl)attributes;            } else {                attrs = new AttributesImpl(attributes);            }            String compType = context.attributeQName2String(componentTypeQName);            if (attrs.getIndex(soap.getEncodingURI(), soap.getAttrItemType()) == -1) {                String encprefix =                       context.getPrefixForURI(soap.getEncodingURI());                if (soap != SOAPConstants.SOAP12_CONSTANTS) {                    compType = compType + arrayType;                                        attrs.addAttribute(soap.getEncodingURI(),                                       soap.getAttrItemType(),                                       encprefix + ":arrayType",                                       "CDATA",                                       compType);                } else {                    attrs.addAttribute(soap.getEncodingURI(),                                       soap.getAttrItemType(),                                       encprefix + ":itemType",                                       "CDATA",                                       compType);                    attrs.addAttribute(soap.getEncodingURI(),                                       "arraySize",                                       encprefix + ":arraySize",                                       "CDATA",                                   arrayType);                }            }            // Force type to be SOAP_ARRAY for all array serialization.            //            // There are two choices here:            // Force the type to type=SOAP_ARRAY            //   Pros:  More interop test successes.            //   Cons:  Since we have specific type information it            //          is more correct to use it.  Plus the specific            //          type information may be important on the            //          server side to disambiguate overloaded operations.            // Use the specific type information:            //   Pros:  The specific type information is more correct            //          and may be useful for operation overloading.            //   Cons:  More interop test failures (as of 2/6/2002).            //            String qname =                    context.getPrefixForURI(schema.getXsiURI(),                                            "xsi") + ":type";            QName soapArray;            if (soap == SOAPConstants.SOAP12_CONSTANTS) {                soapArray = Constants.SOAP_ARRAY12;            } else {                soapArray = Constants.SOAP_ARRAY;            }            int typeI = attrs.getIndex(schema.getXsiURI(),                                       "type");            if (typeI != -1) {                attrs.setAttribute(typeI,                                   schema.getXsiURI(),                                   "type",                                   qname,                                   "CDATA",                                   context.qName2String(soapArray));            } else {                attrs.addAttribute(schema.getXsiURI(),                                   "type",                                   qname,                                   "CDATA",                                   context.qName2String(soapArray));            }            attributes = attrs;        }        // For the maxOccurs case, each item is named with the QName        // we got in the arguments.  For normal array case, we write an element with        // that QName, and then serialize each item as <item>        QName elementName = name;        Attributes serializeAttr = attributes;        if (!maxOccursUsage) {            serializeAttr = null;  // since we are putting them here            context.startElement(name, attributes);            if (itemQName != null)                elementName = itemQName;            else if(componentQName != null)                elementName = componentQName;        }        if (dim2Len < 0) {            // Normal case, serialize each array element            if (list == null) {                for (int index = 0; index < len; index++) {                    Object aValue = Array.get(value, index);                    // Serialize the element.                    context.serialize(elementName,                            (serializeAttr == null ?                            serializeAttr : new AttributesImpl(serializeAttr)),                            aValue,                            componentTypeQName, componentClass); // prefered type QName                }            } else {                for (Iterator iterator = list.iterator(); iterator.hasNext();) {                    Object aValue = iterator.next();                    // Serialize the element.                    context.serialize(elementName,                            (serializeAttr == null ?                            serializeAttr : new AttributesImpl(serializeAttr)),                            aValue,                            componentTypeQName, componentClass); // prefered type QName                }            }        } else {            // Serialize as a 2 dimensional array            for (int index = 0; index < len; index++) {                for (int index2 = 0; index2 < dim2Len; index2++) {                    Object aValue = Array.get(Array.get(value, index), index2);                    context.serialize(elementName, null, aValue, componentTypeQName, componentClass);                }            }        }        if (!maxOccursUsage)            context.endElement();    }    public String getMechanismType() { return Constants.AXIS_SAX; }    private static boolean isArray(Class clazz)    {        return clazz.isArray() || java.util.Collection.class.isAssignableFrom(clazz);    }    private static Class getComponentType(Class clazz)    {        if (clazz.isArray())        {            return clazz.getComponentType();        }        else if (java.util.Collection.class.isAssignableFrom(clazz))        {            return Object.class;        }        else        {            return null;        }    }    /**     * Return XML schema for the specified type, suitable for insertion into     * the &lt;types&gt; element of a WSDL document, or underneath an     * &lt;element&gt; or &lt;attribute&gt; declaration.     *     * @param javaType the Java Class we're writing out schema for     * @param types the Java2WSDL Types object which holds the context     *              for the WSDL being generated.     * @return a type element containing a schema simpleType/complexType     * @see org.apache.axis.wsdl.fromJava.Types     */    public Element writeSchema(Class javaType, Types types) throws Exception {        boolean encoded = true;        MessageContext mc = MessageContext.getCurrentContext();        if (mc != null) {            encoded = mc.isEncoded();        } else {            encoded = types.getServiceDesc().getUse() == Use.ENCODED;        }                if (!encoded) {            Class cType = Object.class;            if (javaType.isArray()) {                cType = javaType.getComponentType();            }            String typeName = types.writeType(cType);            return types.createLiteralArrayElement(typeName, null);        }                // If an array the component type should be processed first        String componentTypeName = null;        Class componentType = null;        if (isArray(javaType)) {            String dimString = "[]";            componentType = getComponentType(javaType);            while (isArray(componentType)) {                dimString += "[]";                componentType = getComponentType(componentType);            }            types.writeType(componentType,null);            componentTypeName =                    types.getQNameString(types.getTypeQName(componentType)) +                    dimString;        }        // Use Types helper method to actually create the complexType        return types.createArrayElement(componentTypeName);    }}

⌨️ 快捷键说明

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