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

📄 utils.java

📁 Java有关XML编程需要用到axis 的源代码 把里面bin下的包导入相应的Java工程 进行使用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        for (int i = 0; tokenizer.hasMoreElements(); i++) {            String element = (String) tokenizer.nextElement();            memberTypes[i] = XMLUtils.getFullQNameFromString(element, node);        }        return memberTypes;    }    /**     * Gets the QName of the type of the node via the specified attribute     * name.     * <p/>     * If "type", the QName represented by the type attribute's value is     * returned.  If the type attribute is not set, the anonymous type     * or anyType is returned if no other type information is available.     * Note that the QName returned in these cases is affected by     * the presence of the nillable attribute.     * <p/>     * If "ref", the QName represented by the ref attribute's value is     * returned.     * <p/>     * If "base" or "element", the QName represented by the base/element     * attribute's value is returned.     *      * @param node         in the dom     * @param typeAttrName (type, base, element, ref)     * @return      */    private static QName getTypeQNameFromAttr(Node node, String typeAttrName) {        if (node == null) {            return null;        }        // Get the raw prefixed value        String prefixedName = getAttribute(node, typeAttrName);        // If "type" was specified but there is no type attribute,        // check for an anonymous type.  If no anonymous type        // then the type is anyType.        if ((prefixedName == null) && typeAttrName.equals("type")) {            if ((getAttribute(node, "ref") == null)                    && (getAttribute(node, "base") == null)                    && (getAttribute(node, "element") == null)) {                // Try getting the anonymous qname                QName anonQName = SchemaUtils.getElementAnonQName(node);                if (anonQName == null) {                    anonQName = SchemaUtils.getAttributeAnonQName(node);                }                if (anonQName != null) {                    return anonQName;                }                // Try returning anyType                String localName = node.getLocalName();                                if ((localName != null)                    && Constants.isSchemaXSD(node.getNamespaceURI())                    && (localName.equals("element") ||                         localName.equals("attribute"))) {                    return Constants.XSD_ANYTYPE;                }            }        }        // Return null if not found        if (prefixedName == null) {            return null;        }        // Change the prefixed name into a full qname        QName qName = getQNameFromPrefixedName(node, prefixedName);        // An alternate qname is returned if nillable//        if (typeAttrName.equals("type")) {//            if (JavaUtils.isTrueExplicitly(getAttribute(node, "nillable"))) {//                qName = getNillableQName(qName);//            }//        }        return qName;    }    /**     * Convert a prefixed name into a qname     *      * @param node              * @param prefixedName      * @return      */    public static QName getQNameFromPrefixedName(Node node,                                                 String prefixedName) {        String localName = prefixedName.substring(prefixedName.lastIndexOf(":")                + 1);        String namespace = null;        // Associate the namespace prefix with a namespace        if (prefixedName.length() == localName.length()) {            namespace = getScopedAttribute(                    node, "xmlns");    // Get namespace for unqualified reference        } else {            namespace = getScopedAttribute(node,                    "xmlns:"                    + prefixedName.substring(0,                            prefixedName.lastIndexOf(":")));        }        return (findQName(namespace, localName));    }    /**     * This method returns a set of all types that are derived     * from this type via an extension of a complexType     *      * @param type             * @param symbolTable      * @return      */    public static HashSet getDerivedTypes(TypeEntry type,                                          SymbolTable symbolTable) {        HashSet types = (HashSet)symbolTable.derivedTypes.get(type);        if (types != null) {            return types;        }         types = new HashSet();        symbolTable.derivedTypes.put(type, types);        if ((type != null) && (type.getNode() != null)) {            getDerivedTypes(type, types, symbolTable);        }        else if (type != null && Constants.isSchemaXSD(type.getQName().getNamespaceURI())                && (type.getQName().getLocalPart().equals("anyType")                || type.getQName().getLocalPart().equals("any"))) {            // All types are derived from anyType, except anonymous ones            final Collection typeValues = symbolTable.getTypeIndex().values();            types.addAll(typeValues);                        // Currently we are unable to mark anonymous types correctly.            // So, this filtering has to wait until a fix is made./*            for (Iterator it = typeValues.iterator(); it.hasNext();) {                SymTabEntry e = (SymTabEntry) it.next();                if (! e.getQName().getLocalPart().startsWith(SymbolTable.ANON_TOKEN))                    types.add(e);            }*/        }        return types;    }    // getNestedTypes    /**     * Method getDerivedTypes     *      * @param type             * @param types            * @param symbolTable      */    private static void getDerivedTypes(TypeEntry type, HashSet types,                                        SymbolTable symbolTable) {        // If all types are in the set, return        if (types.size() == symbolTable.getTypeEntryCount()) {            return;        }        // Search the dictionary for derived types of type        for (Iterator it = symbolTable.getTypeIndex().values().iterator();             it.hasNext();) {            Type t = (Type) it.next();            if ((t instanceof DefinedType) && (t.getNode() != null)                    && !types.contains(t)                    && (((DefinedType) t).getComplexTypeExtensionBase(symbolTable)                    == type)) {                types.add(t);                getDerivedTypes(t, types, symbolTable);            }        }    }    // getDerivedTypes    /**     * This method returns a set of all the nested types.     * Nested types are types declared within this TypeEntry (or descendents)     * plus any extended types and the extended type nested types     * The elements of the returned HashSet are Types.     *      * @param type        is the type entry to consider     * @param symbolTable is the symbolTable     * @param derivedFlag should be set if all dependendent derived types should also be     *                    returned.     * @return      */    protected static HashSet getNestedTypes(TypeEntry type,                                         SymbolTable symbolTable,                                         boolean derivedFlag) {        HashSet types = new HashSet();        getNestedTypes(type, types, symbolTable, derivedFlag);        return types;    }    // getNestedTypes    /**     * Method getNestedTypes     *      * @param type             * @param types            * @param symbolTable      * @param derivedFlag      */    private static void getNestedTypes(TypeEntry type, HashSet types,                                       SymbolTable symbolTable,                                       boolean derivedFlag) {        if (type == null) {            return;        }        // If all types are in the set, return        if (types.size() == symbolTable.getTypeEntryCount()) {            return;        }        // Process types derived from this type        if (derivedFlag) {            HashSet derivedTypes = getDerivedTypes(type, symbolTable);            Iterator it = derivedTypes.iterator();            while (it.hasNext()) {                TypeEntry derivedType = (TypeEntry) it.next();                if (!types.contains(derivedType)) {                    types.add(derivedType);                    getNestedTypes(derivedType, types, symbolTable,                            derivedFlag);                }            }        }        // Continue only if the node exists        if (type.getNode() == null) {            return;        }        Node node = type.getNode();        // Process types declared in this type        Vector v = SchemaUtils.getContainedElementDeclarations(node,                symbolTable);        if (v != null) {            for (int i = 0; i < v.size(); i++) {                ElementDecl elem = (ElementDecl) v.get(i);                if (!types.contains(elem.getType())) {                    types.add(elem.getType());                    getNestedTypes(elem.getType(), types, symbolTable,                            derivedFlag);                }            }        }        // Process attributes declared in this type        v = SchemaUtils.getContainedAttributeTypes(node, symbolTable);        if (v != null) {            for (int i = 0; i < v.size(); i++) {                ContainedAttribute attr = (ContainedAttribute) v.get(i);                TypeEntry te = attr.getType();                if (!types.contains(te)) {                    types.add(te);                    getNestedTypes(te, types, symbolTable, derivedFlag);                }                            }        }        // Process referenced types        if ((type.getRefType() != null) && !types.contains(type.getRefType())) {            types.add(type.getRefType());            getNestedTypes(type.getRefType(), types, symbolTable, derivedFlag);        }        /*         * Anonymous processing and should be automatically handled by the         *  reference processing above         * // Get the anonymous type of the element         * QName anonQName = SchemaUtils.getElementAnonQName(node);         * if (anonQName != null) {         *   TypeEntry anonType = symbolTable.getType(anonQName);         *   if (anonType != null && !types.contains(anonType)) {         *       types.add(anonType);         *   }         * }         *         * // Get the anonymous type of an attribute         * anonQName = SchemaUtils.getAttributeAnonQName(node);         * if (anonQName != null) {         *   TypeEntry anonType = symbolTable.getType(anonQName);         *   if (anonType != null && !types.contains(anonType)) {         *       types.add(anonType);         *   }         * }         */        // Process extended types        TypeEntry extendType = SchemaUtils.getComplexElementExtensionBase(node,                symbolTable);        if (extendType != null) {            if (!types.contains(extendType)) {                types.add(extendType);                getNestedTypes(extendType, types, symbolTable, derivedFlag);            }        }        /*         * Array component processing should be automatically handled by the         *  reference processing above.         * // Process array components         * QName componentQName = SchemaUtils.getArrayComponentQName(node, new IntHolder(0));         * TypeEntry componentType = symbolTable.getType(componentQName);         * if (componentType == null) {         *   componentType = symbolTable.getElement(componentQName);         * }         * if (componentType != null) {         *   if (!types.contains(componentType)) {         *       types.add(componentType);         *       getNestedTypes(componentType, types, symbolTable, derivedFlag);         *   }         * }         */    }    // getNestedTypes    /**     * Generate an XML prefixed attribute value with a corresponding xmlns     * declaration for the prefix.  If there is no namespace,     * don't prefix the name or emit the xmlns attribute.     * <p/>     * Caller should provide the enclosing quotes.     * <p/>     * Usage:  println("name=\"" + genXMLQNameString(qname, "foo") + "\""     *      * @param qname       * @param prefix      * @return      */    public static String genQNameAttributeString(QName qname, String prefix) {        if ((qname.getNamespaceURI() == null)                || qname.getNamespaceURI().equals("")) {            return qname.getLocalPart();        }        return prefix + ":" + qname.getLocalPart() + "\" xmlns:" + prefix                + "=\"" + qname.getNamespaceURI();    }        public static String genQNameAttributeStringWithLastLocalPart(QName qname, String prefix) {        String lastLocalPart = getLastLocalPart(qname.getLocalPart());        if ((qname.getNamespaceURI() == null)                || qname.getNamespaceURI().equals("")) {            return lastLocalPart;        }        return prefix + ":" + lastLocalPart + "\" xmlns:" + prefix                + "=\"" + qname.getNamespaceURI();    }    public static String getLastLocalPart(String localPart) {        int anonymousDelimitorIndex = localPart.lastIndexOf('>');        if (anonymousDelimitorIndex > -1 && anonymousDelimitorIndex < localPart.length()-1) {            localPart = localPart.substring(anonymousDelimitorIndex + 1);        }        return localPart;            }}

⌨️ 快捷键说明

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