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

📄 xsdhandler.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        return ns == null ? XMLSymbols.EMPTY_STRING : ns;    }    private String emptyString2Null(String ns) {        return ns == XMLSymbols.EMPTY_STRING ? null : ns;    }    // use Schema Element to lookup the SystemId.    private String doc2SystemId(Element ele) {        String documentURI = null;        /**         * REVISIT: Casting until DOM Level 3 interfaces are available. -- mrglavas         */        if(ele.getOwnerDocument() instanceof com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaDOM){            documentURI = ((com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaDOM) ele.getOwnerDocument()).getDocumentURI();        }        return documentURI != null ? documentURI : (String) fDoc2SystemId.get(ele);    }        // This vector stores strings which are combinations of the    // publicId and systemId of the inputSource corresponding to a    // schema document.  This combination is used so that the user's    // EntityResolver can provide a consistent way of identifying a    // schema document that is included in multiple other schemas.    private Hashtable fTraversed = new Hashtable();        // this hashtable contains a mapping from Schema Element to its systemId    // this is useful to resolve a uri relative to the referring document    private Hashtable fDoc2SystemId = new Hashtable();        // the primary XSDocumentInfo we were called to parse    private XSDocumentInfo fRoot = null;        // This hashtable's job is to act as a link between the Schema Element and its    // XSDocumentInfo object.    private Hashtable fDoc2XSDocumentMap = new Hashtable();        // map between <redefine> elements and the XSDocumentInfo    // objects that correspond to the documents being redefined.    private Hashtable fRedefine2XSDMap = new Hashtable();        // map between <redefine> elements and the namespace support    private Hashtable fRedefine2NSSupport = new Hashtable();        // these objects store a mapping between the names of redefining    // groups/attributeGroups and the groups/AttributeGroups which    // they redefine by restriction (implicitly).  It is up to the    // Group and AttributeGroup traversers to check these restrictions for    // validity.    private Hashtable fRedefinedRestrictedAttributeGroupRegistry = new Hashtable();    private Hashtable fRedefinedRestrictedGroupRegistry = new Hashtable();        // a variable storing whether the last schema document    // processed (by getSchema) was a duplicate.    private boolean fLastSchemaWasDuplicate;        // validate annotations feature    private boolean fValidateAnnotations = false;        //handle multiple import feature    private boolean fHonourAllSchemaLocations = false;    // the XMLErrorReporter    private XMLErrorReporter fErrorReporter;    private XMLEntityResolver fEntityResolver;        // the XSAttributeChecker    private XSAttributeChecker fAttributeChecker;        // the symbol table    private SymbolTable fSymbolTable;        // the GrammarResolver    private XSGrammarBucket fGrammarBucket;        // the Grammar description    private XSDDescription fSchemaGrammarDescription;        // the Grammar Pool    private XMLGrammarPool fGrammarPool;        //************ Traversers **********    XSDAttributeGroupTraverser fAttributeGroupTraverser;    XSDAttributeTraverser fAttributeTraverser;    XSDComplexTypeTraverser fComplexTypeTraverser;    XSDElementTraverser fElementTraverser;    XSDGroupTraverser fGroupTraverser;    XSDKeyrefTraverser fKeyrefTraverser;    XSDNotationTraverser fNotationTraverser;    XSDSimpleTypeTraverser fSimpleTypeTraverser;    XSDUniqueOrKeyTraverser fUniqueOrKeyTraverser;    XSDWildcardTraverser fWildCardTraverser;        SchemaDOMParser fSchemaParser;    SchemaContentHandler fXSContentHandler;    XML11Configuration fAnnotationValidator;    XSAnnotationGrammarPool fGrammarBucketAdapter;        // these data members are needed for the deferred traversal    // of local elements.        // the initial size of the array to store deferred local elements    private static final int INIT_STACK_SIZE = 30;    // the incremental size of the array to store deferred local elements    private static final int INC_STACK_SIZE  = 10;    // current position of the array (# of deferred local elements)    private int fLocalElemStackPos = 0;        private XSParticleDecl[] fParticle = new XSParticleDecl[INIT_STACK_SIZE];    private Element[] fLocalElementDecl = new Element[INIT_STACK_SIZE];    private XSDocumentInfo[] fLocalElementDecl_schema = new XSDocumentInfo[INIT_STACK_SIZE]; //JACK    private int[] fAllContext = new int[INIT_STACK_SIZE];    private XSObject[] fParent = new XSObject[INIT_STACK_SIZE];    private String [][] fLocalElemNamespaceContext = new String [INIT_STACK_SIZE][1];        // these data members are needed for the deferred traversal    // of keyrefs.        // the initial size of the array to store deferred keyrefs    private static final int INIT_KEYREF_STACK = 2;    // the incremental size of the array to store deferred keyrefs    private static final int INC_KEYREF_STACK_AMOUNT = 2;    // current position of the array (# of deferred keyrefs)    private int fKeyrefStackPos = 0;        private Element [] fKeyrefs = new Element[INIT_KEYREF_STACK];    private XSDocumentInfo [] fKeyrefsMapXSDocumentInfo = new XSDocumentInfo[INIT_KEYREF_STACK];    private XSElementDecl [] fKeyrefElems = new XSElementDecl [INIT_KEYREF_STACK];    private String [][] fKeyrefNamespaceContext = new String[INIT_KEYREF_STACK][1];        // Constructors    public XSDHandler(){        fHiddenNodes = new Hashtable();               fSchemaParser = new SchemaDOMParser(new SchemaParsingConfig());    }        // it should be possible to use the same XSDHandler to parse    // multiple schema documents; this will allow one to be    // constructed.    public XSDHandler (XSGrammarBucket gBucket) {        this();        fGrammarBucket = gBucket;                // Note: don't use SchemaConfiguration internally        //       we will get stack overflaw because        //       XMLSchemaValidator will be instantiating XSDHandler...        fSchemaGrammarDescription = new XSDDescription();    } // end constructor           /**     * This method initiates the parse of a schema.  It will likely be     * called from the Validator and it will make the     * resulting grammar available; it returns a reference to this object just     * in case.  A reset(XMLComponentManager) must be called before this methods is called.     * @param is     * @param desc     * @param locationPairs     * @return     * @throws IOException     */    public SchemaGrammar parseSchema(XMLInputSource is, XSDDescription desc,            Hashtable locationPairs)    throws IOException {        fLocationPairs = locationPairs;        fSchemaParser.resetNodePool();           SchemaGrammar grammar = null;        String schemaNamespace  = null;        short referType = desc.getContextType();        // if loading using JAXP schemaSource property, or using grammar caching loadGrammar        // the desc.targetNamespace is always null.        // Therefore we should not attempt to find out if        // the schema is already in the bucket, since in the case we have        // no namespace schema in the bucket, findGrammar will always return the        // no namespace schema.        if (referType != XSDDescription.CONTEXT_PREPARSE){            // first try to find it in the bucket/pool, return if one is found            if(fHonourAllSchemaLocations && referType == XSDDescription.CONTEXT_IMPORT && isExistingGrammar(desc)) {                grammar = fGrammarBucket.getGrammar(desc.getTargetNamespace());            }            else {                grammar = findGrammar(desc);            }            if (grammar != null)                return grammar;            schemaNamespace = desc.getTargetNamespace();            // handle empty string URI as null            if (schemaNamespace != null) {                schemaNamespace = fSymbolTable.addSymbol(schemaNamespace);            }        }                // before parsing a schema, need to clear registries associated with        // parsing schemas        prepareForParse();                       Document schemaRootDoc = null;        Element schemaRoot = null;        // first phase:  construct trees.        if (is instanceof DOMInputSource) {            //clean up the field fHiddenNodes, used for DOMInputSource            fHiddenNodes.clear();            Node domNode = ((DOMInputSource)is).getNode();                        if (domNode instanceof Document) {                schemaRootDoc = (Document)domNode;                schemaRoot = DOMUtil.getRoot(schemaRootDoc);            }            else if (domNode instanceof Element) {                schemaRoot = (Element)domNode;            }            else {                return null;            }        } // DOMInputSource        else if (is instanceof SAXInputSource) {            XMLReader parser = ((SAXInputSource)is).getXMLReader();            InputSource inputSource = ((SAXInputSource)is).getInputSource();             boolean namespacePrefixes = false;            if (parser != null) {                try {                    namespacePrefixes = parser.getFeature(NAMESPACE_PREFIXES);                }                catch (SAXException se) {}            }            else {                try {                    parser = XMLReaderFactory.createXMLReader();                }                // If something went wrong with the factory                // just use our own SAX parser.                catch (SAXException se) {                    parser = new SAXParser();                }                try {                    parser.setFeature(NAMESPACE_PREFIXES, true);                    namespacePrefixes = true;                }                catch (SAXException se) {}            }            // If XML names and Namespace URIs are already internalized we            // can avoid running them through the SymbolTable.            boolean stringsInternalized = false;            try {                stringsInternalized = parser.getFeature(STRING_INTERNING);            }            catch (SAXException exc) {                // The feature isn't recognized or getting it is not supported.                // In either case, assume that strings are not internalized.            }            if (fXSContentHandler == null) {                fXSContentHandler = new SchemaContentHandler();            }            fXSContentHandler.reset(fSchemaParser, fSymbolTable,                     namespacePrefixes, stringsInternalized);            parser.setContentHandler(fXSContentHandler);            parser.setErrorHandler(fErrorReporter.getSAXErrorHandler());        	try {            	parser.parse(inputSource);	        	}        	catch (SAXException se) {        		return null;        	}        	schemaRootDoc = fXSContentHandler.getDocument();            if (schemaRootDoc == null) {

⌨️ 快捷键说明

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