xsdhandler.java

来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 1,320 行 · 第 1/5 页

JAVA
1,320
字号
                        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));                }                else {                    reportSchemaError("s4s-elt-invalid-content.1", new Object [] {SchemaSymbols.ELT_SCHEMA, DOMUtil.getLocalName(globalComp)}, globalComp);                }            } // end for            // now we're done with this one!            currSchemaDoc.returnSchemaAttrs();            DOMUtil.setHidden(currDoc);            // 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 error against the given uri.    // if we have reported an error, then we don't need to report again;    // otherwise we reported the error, and remember this fact.    private final boolean needReportTNSError(String uri) {        if (fReportedTNS == null)            fReportedTNS = new Vector();        else if (fReportedTNS.contains(uri))            return false;        fReportedTNS.addElement(uri);        return true;    }        private static final String[] COMP_TYPE = {        null,               // index 0        "attribute declaration",        "attribute group",        "element declaration",        "group",        "identity constraint",        "notation",        "type definition",    };    private static final String[] CIRCULAR_CODES = {        "Internal-Error",        "Internal-Error",        "src-attribute_group.3",        "e-props-correct.6",        "mg-props-correct.2",        "Internal-Error",        "Internal-Error",        "st-props-correct.2",       //or ct-props-correct.3    };    // since it is forbidden for traversers to talk to each other    // directly (except wen a traverser encounters a local declaration),    // this provides a generic means for a traverser to call    // for the traversal of some declaration.  An XSDocumentInfo is    // required because the XSDocumentInfo that the traverser is traversing    // may bear no relation to the one the handler is operating on.    // This method will:    // 1.  See if a global definition matching declToTraverse exists;    // 2. if so, determine if there is a path from currSchema to the    // schema document where declToTraverse lives (i.e., do a lookup    // in DependencyMap);    // 3. depending on declType (which will be relevant to step 1 as    // well), call the appropriate traverser with the appropriate    // XSDocumentInfo object.    // This method returns whatever the traverser it called returned;    // this will be an Object of some kind    // that lives in the Grammar.    protected Object getGlobalDecl(XSDocumentInfo currSchema,                                   int declType,                                   QName declToTraverse,                                   Element elmNode) {        if (DEBUG_NODE_POOL) {            System.out.println("TRAVERSE_GL: "+declToTraverse.toString());        }        // from the schema spec, all built-in types are present in all schemas,        // so if the requested component is a type, and could be found in the        // default schema grammar, we should return that type.        // otherwise (since we would support user-defined schema grammar) we'll        // use the normal way to get the decl        if (declToTraverse.uri != null &&            declToTraverse.uri == SchemaSymbols.URI_SCHEMAFORSCHEMA) {            if (declType == TYPEDECL_TYPE) {                Object retObj = SchemaGrammar.SG_SchemaNS.getGlobalTypeDecl(declToTraverse.localpart);                if (retObj != null)                    return retObj;            }        }        // now check whether this document can access the requsted namespace        if (!currSchema.isAllowedNS(declToTraverse.uri)) {            // cannot get to this schema from the one containing the requesting decl            if (currSchema.needReportTNSError(declToTraverse.uri)) {                String code = declToTraverse.uri == null ? "src-resolve.4.1" : "src-resolve.4.2";                reportSchemaError(code, new Object[]{fDoc2SystemId.get(currSchema.fSchemaDoc), declToTraverse.uri, declToTraverse.rawname}, elmNode);            }            return null;        }        // check whether there is grammar for the requested namespace        SchemaGrammar sGrammar = fGrammarBucket.getGrammar(declToTraverse.uri);        if (sGrammar == null) {            if (needReportTNSError(declToTraverse.uri))                reportSchemaError("src-resolve", new Object[]{declToTraverse.rawname, COMP_TYPE[declType]}, elmNode);            return null;        }        // if there is such grammar, check whether the requested component is in the grammar        Object retObj = null;        switch (declType) {        case ATTRIBUTE_TYPE :            retObj = sGrammar.getGlobalAttributeDecl(declToTraverse.localpart);            break;        case ATTRIBUTEGROUP_TYPE :            retObj = sGrammar.getGlobalAttributeGroupDecl(declToTraverse.localpart);            break;        case ELEMENT_TYPE :            retObj = sGrammar.getGlobalElementDecl(declToTraverse.localpart);            break;        case GROUP_TYPE :            retObj = sGrammar.getGlobalGroupDecl(declToTraverse.localpart);            break;        case IDENTITYCONSTRAINT_TYPE :            retObj = sGrammar.getIDConstraintDecl(declToTraverse.localpart);            break;        case NOTATION_TYPE :            retObj = sGrammar.getGlobalNotationDecl(declToTraverse.localpart);            break;        case TYPEDECL_TYPE :            retObj = sGrammar.getGlobalTypeDecl(declToTraverse.localpart);            break;        }        // if the component is parsed, return it        if (retObj != null)            return retObj;        XSDocumentInfo schemaWithDecl = null;        Element decl = null;        // the component is not parsed, try to find a DOM element for it        String declKey = declToTraverse.uri == null? ","+declToTraverse.localpart:                         declToTraverse.uri+","+declToTraverse.localpart;        switch (declType) {        case ATTRIBUTE_TYPE :            decl = (Element)fUnparsedAttributeRegistry.get(declKey);            break;        case ATTRIBUTEGROUP_TYPE :            decl = (Element)fUnparsedAttributeGroupRegistry.get(declKey);            break;        case ELEMENT_TYPE :            decl = (Element)fUnparsedElementRegistry.get(declKey);            break;        case GROUP_TYPE :            decl = (Element)fUnparsedGroupRegistry.get(declKey);            break;        case IDENTITYCONSTRAINT_TYPE :            decl = (Element)fUnparsedIdentityConstraintRegistry.get(declKey);            break;        case NOTATION_TYPE :            decl = (Element)fUnparsedNotationRegistry.get(declKey);            break;        case TYPEDECL_TYPE :            decl = (Element)fUnparsedTypeRegistry.get(declKey);            break;        default:            reportSchemaError("Internal-Error", new Object [] {"XSDHandler asked to locate component of type " + declType + "; it does not recognize this type!"}, elmNode);        }                // no DOM element found, so the component can't be located        if (decl == null) {            reportSchemaError("src-resolve", new Object[]{declToTraverse.rawname, COMP_TYPE[declType]}, elmNode);            return null;        }        // get the schema doc containing the component to be parsed        // it should always return non-null value, but since null-checking        // comes for free, let's be safe and check again        schemaWithDecl = findXSDocumentForDecl(currSchema, decl);        if (schemaWithDecl == null) {            // cannot get to this schema from the one containing the requesting decl            String code = declToTraverse.uri == null ? "src-resolve.4.1" : "src-resolve.4.2";            reportSchemaError(code, new Object[]{fDoc2SystemId.get(currSchema.fSchemaDoc), declToTraverse.uri, declToTraverse.rawname}, elmNode);            return null;        }        // a component is hidden, meaning either it's traversed, or being traversed.        // but we didn't find it in the grammar, so it's the latter case, and        // a circular reference. error!        if (DOMUtil.isHidden(decl)) {            String code = CIRCULAR_CODES[declType];            if (declType == TYPEDECL_TYPE) {                if (SchemaSymbols.ELT_COMPLEXTYPE.equals(DOMUtil.getLocalName(decl)))                    code = "ct-props-correct.3";            }            // decl must not be null if we're here...            reportSchemaError(code, new Object [] {declToTraverse.prefix+":"+declToTraverse.localpart}, elmNode);            return null;        }        // hide the element node before traversing it        DOMUtil.setHidden(decl);        SchemaNamespaceSupport nsSupport = null;        // if the parent is <redefine> use the namespace delcs for it.        Element parent = DOMUtil.getParent(decl);        if (DOMUtil.getLocalName(parent).equals(SchemaSymbols.ELT_REDEFINE))            nsSupport = (SchemaNamespaceSupport)fRedefine2NSSupport.get(parent);        // back up the current SchemaNamespaceSupport, because we need to provide        // a fresh one to the traverseGlobal methods.        schemaWithDecl.backupNSSupport(nsSupport);        // traverse the referenced global component        switch (declType) {        case ATTRIBUTE_TYPE :            retObj = fAttributeTraverser.traverseGlobal(decl, schemaWithDecl, sGrammar);            break;        case ATTRIBUTEGROUP_TYPE :            retObj = fAttributeGroupTraverser.traverseGlobal(decl, schemaWithDecl, sGrammar);            break;        case ELEMENT_TYPE :            retObj = fElementTraverser.traverseGlobal(decl, schemaWithDecl, sGrammar);            break;        case GROUP

⌨️ 快捷键说明

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