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

📄 xsdhandler.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        // set its Document node to hidden so that we don't try to traverse        // it again; then we look to its Dependency map entry.  We keep a        // stack of schemas that we haven't yet finished processing; this        // is a depth-first traversal.                    Stack schemasToProcess = new Stack();        schemasToProcess.push(fRoot);               while (!schemasToProcess.empty()) {                        XSDocumentInfo currSchemaDoc =                (XSDocumentInfo)schemasToProcess.pop();            Element currDoc = currSchemaDoc.fSchemaElement;             if(DOMUtil.isHidden(currDoc, fHiddenNodes)){                // must have processed this already!                continue;            }            Element currRoot = currDoc;            // process this schema's global decls            boolean dependenciesCanOccur = true;            for (Element globalComp =                DOMUtil.getFirstChildElement(currRoot);            globalComp != null;            globalComp = DOMUtil.getNextSiblingElement(globalComp)) {                // this loop makes sure the <schema> element ordering is                // also valid.                if (DOMUtil.getLocalName(globalComp).equals(SchemaSymbols.ELT_ANNOTATION)) {                    //skip it; traverse it later                    continue;                }                else if (DOMUtil.getLocalName(globalComp).equals(SchemaSymbols.ELT_INCLUDE) ||                        DOMUtil.getLocalName(globalComp).equals(SchemaSymbols.ELT_IMPORT)) {                    if (!dependenciesCanOccur) {                        reportSchemaError("s4s-elt-invalid-content.3", new Object [] {DOMUtil.getLocalName(globalComp)}, globalComp);                    }                    DOMUtil.setHidden(globalComp, fHiddenNodes);                }                else if (DOMUtil.getLocalName(globalComp).equals(SchemaSymbols.ELT_REDEFINE)) {                    if (!dependenciesCanOccur) {                        reportSchemaError("s4s-elt-invalid-content.3", new Object [] {DOMUtil.getLocalName(globalComp)}, globalComp);                    }                    for (Element redefineComp = DOMUtil.getFirstChildElement(globalComp);                    redefineComp != null;                    redefineComp = DOMUtil.getNextSiblingElement(redefineComp)) {                        String lName = DOMUtil.getAttrValue(redefineComp, SchemaSymbols.ATT_NAME);                        if (lName.length() == 0) // an error we'll catch later                            continue;                        String qName = currSchemaDoc.fTargetNamespace == null ?                                ","+lName:                                    currSchemaDoc.fTargetNamespace +","+lName;                        String componentType = DOMUtil.getLocalName(redefineComp);                        if (componentType.equals(SchemaSymbols.ELT_ATTRIBUTEGROUP)) {                            checkForDuplicateNames(qName, fUnparsedAttributeGroupRegistry, fUnparsedAttributeGroupRegistrySub, redefineComp, currSchemaDoc);                            // the check will have changed our name;                            String targetLName = DOMUtil.getAttrValue(redefineComp, SchemaSymbols.ATT_NAME)+REDEF_IDENTIFIER;                            // and all we need to do is error-check+rename our kkids:                            renameRedefiningComponents(currSchemaDoc, redefineComp, SchemaSymbols.ELT_ATTRIBUTEGROUP,                                    lName, targetLName);                        }                        else if ((componentType.equals(SchemaSymbols.ELT_COMPLEXTYPE)) ||                                (componentType.equals(SchemaSymbols.ELT_SIMPLETYPE))) {                            checkForDuplicateNames(qName, fUnparsedTypeRegistry, fUnparsedTypeRegistrySub, redefineComp, currSchemaDoc);                            // the check will have changed our name;                            String targetLName = DOMUtil.getAttrValue(redefineComp, SchemaSymbols.ATT_NAME) + REDEF_IDENTIFIER;                            // and all we need to do is error-check+rename our kkids:                            if (componentType.equals(SchemaSymbols.ELT_COMPLEXTYPE)) {                                renameRedefiningComponents(currSchemaDoc, redefineComp, SchemaSymbols.ELT_COMPLEXTYPE,                                        lName, targetLName);                            }                            else { // must be simpleType                                renameRedefiningComponents(currSchemaDoc, redefineComp, SchemaSymbols.ELT_SIMPLETYPE,                                        lName, targetLName);                            }                        }                        else if (componentType.equals(SchemaSymbols.ELT_GROUP)) {                            checkForDuplicateNames(qName, fUnparsedGroupRegistry, fUnparsedGroupRegistrySub, redefineComp, currSchemaDoc);                            // the check will have changed our name;                            String targetLName = DOMUtil.getAttrValue(redefineComp, SchemaSymbols.ATT_NAME)+REDEF_IDENTIFIER;                            // and all we need to do is error-check+rename our kids:                            renameRedefiningComponents(currSchemaDoc, redefineComp, SchemaSymbols.ELT_GROUP,                                    lName, targetLName);                        }                    } // end march through <redefine> children                    // and now set as traversed                    //DOMUtil.setHidden(globalComp);                }                else {                    dependenciesCanOccur = false;                    String lName = DOMUtil.getAttrValue(globalComp, SchemaSymbols.ATT_NAME);                    if (lName.length() == 0) // an error we'll catch later                        continue;                    String qName = currSchemaDoc.fTargetNamespace == null?                            ","+lName:                                currSchemaDoc.fTargetNamespace +","+lName;                    String componentType = DOMUtil.getLocalName(globalComp);                    if (componentType.equals(SchemaSymbols.ELT_ATTRIBUTE)) {                        checkForDuplicateNames(qName, fUnparsedAttributeRegistry, fUnparsedAttributeRegistrySub, globalComp, currSchemaDoc);                    }                    else if (componentType.equals(SchemaSymbols.ELT_ATTRIBUTEGROUP)) {                        checkForDuplicateNames(qName, fUnparsedAttributeGroupRegistry, fUnparsedAttributeGroupRegistrySub, globalComp, currSchemaDoc);                    }                    else if ((componentType.equals(SchemaSymbols.ELT_COMPLEXTYPE)) ||                            (componentType.equals(SchemaSymbols.ELT_SIMPLETYPE))) {                        checkForDuplicateNames(qName, fUnparsedTypeRegistry, fUnparsedTypeRegistrySub, globalComp, currSchemaDoc);                    }                    else if (componentType.equals(SchemaSymbols.ELT_ELEMENT)) {                        checkForDuplicateNames(qName, fUnparsedElementRegistry, fUnparsedElementRegistrySub, globalComp, currSchemaDoc);                    }                    else if (componentType.equals(SchemaSymbols.ELT_GROUP)) {                        checkForDuplicateNames(qName, fUnparsedGroupRegistry, fUnparsedGroupRegistrySub, globalComp, currSchemaDoc);                    }                    else if (componentType.equals(SchemaSymbols.ELT_NOTATION)) {                        checkForDuplicateNames(qName, fUnparsedNotationRegistry, fUnparsedNotationRegistrySub, globalComp, currSchemaDoc);                    }                }            } // end for                        // now we're done with this one!           	DOMUtil.setHidden(currDoc, fHiddenNodes);            // now add the schemas this guy depends on            Vector currSchemaDepends = (Vector)fDependencyMap.get(currSchemaDoc);            for (int i = 0; i < currSchemaDepends.size(); i++) {                schemasToProcess.push(currSchemaDepends.elementAt(i));            }        } // while    } // end buildGlobalNameRegistries        // Beginning at the first schema processing was requested for    // (fRoot), this method    // examines each child (global schema information item) of each    // schema document (and of each <redefine> element)    // corresponding to an XSDocumentInfo object.  If the    // readOnly field on that node has not been set, it calls an    // appropriate traverser to traverse it.  Once all global decls in    // an XSDocumentInfo object have been traversed, it marks that object    // as traversed (or hidden) in order to avoid infinite loops.  It completes    // when it has visited all XSDocumentInfo objects in the    // DependencyMap and marked them as traversed.    protected void traverseSchemas(ArrayList annotationInfo) {        // the process here is very similar to that in        // buildGlobalRegistries, except we can't set our schemas as        // hidden for a second time; so make them all visible again        // first!        setSchemasVisible(fRoot);        Stack schemasToProcess = new Stack();        schemasToProcess.push(fRoot);        while (!schemasToProcess.empty()) {            XSDocumentInfo currSchemaDoc =                (XSDocumentInfo)schemasToProcess.pop();            Element currDoc = currSchemaDoc.fSchemaElement;                   SchemaGrammar currSG = fGrammarBucket.getGrammar(currSchemaDoc.fTargetNamespace);            if(DOMUtil.isHidden(currDoc, fHiddenNodes)) {                // must have processed this already!                continue;            }            Element currRoot = currDoc;            boolean sawAnnotation = false;            // traverse this schema's global decls            for (Element globalComp =                DOMUtil.getFirstVisibleChildElement(currRoot, fHiddenNodes);            globalComp != null;            globalComp = DOMUtil.getNextVisibleSiblingElement(globalComp, fHiddenNodes)) {                DOMUtil.setHidden(globalComp, fHiddenNodes);                 String componentType = DOMUtil.getLocalName(globalComp);                // includes and imports will not show up here!                if (DOMUtil.getLocalName(globalComp).equals(SchemaSymbols.ELT_REDEFINE)) {                    // use the namespace decls for the redefine, instead of for the parent <schema>                    currSchemaDoc.backupNSSupport((SchemaNamespaceSupport)fRedefine2NSSupport.get(globalComp));                    for (Element redefinedComp = DOMUtil.getFirstVisibleChildElement(globalComp, fHiddenNodes);                    redefinedComp != null;                    redefinedComp = DOMUtil.getNextVisibleSiblingElement(redefinedComp, fHiddenNodes)) {                        String redefinedComponentType = DOMUtil.getLocalName(redefinedComp);                        DOMUtil.setHidden(redefinedComp, fHiddenNodes);                        if (redefinedComponentType.equals(SchemaSymbols.ELT_ATTRIBUTEGROUP)) {                            fAttributeGroupTraverser.traverseGlobal(redefinedComp, currSchemaDoc, currSG);                        }                        else if (redefinedComponentType.equals(SchemaSymbols.ELT_COMPLEXTYPE)) {                            fComplexTypeTraverser.traverseGlobal(redefinedComp, currSchemaDoc, currSG);                        }                        else if (redefinedComponentType.equals(SchemaSymbols.ELT_GROUP)) {                            fGroupTraverser.traverseGlobal(redefinedComp, currSchemaDoc, currSG);                        }                        else if (redefinedComponentType.equals(SchemaSymbols.ELT_SIMPLETYPE)) {                            fSimpleTypeTraverser.traverseGlobal(redefinedComp, currSchemaDoc, currSG);                        }                        // annotations will have been processed already; this is now                        // unnecessary                        //else if (redefinedComponentType.equals(SchemaSymbols.ELT_ANNOTATION)) {                        //    fElementTraverser.traverseAnnotationDecl(redefinedComp, null, true, currSchemaDoc);                        //}                        else {                            reportSchemaError("s4s-elt-must-match.1", new Object [] {DOMUtil.getLocalName(globalComp), "(annotation | (simpleType | complexType | group | attributeGroup))*", redefinedComponentType}, redefinedComp);                        }                    } // end march through <redefine> children                    currSchemaDoc.restoreNSSupport();                }                else if (componentType.equals(SchemaSymbols.ELT_ATTRIBUTE)) {                    fAttributeTraverser.traverseGlobal(globalComp, currSchemaDoc, currSG);                }                else if (componentType.equals(SchemaSymbols.ELT_ATTRIBUTEGROUP)) {                    fAttributeGroupTraverser.traverseGlobal(globalComp, currSchemaDoc, currSG);                }                else if (componentType.equals(SchemaSymbols.ELT_COMPLEXTYPE)) {                    fComplexTypeTraverser.traverseGlobal(globalComp, currSchemaDoc, currSG);                }                else if (componentType.equals(SchemaSymbols.ELT_ELEMENT)) {                    fElementTraverser.traverseGlobal(globalComp, currSchemaDoc, currSG);                }                else if (componentType.equals(SchemaSymbols.ELT_GROUP)) {                    fGroupTraverser.traverseGlobal(globalComp, currSchemaDoc, currSG);                }                else if (componentType.equals(SchemaSymbols.ELT_NOTATION)) {                    fNotationTraverser.traverse(globalComp, currSchemaDoc, currSG);                }                else if (componentType.equals(SchemaSymbols.ELT_SIMPLETYPE)) {                    fSimpleTypeTraverser.traverseGlobal(globalComp, currSchemaDoc, currSG);                }                else if (componentType.equals(SchemaSymbols.ELT_ANNOTATION)) {                    currSG.addAnnotation(fElementTraverser.traverseAnnotationDecl(globalComp, currSchemaDoc.getSchemaAttrs(), true, currSchemaDoc));                    sawAnnotation = true;                }                else {                    reportSchemaError("s4s-elt-invalid-content.1", new Object [] {SchemaSymbols.ELT_SCHEMA, DOMUtil.getLocalName(globalComp)}, globalComp);                }            } // end for                        if (!sawAnnotation) {                String text = DOMUtil.getSyntheticAnnotation(currRoot);                if (text != null) {                    currSG.addAnnotation(fElementTraverser.traverseSyntheticAnnotation(currRoot, text, currSchemaDoc.getSchemaAttrs(), true, currSchemaDoc));                }            }                        /** Collect annotation information for validation. **/            if (annotationInfo != null) {                XSAnnotationInfo info = currSchemaDoc.getAnnotations();                /** Only add annotations to the list if there were any in this document. **/                if (info != null) {                    annotationInfo.add(doc2SystemId(currDoc));                    annotationInfo.add(info);                }            }            // now we're done with this one!            currSchemaDoc.returnSchemaAttrs();            DOMUtil.setHidden(currDoc, fHiddenNodes);            // now add the schemas this guy depends on            Vector currSchemaDepends = (Vector)fDependencyMap.get(currSchemaDoc);            for (int i = 0; i < currSchemaDepends.size(); i++) {                schemasToProcess.push(currSchemaDepends.elementAt(i));            }        } // while    } // end traverseSchemas        // store whether we have reported an error about that no grammar    // is found for the given namespace uri    private Vector fReportedTNS = null;    // check whether we need to report an err

⌨️ 快捷键说明

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