schemagrammar.java
来自「JAVA 所有包」· Java 代码 · 共 1,202 行 · 第 1/4 页
JAVA
1,202 行
public final static BuiltinSchemaGrammar SG_SchemaNS = new BuiltinSchemaGrammar(GRAMMAR_XS); public final static Schema4Annotations SG_Schema4Annotations = new Schema4Annotations(); public final static XSSimpleType fAnySimpleType = (XSSimpleType)SG_SchemaNS.getGlobalTypeDecl(SchemaSymbols.ATTVAL_ANYSIMPLETYPE); // the grammars to hold components of the schema-instance namespace public final static BuiltinSchemaGrammar SG_XSI = new BuiltinSchemaGrammar(GRAMMAR_XSI); static final XSComplexTypeDecl[] resize(XSComplexTypeDecl[] oldArray, int newSize) { XSComplexTypeDecl[] newArray = new XSComplexTypeDecl[newSize]; System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize)); return newArray; } static final XSGroupDecl[] resize(XSGroupDecl[] oldArray, int newSize) { XSGroupDecl[] newArray = new XSGroupDecl[newSize]; System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize)); return newArray; } static final XSElementDecl[] resize(XSElementDecl[] oldArray, int newSize) { XSElementDecl[] newArray = new XSElementDecl[newSize]; System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize)); return newArray; } static final SimpleLocator[] resize(SimpleLocator[] oldArray, int newSize) { SimpleLocator[] newArray = new SimpleLocator[newSize]; System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize)); return newArray; } // XSNamespaceItem methods // the max index / the max value of XSObject type private static final short MAX_COMP_IDX = XSTypeDefinition.SIMPLE_TYPE; private static final boolean[] GLOBAL_COMP = {false, // null true, // attribute true, // element true, // type false, // attribute use true, // attribute group true, // group false, // model group false, // particle false, // wildcard false, // idc true, // notation false, // annotation false, // facet false, // multi value facet true, // complex type true // simple type }; // store a certain kind of components from all namespaces private XSNamedMap[] fComponents = null; // store the documents and their locations contributing to this namespace // REVISIT: use StringList and XSObjectList for there fields. private Vector fDocuments = null; private Vector fLocations = null; public synchronized void addDocument(Object document, String location) { if (fDocuments == null) { fDocuments = new Vector(); fLocations = new Vector(); } fDocuments.addElement(document); fLocations.addElement(location); } /** * [schema namespace] * @see <a href="http://www.w3.org/TR/xmlschema-1/#nsi-schema_namespace">[schema namespace]</a> * @return The target namespace of this item. */ public String getSchemaNamespace() { return fTargetNamespace; } // annotation support synchronized DOMParser getDOMParser() { if (fDOMParser != null) return fDOMParser; // REVISIT: when schema handles XML 1.1, will need to // revisit this (and the practice of not prepending an XML decl to the annotation string IntegratedParserConfiguration config = new IntegratedParserConfiguration(fSymbolTable); // note that this should never produce errors or require // entity resolution, so just a barebones configuration with // a couple of feature set will do fine config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE, true); config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE, false); fDOMParser = new DOMParser(config); return fDOMParser; } synchronized SAXParser getSAXParser() { if (fSAXParser != null) return fSAXParser; // REVISIT: when schema handles XML 1.1, will need to // revisit this (and the practice of not prepending an XML decl to the annotation string IntegratedParserConfiguration config = new IntegratedParserConfiguration(fSymbolTable); // note that this should never produce errors or require // entity resolution, so just a barebones configuration with // a couple of feature set will do fine config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE, true); config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE, false); fSAXParser = new SAXParser(config); return fSAXParser; } /** * [schema components]: a list of top-level components, i.e. element * declarations, attribute declarations, etc. * @param objectType The type of the declaration, i.e. * <code>ELEMENT_DECLARATION</code>. Note that * <code>XSTypeDefinition.SIMPLE_TYPE</code> and * <code>XSTypeDefinition.COMPLEX_TYPE</code> can also be used as the * <code>objectType</code> to retrieve only complex types or simple * types, instead of all types. * @return A list of top-level definition of the specified type in * <code>objectType</code> or an empty <code>XSNamedMap</code> if no * such definitions exist. */ public synchronized XSNamedMap getComponents(short objectType) { if (objectType <= 0 || objectType > MAX_COMP_IDX || !GLOBAL_COMP[objectType]) { return XSNamedMapImpl.EMPTY_MAP; } if (fComponents == null) fComponents = new XSNamedMap[MAX_COMP_IDX+1]; // get the hashtable for this type of components if (fComponents[objectType] == null) { SymbolHash table = null; switch (objectType) { case XSConstants.TYPE_DEFINITION: case XSTypeDefinition.COMPLEX_TYPE: case XSTypeDefinition.SIMPLE_TYPE: table = fGlobalTypeDecls; break; case XSConstants.ATTRIBUTE_DECLARATION: table = fGlobalAttrDecls; break; case XSConstants.ELEMENT_DECLARATION: table = fGlobalElemDecls; break; case XSConstants.ATTRIBUTE_GROUP: table = fGlobalAttrGrpDecls; break; case XSConstants.MODEL_GROUP_DEFINITION: table = fGlobalGroupDecls; break; case XSConstants.NOTATION_DECLARATION: table = fGlobalNotationDecls; break; } // for complex/simple types, create a special implementation, // which take specific types out of the hash table if (objectType == XSTypeDefinition.COMPLEX_TYPE || objectType == XSTypeDefinition.SIMPLE_TYPE) { fComponents[objectType] = new XSNamedMap4Types(fTargetNamespace, table, objectType); } else { fComponents[objectType] = new XSNamedMapImpl(fTargetNamespace, table); } } return fComponents[objectType]; } /** * Convenience method. Returns a top-level simple or complex type * definition. * @param name The name of the definition. * @return An <code>XSTypeDefinition</code> or null if such definition * does not exist. */ public XSTypeDefinition getTypeDefinition(String name) { return getGlobalTypeDecl(name); } /** * Convenience method. Returns a top-level attribute declaration. * @param name The name of the declaration. * @return A top-level attribute declaration or null if such declaration * does not exist. */ public XSAttributeDeclaration getAttributeDeclaration(String name) { return getGlobalAttributeDecl(name); } /** * Convenience method. Returns a top-level element declaration. * @param name The name of the declaration. * @return A top-level element declaration or null if such declaration * does not exist. */ public XSElementDeclaration getElementDeclaration(String name) { return getGlobalElementDecl(name); } /** * Convenience method. Returns a top-level attribute group definition. * @param name The name of the definition. * @return A top-level attribute group definition or null if such * definition does not exist. */ public XSAttributeGroupDefinition getAttributeGroup(String name) { return getGlobalAttributeGroupDecl(name); } /** * Convenience method. Returns a top-level model group definition. * * @param name The name of the definition. * @return A top-level model group definition definition or null if such * definition does not exist. */ public XSModelGroupDefinition getModelGroupDefinition(String name) { return getGlobalGroupDecl(name); } /** * Convenience method. Returns a top-level notation declaration. * * @param name The name of the declaration. * @return A top-level notation declaration or null if such declaration * does not exist. */ public XSNotationDeclaration getNotationDeclaration(String name) { return getGlobalNotationDecl(name); } /** * [document location] * @see <a href="http://www.w3.org/TR/xmlschema-1/#sd-document_location">[document location]</a> * @return a list of document information item */ public StringList getDocumentLocations() { return new StringListImpl(fLocations); } /** * Return an <code>XSModel</code> that represents components in this schema * grammar. * * @return an <code>XSModel</code> representing this schema grammar */ public XSModel toXSModel() { return new XSModelImpl(new SchemaGrammar[]{this}); } public XSModel toXSModel(XSGrammar[] grammars) { if (grammars == null || grammars.length == 0) return toXSModel(); int len = grammars.length; boolean hasSelf = false; for (int i = 0; i < len; i++) { if (grammars[i] == this) { hasSelf = true; break; } } SchemaGrammar[] gs = new SchemaGrammar[hasSelf ? len : len+1]; for (int i = 0; i < len; i++) gs[i] = (SchemaGrammar)grammars[i]; if (!hasSelf) gs[len] = this; return new XSModelImpl(gs); } /** * @see com.sun.org.apache.xerces.internal.xs.XSNamespaceItem#getAnnotations() */ public XSObjectList getAnnotations() { return new XSObjectListImpl(fAnnotations, fNumAnnotations); } public void addAnnotation(XSAnnotationImpl annotation) { if(annotation == null) return; if(fAnnotations == null) { fAnnotations = new XSAnnotationImpl[2]; } else if(fNumAnnotations == fAnnotations.length) { XSAnnotationImpl[] newArray = new XSAnnotationImpl[fNumAnnotations << 1]; System.arraycopy(fAnnotations, 0, newArray, 0, fNumAnnotations); fAnnotations = newArray; } fAnnotations[fNumAnnotations++] = annotation; }} // class SchemaGrammar
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?