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

📄 types.java

📁 Java有关XML编程需要用到axis 的源代码 把里面bin下的包导入相应的Java工程 进行使用
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                        && Modifier.isPublic(m3.getModifiers()) && (m4 != null)                        && Modifier.isStatic(m4.getModifiers())                        && Modifier.isPublic(m4.getModifiers())) {                    // Return false if there is a setValue member method                    try {                        if (cls.getMethod("setValue", new Class[]{                            m.getReturnType()}) == null) {                            return true;                        }                        return false;                    } catch (java.lang.NoSuchMethodException e) {                        return true;                    }                }            }        } catch (java.lang.NoSuchMethodException e) {        }        return false;    }    /**     * Write Enumeration Complex Type     * (Only supports enumeration classes of string types)     *     * @param qName QName of type.     * @param cls   class of type     * @return     * @throws NoSuchMethodException     * @throws IllegalAccessException     * @throws AxisFault     */    public Element writeEnumType(QName qName, Class cls)            throws NoSuchMethodException, IllegalAccessException, AxisFault {        if (!isEnumClass(cls)) {            return null;        }        // Get the base type of the enum class        java.lang.reflect.Method m = cls.getMethod("getValue", null);        Class base = m.getReturnType();        // Create simpleType, restriction elements        Element simpleType = docHolder.createElement("simpleType");        simpleType.setAttribute("name", qName.getLocalPart());        Element restriction = docHolder.createElement("restriction");        simpleType.appendChild(restriction);        String baseType = writeType(base, null);        restriction.setAttribute("base", baseType);        // Create an enumeration using the field values        Field[] fields = cls.getDeclaredFields();        for (int i = 0; i < fields.length; i++) {            Field field = fields[i];            int mod = field.getModifiers();            // Inspect each public static final field of the same type            // as the base            if (Modifier.isPublic(mod) && Modifier.isStatic(mod)                    && Modifier.isFinal(mod) && (field.getType() == base)) {                // Create an enumeration using the value specified                Element enumeration = docHolder.createElement("enumeration");                enumeration.setAttribute("value", field.get(null).toString());                restriction.appendChild(enumeration);            }        }        return simpleType;    }    /**     * Create a top-level element declaration in our generated schema     *     * @param qname     * @param javaType     * @param typeQName     * @param nillable  nillable attribute of the element     * @param itemQName     * @throws AxisFault     */    public void writeElementDecl(QName qname,                                 Class javaType,                                 QName typeQName,                                 boolean nillable,                                 QName itemQName)            throws AxisFault {        if (writtenElementQNames.contains(qname)) {            return;        }        String name = qname.getLocalPart();        Element element = docHolder.createElement("element");        // Generate an element name that matches the type.        element.setAttribute("name", name);        if (nillable) {            element.setAttribute("nillable", "true");        }        /*         * These are not legal on top-level elements!         * (feel free to delete this block after say Oct 2005)        if (omittable) {            element.setAttribute("minOccurs", "0");            element.setAttribute("maxOccurs", "1");        }        if (javaType.isArray()) {            element.setAttribute("maxOccurs", "unbounded");        }        */        if (javaType.isArray()) {            // TODO : Should check to see if this array type is specifically mapped            String componentType = writeType(javaType.getComponentType());            Element complexType = createLiteralArrayElement(componentType,                                                            itemQName);            element.appendChild(complexType);        } else {            // Write the type for this element, handling anonymous or named            // types appropriately.            makeTypeElement(javaType, typeQName, element);        }        writeSchemaElementDecl(qname, element);    }    /**     * Create Element with a given name and type     *     * @param elementName the name of the created element     * @param elementType schema type representation of the element     * @param nullable    nullable attribute of the element     * @param omittable     * @param docHolder     * @return the created Element     */    public Element createElement(String elementName, String elementType,                                 boolean nullable, boolean omittable,                                 Document docHolder) {        Element element = docHolder.createElement("element");        element.setAttribute("name", elementName);        if (nullable) {            element.setAttribute("nillable", "true");        }        if (omittable) {            element.setAttribute("minOccurs", "0");            element.setAttribute("maxOccurs", "1");        }        if (elementType != null) {            element.setAttribute("type", elementType);        }        return element;    }    /**     * Create Attribute Element with a given name and type     *     * @param elementName the name of the created element     * @param javaType     * @param xmlType     * @param nullable    nullable attribute of the element     * @param docHolder     * @return the created Element     * @throws AxisFault     */    public Element createAttributeElement(            String elementName, Class javaType, QName xmlType, boolean nullable, Document docHolder)            throws AxisFault {        Element element = docHolder.createElement("attribute");        element.setAttribute("name", elementName);        if (nullable) {            element.setAttribute("nillable", "true");        }        makeTypeElement(javaType, xmlType, element);        return element;    }    /**     * Is the given class one of the simple types?  In other words,     * do we have a mapping for this type which is in the xsd or     * soap-enc namespaces?     *     * @param type input Class     * @return true if the type is a simple type     */    boolean isSimpleType(Class type) {        QName qname = tm.getTypeQName(type);        if (qname == null) {            return false;    // No mapping        }        String nsURI = qname.getNamespaceURI();        return (Constants.isSchemaXSD(nsURI) || Constants.isSOAP_ENC(nsURI));    }    /**     * Is the given class acceptable as an attribute     *     * @param type input Class     * @return true if the type is a simple, enum type or extends SimpleType     */    public boolean isAcceptableAsAttribute(Class type) {        return isSimpleType(type) || isEnumClass(type)                || implementsSimpleType(type);    }    /**     * Does the class implement SimpleType     *     * @param type input Class     * @return true if the type implements SimpleType     */    boolean implementsSimpleType(Class type) {        Class[] impls = type.getInterfaces();        for (int i = 0; i < impls.length; i++) {            if (impls[i] == SimpleType.class) {                return true;            }        }        return false;    }    /**     * Generates a unique element name for a given namespace of the form     * el0, el1 ....     *     * @param qName the namespace for the generated element     * @return elementname     */    // *** NOT USED? ***    //    // private String generateUniqueElementName(QName qName) {    // Integer count = (Integer)schemaUniqueElementNames.get(qName.getNamespaceURI());    // if (count == null)    // count = new Integer(0);    // else    // count = new Integer(count.intValue() + 1);    // schemaUniqueElementNames.put(qName.getNamespaceURI(), count);    // return "el" + count.intValue();    // }    /**     * Add the type to an ArrayList and return true if the Schema node     * needs to be generated     * If the type already exists, just return false to indicate that the type is already     * generated in a previous iteration     *     * @param qName of the type.     * @return if the type is added returns true,     *         else if the type is already present returns false     */    private boolean addToTypesList(QName qName) {        boolean added = false;        String namespaceURI = qName.getNamespaceURI();        ArrayList types = (ArrayList) schemaTypes.get(namespaceURI);        // Quick return if schema type (will never add these ourselves)        if (Constants.isSchemaXSD(namespaceURI)                || (Constants.isSOAP_ENC(namespaceURI)                && !"Array".equals(qName.getLocalPart()))) {            // Make sure we do have the namespace declared, though...            writeTypeNamespace(namespaceURI);            return false;        }        if (types == null) {            types = new ArrayList();            types.add(qName.getLocalPart());            writeTypeNamespace(namespaceURI);            schemaTypes.put(namespaceURI, types);            added = true;        } else {            if (!types.contains(qName.getLocalPart())) {                types.add(qName.getLocalPart());                added = true;            }        }        // If addded, look at the namespace uri to see if the schema element should be        // generated.        if (added) {            String prefix = namespaces.getCreatePrefix(namespaceURI);            if (prefix.equals(Constants.NS_PREFIX_SOAP_ENV)                    || prefix.equals(Constants.NS_PREFIX_SOAP_ENC)                    || prefix.equals(Constants.NS_PREFIX_SCHEMA_XSD)                    || prefix.equals(Constants.NS_PREFIX_WSDL)                    || prefix.equals(Constants.NS_PREFIX_WSDL_SOAP)) {                return false;            } else {                return true;            }        }        return false;    }    /**     * Add the element to an ArrayList and return true if the Schema element     * needs to be generated     * If the element already exists, just return false to indicate that the type is already     * generated in a previous iteration     *     * @param qName the name space of the element     * @return if the type is added returns true, else if the type is already present returns false     */    private boolean addToElementsList(QName qName) {        if (qName == null) {            return false;        }        boolean added = false;        ArrayList elements =                (ArrayList) schemaElementNames.get(qName.getNamespaceURI());        if (elements == null) {            elements = new ArrayList();            elements.add(qName.getLocalPart());            schemaElementNames.put(qName.getNamespaceURI(), elements);            added = true;        } else {            if (!elements.contains(qName.getLocalPart())) {                elements.add(qName.getLocalPart());                added = true;            }        }        return added;    }    /**     * Determines if the field is nullable. All non-primitives are nillable.     *     * @param type input Class     * @return true if nullable

⌨️ 快捷键说明

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