0001: /*
0002: * Licensed to the Apache Software Foundation (ASF) under one or more
0003: * contributor license agreements. See the NOTICE file distributed with
0004: * this work for additional information regarding copyright ownership.
0005: * The ASF licenses this file to You under the Apache License, Version 2.0
0006: * (the "License"); you may not use this file except in compliance with
0007: * the License. You may obtain a copy of the License at
0008: *
0009: * http://www.apache.org/licenses/LICENSE-2.0
0010: *
0011: * Unless required by applicable law or agreed to in writing, software
0012: * distributed under the License is distributed on an "AS IS" BASIS,
0013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014: * See the License for the specific language governing permissions and
0015: * limitations under the License.
0016: */
0017:
0018: package org.apache.xerces.impl.xs;
0019:
0020: import java.lang.ref.SoftReference;
0021: import java.util.Vector;
0022:
0023: import org.apache.xerces.impl.Constants;
0024: import org.apache.xerces.impl.dv.SchemaDVFactory;
0025: import org.apache.xerces.impl.dv.ValidatedInfo;
0026: import org.apache.xerces.impl.dv.XSSimpleType;
0027: import org.apache.xerces.impl.xs.identity.IdentityConstraint;
0028: import org.apache.xerces.impl.xs.util.SimpleLocator;
0029: import org.apache.xerces.impl.xs.util.StringListImpl;
0030: import org.apache.xerces.impl.xs.util.XSNamedMap4Types;
0031: import org.apache.xerces.impl.xs.util.XSNamedMapImpl;
0032: import org.apache.xerces.impl.xs.util.XSObjectListImpl;
0033: import org.apache.xerces.parsers.DOMParser;
0034: import org.apache.xerces.parsers.SAXParser;
0035: import org.apache.xerces.parsers.XML11Configuration;
0036: import org.apache.xerces.util.SymbolHash;
0037: import org.apache.xerces.util.SymbolTable;
0038: import org.apache.xerces.xni.NamespaceContext;
0039: import org.apache.xerces.xni.grammars.XMLGrammarDescription;
0040: import org.apache.xerces.xni.grammars.XSGrammar;
0041: import org.apache.xerces.xs.StringList;
0042: import org.apache.xerces.xs.XSAnnotation;
0043: import org.apache.xerces.xs.XSAttributeDeclaration;
0044: import org.apache.xerces.xs.XSAttributeGroupDefinition;
0045: import org.apache.xerces.xs.XSConstants;
0046: import org.apache.xerces.xs.XSElementDeclaration;
0047: import org.apache.xerces.xs.XSModel;
0048: import org.apache.xerces.xs.XSModelGroupDefinition;
0049: import org.apache.xerces.xs.XSNamedMap;
0050: import org.apache.xerces.xs.XSNamespaceItem;
0051: import org.apache.xerces.xs.XSNotationDeclaration;
0052: import org.apache.xerces.xs.XSObjectList;
0053: import org.apache.xerces.xs.XSParticle;
0054: import org.apache.xerces.xs.XSTypeDefinition;
0055: import org.apache.xerces.xs.XSWildcard;
0056: import org.xml.sax.SAXException;
0057:
0058: /**
0059: * This class is to hold all schema component declaration that are declared
0060: * within one namespace.
0061: *
0062: * The Grammar class this class extends contains what little
0063: * commonality there is between XML Schema and DTD grammars. It's
0064: * useful to distinguish grammar objects from other kinds of object
0065: * when they exist in pools or caches.
0066: *
0067: * @xerces.internal
0068: *
0069: * @author Sandy Gao, IBM
0070: * @author Elena Litani, IBM
0071: *
0072: * @version $Id: SchemaGrammar.java 446734 2006-09-15 20:51:23Z mrglavas $
0073: */
0074:
0075: public class SchemaGrammar implements XSGrammar, XSNamespaceItem {
0076:
0077: // the target namespace of grammar
0078: String fTargetNamespace;
0079:
0080: // global decls: map from decl name to decl object
0081: SymbolHash fGlobalAttrDecls;
0082: SymbolHash fGlobalAttrGrpDecls;
0083: SymbolHash fGlobalElemDecls;
0084: SymbolHash fGlobalGroupDecls;
0085: SymbolHash fGlobalNotationDecls;
0086: SymbolHash fGlobalIDConstraintDecls;
0087: SymbolHash fGlobalTypeDecls;
0088:
0089: // the XMLGrammarDescription member
0090: XSDDescription fGrammarDescription = null;
0091:
0092: // annotations associated with the "root" schema of this targetNamespace
0093: XSAnnotationImpl[] fAnnotations = null;
0094:
0095: // number of annotations declared
0096: int fNumAnnotations;
0097:
0098: // symbol table for constructing parsers (annotation support)
0099: private SymbolTable fSymbolTable = null;
0100: // parsers for annotation support
0101: private SoftReference fSAXParser = null;
0102: private SoftReference fDOMParser = null;
0103:
0104: //
0105: // Constructors
0106: //
0107:
0108: // needed to make BuiltinSchemaGrammar work.
0109: protected SchemaGrammar() {
0110: }
0111:
0112: /**
0113: * Default constructor.
0114: *
0115: * @param targetNamespace
0116: * @param grammarDesc the XMLGrammarDescription corresponding to this objec
0117: * at the least a systemId should always be known.
0118: * @param symbolTable needed for annotation support
0119: */
0120: public SchemaGrammar(String targetNamespace,
0121: XSDDescription grammarDesc, SymbolTable symbolTable) {
0122: fTargetNamespace = targetNamespace;
0123: fGrammarDescription = grammarDesc;
0124: fSymbolTable = symbolTable;
0125:
0126: // REVISIT: do we know the numbers of the following global decls
0127: // when creating this grammar? If so, we can pass the numbers in,
0128: // and use that number to initialize the following hashtables.
0129: fGlobalAttrDecls = new SymbolHash();
0130: fGlobalAttrGrpDecls = new SymbolHash();
0131: fGlobalElemDecls = new SymbolHash();
0132: fGlobalGroupDecls = new SymbolHash();
0133: fGlobalNotationDecls = new SymbolHash();
0134: fGlobalIDConstraintDecls = new SymbolHash();
0135:
0136: // if we are parsing S4S, put built-in types in first
0137: // they might get overwritten by the types from S4S, but that's
0138: // considered what the application wants to do.
0139: if (fTargetNamespace == SchemaSymbols.URI_SCHEMAFORSCHEMA)
0140: fGlobalTypeDecls = SG_SchemaNS.fGlobalTypeDecls.makeClone();
0141: else
0142: fGlobalTypeDecls = new SymbolHash();
0143: } // <init>(String, XSDDescription)
0144:
0145: // number of built-in XSTypes we need to create for base and full
0146: // datatype set
0147: private static final int BASICSET_COUNT = 29;
0148: private static final int FULLSET_COUNT = 46;
0149:
0150: private static final int GRAMMAR_XS = 1;
0151: private static final int GRAMMAR_XSI = 2;
0152:
0153: // this class makes sure the static, built-in schema grammars
0154: // are immutable.
0155: public static class BuiltinSchemaGrammar extends SchemaGrammar {
0156: /**
0157: * Special constructor to create the grammars for the schema namespaces
0158: *
0159: * @param grammar
0160: */
0161: public BuiltinSchemaGrammar(int grammar) {
0162: SchemaDVFactory schemaFactory = SchemaDVFactory
0163: .getInstance();
0164:
0165: if (grammar == GRAMMAR_XS) {
0166: // target namespace
0167: fTargetNamespace = SchemaSymbols.URI_SCHEMAFORSCHEMA;
0168:
0169: // grammar description
0170: fGrammarDescription = new XSDDescription();
0171: fGrammarDescription.fContextType = XSDDescription.CONTEXT_PREPARSE;
0172: fGrammarDescription
0173: .setNamespace(SchemaSymbols.URI_SCHEMAFORSCHEMA);
0174:
0175: // no global decls other than types
0176: fGlobalAttrDecls = new SymbolHash(1);
0177: fGlobalAttrGrpDecls = new SymbolHash(1);
0178: fGlobalElemDecls = new SymbolHash(1);
0179: fGlobalGroupDecls = new SymbolHash(1);
0180: fGlobalNotationDecls = new SymbolHash(1);
0181: fGlobalIDConstraintDecls = new SymbolHash(1);
0182:
0183: // get all built-in types
0184: fGlobalTypeDecls = schemaFactory.getBuiltInTypes();
0185: // add anyType
0186: fGlobalTypeDecls.put(fAnyType.getName(), fAnyType);
0187: } else if (grammar == GRAMMAR_XSI) {
0188: // target namespace
0189: fTargetNamespace = SchemaSymbols.URI_XSI;
0190: // grammar description
0191: fGrammarDescription = new XSDDescription();
0192: fGrammarDescription.fContextType = XSDDescription.CONTEXT_PREPARSE;
0193: fGrammarDescription.setNamespace(SchemaSymbols.URI_XSI);
0194:
0195: // no global decls other than attributes
0196: fGlobalAttrGrpDecls = new SymbolHash(1);
0197: fGlobalElemDecls = new SymbolHash(1);
0198: fGlobalGroupDecls = new SymbolHash(1);
0199: fGlobalNotationDecls = new SymbolHash(1);
0200: fGlobalIDConstraintDecls = new SymbolHash(1);
0201: fGlobalTypeDecls = new SymbolHash(1);
0202:
0203: // 4 attributes, so initialize the size as 4*2 = 8
0204: fGlobalAttrDecls = new SymbolHash(8);
0205: String name = null;
0206: String tns = null;
0207: XSSimpleType type = null;
0208: short scope = XSConstants.SCOPE_GLOBAL;
0209:
0210: // xsi:type
0211: name = SchemaSymbols.XSI_TYPE;
0212: tns = SchemaSymbols.URI_XSI;
0213: type = schemaFactory
0214: .getBuiltInType(SchemaSymbols.ATTVAL_QNAME);
0215: fGlobalAttrDecls.put(name, new BuiltinAttrDecl(name,
0216: tns, type, scope));
0217:
0218: // xsi:nil
0219: name = SchemaSymbols.XSI_NIL;
0220: tns = SchemaSymbols.URI_XSI;
0221: type = schemaFactory
0222: .getBuiltInType(SchemaSymbols.ATTVAL_BOOLEAN);
0223: fGlobalAttrDecls.put(name, new BuiltinAttrDecl(name,
0224: tns, type, scope));
0225:
0226: XSSimpleType anyURI = schemaFactory
0227: .getBuiltInType(SchemaSymbols.ATTVAL_ANYURI);
0228:
0229: // xsi:schemaLocation
0230: name = SchemaSymbols.XSI_SCHEMALOCATION;
0231: tns = SchemaSymbols.URI_XSI;
0232: type = schemaFactory.createTypeList(null,
0233: SchemaSymbols.URI_XSI, (short) 0, anyURI, null);
0234: fGlobalAttrDecls.put(name, new BuiltinAttrDecl(name,
0235: tns, type, scope));
0236:
0237: // xsi:noNamespaceSchemaLocation
0238: name = SchemaSymbols.XSI_NONAMESPACESCHEMALOCATION;
0239: tns = SchemaSymbols.URI_XSI;
0240: type = anyURI;
0241: fGlobalAttrDecls.put(name, new BuiltinAttrDecl(name,
0242: tns, type, scope));
0243: }
0244: } // <init>(int)
0245:
0246: // return the XMLGrammarDescription corresponding to this
0247: // object
0248: public XMLGrammarDescription getGrammarDescription() {
0249: return fGrammarDescription.makeClone();
0250: } // getGrammarDescription(): XMLGrammarDescription
0251:
0252: // override these methods solely so that these
0253: // objects cannot be modified once they're created.
0254: public void setImportedGrammars(Vector importedGrammars) {
0255: // ignore
0256: }
0257:
0258: public void addGlobalAttributeDecl(XSAttributeDecl decl) {
0259: // ignore
0260: }
0261:
0262: public void addGlobalAttributeGroupDecl(
0263: XSAttributeGroupDecl decl) {
0264: // ignore
0265: }
0266:
0267: public void addGlobalElementDecl(XSElementDecl decl) {
0268: // ignore
0269: }
0270:
0271: public void addGlobalGroupDecl(XSGroupDecl decl) {
0272: // ignore
0273: }
0274:
0275: public void addGlobalNotationDecl(XSNotationDecl decl) {
0276: // ignore
0277: }
0278:
0279: public void addGlobalTypeDecl(XSTypeDefinition decl) {
0280: // ignore
0281: }
0282:
0283: public void addComplexTypeDecl(XSComplexTypeDecl decl,
0284: SimpleLocator locator) {
0285: // ignore
0286: }
0287:
0288: public void addRedefinedGroupDecl(XSGroupDecl derived,
0289: XSGroupDecl base, SimpleLocator locator) {
0290: // ignore
0291: }
0292:
0293: public synchronized void addDocument(Object document,
0294: String location) {
0295: // ignore
0296: }
0297:
0298: // annotation support
0299: synchronized DOMParser getDOMParser() {
0300: return null;
0301: }
0302:
0303: synchronized SAXParser getSAXParser() {
0304: return null;
0305: }
0306: }
0307:
0308: /**
0309: * <p>A partial schema for schemas for validating annotations.</p>
0310: *
0311: * @xerces.internal
0312: *
0313: * @author Michael Glavassevich, IBM
0314: */
0315: public static final class Schema4Annotations extends SchemaGrammar {
0316:
0317: /**
0318: * Special constructor to create a schema
0319: * capable of validating annotations.
0320: */
0321: public Schema4Annotations() {
0322:
0323: // target namespace
0324: fTargetNamespace = SchemaSymbols.URI_SCHEMAFORSCHEMA;
0325:
0326: // grammar description
0327: fGrammarDescription = new XSDDescription();
0328: fGrammarDescription.fContextType = XSDDescription.CONTEXT_PREPARSE;
0329: fGrammarDescription
0330: .setNamespace(SchemaSymbols.URI_SCHEMAFORSCHEMA);
0331:
0332: // no global decls other than types and
0333: // element declarations for <annotation>, <documentation> and <appinfo>.
0334: fGlobalAttrDecls = new SymbolHash(1);
0335: fGlobalAttrGrpDecls = new SymbolHash(1);
0336: fGlobalElemDecls = new SymbolHash(6);
0337: fGlobalGroupDecls = new SymbolHash(1);
0338: fGlobalNotationDecls = new SymbolHash(1);
0339: fGlobalIDConstraintDecls = new SymbolHash(1);
0340:
0341: // get all built-in types
0342: fGlobalTypeDecls = SG_SchemaNS.fGlobalTypeDecls;
0343:
0344: // create element declarations for <annotation>, <documentation> and <appinfo>
0345: XSElementDecl annotationDecl = createAnnotationElementDecl(SchemaSymbols.ELT_ANNOTATION);
0346: XSElementDecl documentationDecl = createAnnotationElementDecl(SchemaSymbols.ELT_DOCUMENTATION);
0347: XSElementDecl appinfoDecl = createAnnotationElementDecl(SchemaSymbols.ELT_APPINFO);
0348:
0349: // add global element declarations
0350: fGlobalElemDecls.put(annotationDecl.fName, annotationDecl);
0351: fGlobalElemDecls.put(documentationDecl.fName,
0352: documentationDecl);
0353: fGlobalElemDecls.put(appinfoDecl.fName, appinfoDecl);
0354:
0355: // create complex type declarations for <annotation>, <documentation> and <appinfo>
0356: XSComplexTypeDecl annotationType = new XSComplexTypeDecl();
0357: XSComplexTypeDecl documentationType = new XSComplexTypeDecl();
0358: XSComplexTypeDecl appinfoType = new XSComplexTypeDecl();
0359:
0360: // set the types on their element declarations
0361: annotationDecl.fType = annotationType;
0362: documentationDecl.fType = documentationType;
0363: appinfoDecl.fType = appinfoType;
0364:
0365: // create attribute groups for <annotation>, <documentation> and <appinfo>
0366: XSAttributeGroupDecl annotationAttrs = new XSAttributeGroupDecl();
0367: XSAttributeGroupDecl documentationAttrs = new XSAttributeGroupDecl();
0368: XSAttributeGroupDecl appinfoAttrs = new XSAttributeGroupDecl();
0369:
0370: // fill in attribute groups
0371: {
0372: // create and fill attribute uses for <annotation>, <documentation> and <appinfo>
0373: XSAttributeUseImpl annotationIDAttr = new XSAttributeUseImpl();
0374: annotationIDAttr.fAttrDecl = new XSAttributeDecl();
0375: annotationIDAttr.fAttrDecl.setValues(
0376: SchemaSymbols.ATT_ID, null,
0377: (XSSimpleType) fGlobalTypeDecls
0378: .get(SchemaSymbols.ATTVAL_ID),
0379: XSConstants.VC_NONE, XSConstants.SCOPE_LOCAL,
0380: null, annotationType, null);
0381: annotationIDAttr.fUse = SchemaSymbols.USE_OPTIONAL;
0382: annotationIDAttr.fConstraintType = XSConstants.VC_NONE;
0383:
0384: XSAttributeUseImpl documentationSourceAttr = new XSAttributeUseImpl();
0385: documentationSourceAttr.fAttrDecl = new XSAttributeDecl();
0386: documentationSourceAttr.fAttrDecl.setValues(
0387: SchemaSymbols.ATT_SOURCE, null,
0388: (XSSimpleType) fGlobalTypeDecls
0389: .get(SchemaSymbols.ATTVAL_ANYURI),
0390: XSConstants.VC_NONE, XSConstants.SCOPE_LOCAL,
0391: null, documentationType, null);
0392: documentationSourceAttr.fUse = SchemaSymbols.USE_OPTIONAL;
0393: documentationSourceAttr.fConstraintType = XSConstants.VC_NONE;
0394:
0395: XSAttributeUseImpl documentationLangAttr = new XSAttributeUseImpl();
0396: documentationLangAttr.fAttrDecl = new XSAttributeDecl();
0397: documentationLangAttr.fAttrDecl.setValues("lang"
0398: .intern(), NamespaceContext.XML_URI,
0399: (XSSimpleType) fGlobalTypeDecls
0400: .get(SchemaSymbols.ATTVAL_LANGUAGE),
0401: XSConstants.VC_NONE, XSConstants.SCOPE_LOCAL,
0402: null, documentationType, null);
0403: documentationLangAttr.fUse = SchemaSymbols.USE_OPTIONAL;
0404: documentationLangAttr.fConstraintType = XSConstants.VC_NONE;
0405:
0406: XSAttributeUseImpl appinfoSourceAttr = new XSAttributeUseImpl();
0407: appinfoSourceAttr.fAttrDecl = new XSAttributeDecl();
0408: appinfoSourceAttr.fAttrDecl.setValues(
0409: SchemaSymbols.ATT_SOURCE, null,
0410: (XSSimpleType) fGlobalTypeDecls
0411: .get(SchemaSymbols.ATTVAL_ANYURI),
0412: XSConstants.VC_NONE, XSConstants.SCOPE_LOCAL,
0413: null, appinfoType, null);
0414: appinfoSourceAttr.fUse = SchemaSymbols.USE_OPTIONAL;
0415: appinfoSourceAttr.fConstraintType = XSConstants.VC_NONE;
0416:
0417: // create lax attribute wildcard for <annotation>, <documentation> and <appinfo>
0418: XSWildcardDecl otherAttrs = new XSWildcardDecl();
0419: otherAttrs.fNamespaceList = new String[] {
0420: fTargetNamespace, null };
0421: otherAttrs.fType = XSWildcard.NSCONSTRAINT_NOT;
0422: otherAttrs.fProcessContents = XSWildcard.PC_LAX;
0423:
0424: // add attribute uses and wildcards to attribute groups for <annotation>, <documentation> and <appinfo>
0425: annotationAttrs.addAttributeUse(annotationIDAttr);
0426: annotationAttrs.fAttributeWC = otherAttrs;
0427:
0428: documentationAttrs
0429: .addAttributeUse(documentationSourceAttr);
0430: documentationAttrs
0431: .addAttributeUse(documentationLangAttr);
0432: documentationAttrs.fAttributeWC = otherAttrs;
0433:
0434: appinfoAttrs.addAttributeUse(appinfoSourceAttr);
0435: appinfoAttrs.fAttributeWC = otherAttrs;
0436: }
0437:
0438: // create particles for <annotation>
0439: XSParticleDecl annotationParticle = createUnboundedModelGroupParticle();
0440: {
0441: XSModelGroupImpl annotationChoice = new XSModelGroupImpl();
0442: annotationChoice.fCompositor = XSModelGroupImpl.MODELGROUP_CHOICE;
0443: annotationChoice.fParticleCount = 2;
0444: annotationChoice.fParticles = new XSParticleDecl[2];
0445: annotationChoice.fParticles[0] = createChoiceElementParticle(appinfoDecl);
0446: annotationChoice.fParticles[1] = createChoiceElementParticle(documentationDecl);
0447: annotationParticle.fValue = annotationChoice;
0448: }
0449:
0450: // create wildcard particle for <documentation> and <appinfo>
0451: XSParticleDecl anyWCSequenceParticle = createUnboundedAnyWildcardSequenceParticle();
0452:
0453: // fill complex types
0454: annotationType
0455: .setValues(
0456: "#AnonType_" + SchemaSymbols.ELT_ANNOTATION,
0457: fTargetNamespace,
0458: SchemaGrammar.fAnyType,
0459: XSConstants.DERIVATION_RESTRICTION,
0460: XSConstants.DERIVATION_NONE,
0461: (short) (XSConstants.DERIVATION_EXTENSION | XSConstants.DERIVATION_RESTRICTION),
0462: XSComplexTypeDecl.CONTENTTYPE_ELEMENT,
0463: false, annotationAttrs, null,
0464: annotationParticle, new XSObjectListImpl(
0465: null, 0));
0466: annotationType.setName("#AnonType_"
0467: + SchemaSymbols.ELT_ANNOTATION);
0468: annotationType.setIsAnonymous();
0469:
0470: documentationType
0471: .setValues(
0472: "#AnonType_"
0473: + SchemaSymbols.ELT_DOCUMENTATION,
0474: fTargetNamespace,
0475: SchemaGrammar.fAnyType,
0476: XSConstants.DERIVATION_RESTRICTION,
0477: XSConstants.DERIVATION_NONE,
0478: (short) (XSConstants.DERIVATION_EXTENSION | XSConstants.DERIVATION_RESTRICTION),
0479: XSComplexTypeDecl.CONTENTTYPE_MIXED, false,
0480: documentationAttrs, null,
0481: anyWCSequenceParticle,
0482: new XSObjectListImpl(null, 0));
0483: documentationType.setName("#AnonType_"
0484: + SchemaSymbols.ELT_DOCUMENTATION);
0485: documentationType.setIsAnonymous();
0486:
0487: appinfoType
0488: .setValues(
0489: "#AnonType_" + SchemaSymbols.ELT_APPINFO,
0490: fTargetNamespace,
0491: SchemaGrammar.fAnyType,
0492: XSConstants.DERIVATION_RESTRICTION,
0493: XSConstants.DERIVATION_NONE,
0494: (short) (XSConstants.DERIVATION_EXTENSION | XSConstants.DERIVATION_RESTRICTION),
0495: XSComplexTypeDecl.CONTENTTYPE_MIXED, false,
0496: appinfoAttrs, null, anyWCSequenceParticle,
0497: new XSObjectListImpl(null, 0));
0498: appinfoType.setName("#AnonType_"
0499: + SchemaSymbols.ELT_APPINFO);
0500: appinfoType.setIsAnonymous();
0501:
0502: } // <init>(int)
0503:
0504: // return the XMLGrammarDescription corresponding to this
0505: // object
0506: public XMLGrammarDescription getGrammarDescription() {
0507: return fGrammarDescription.makeClone();
0508: } // getGrammarDescription(): XMLGrammarDescription
0509:
0510: // override these methods solely so that these
0511: // objects cannot be modified once they're created.
0512: public void setImportedGrammars(Vector importedGrammars) {
0513: // ignore
0514: }
0515:
0516: public void addGlobalAttributeDecl(XSAttributeDecl decl) {
0517: // ignore
0518: }
0519:
0520: public void addGlobalAttributeGroupDecl(
0521: XSAttributeGroupDecl decl) {
0522: // ignore
0523: }
0524:
0525: public void addGlobalElementDecl(XSElementDecl decl) {
0526: // ignore
0527: }
0528:
0529: public void addGlobalGroupDecl(XSGroupDecl decl) {
0530: // ignore
0531: }
0532:
0533: public void addGlobalNotationDecl(XSNotationDecl decl) {
0534: // ignore
0535: }
0536:
0537: public void addGlobalTypeDecl(XSTypeDefinition decl) {
0538: // ignore
0539: }
0540:
0541: public void addComplexTypeDecl(XSComplexTypeDecl decl,
0542: SimpleLocator locator) {
0543: // ignore
0544: }
0545:
0546: public void addRedefinedGroupDecl(XSGroupDecl derived,
0547: XSGroupDecl base, SimpleLocator locator) {
0548: // ignore
0549: }
0550:
0551: public synchronized void addDocument(Object document,
0552: String location) {
0553: // ignore
0554: }
0555:
0556: // annotation support
0557: synchronized DOMParser getDOMParser() {
0558: return null;
0559: }
0560:
0561: synchronized SAXParser getSAXParser() {
0562: return null;
0563: }
0564:
0565: //
0566: // private helper methods
0567: //
0568:
0569: private XSElementDecl createAnnotationElementDecl(
0570: String localName) {
0571: XSElementDecl eDecl = new XSElementDecl();
0572: eDecl.fName = localName;
0573: eDecl.fTargetNamespace = fTargetNamespace;
0574: eDecl.setIsGlobal();
0575: eDecl.fBlock = (XSConstants.DERIVATION_EXTENSION
0576: | XSConstants.DERIVATION_RESTRICTION | XSConstants.DERIVATION_SUBSTITUTION);
0577: eDecl.setConstraintType(XSConstants.VC_NONE);
0578: return eDecl;
0579: }
0580:
0581: private XSParticleDecl createUnboundedModelGroupParticle() {
0582: XSParticleDecl particle = new XSParticleDecl();
0583: particle.fMinOccurs = 0;
0584: particle.fMaxOccurs = SchemaSymbols.OCCURRENCE_UNBOUNDED;
0585: particle.fType = XSParticleDecl.PARTICLE_MODELGROUP;
0586: return particle;
0587: }
0588:
0589: private XSParticleDecl createChoiceElementParticle(
0590: XSElementDecl ref) {
0591: XSParticleDecl particle = new XSParticleDecl();
0592: particle.fMinOccurs = 1;
0593: particle.fMaxOccurs = 1;
0594: particle.fType = XSParticleDecl.PARTICLE_ELEMENT;
0595: particle.fValue = ref;
0596: return particle;
0597: }
0598:
0599: private XSParticleDecl createUnboundedAnyWildcardSequenceParticle() {
0600: XSParticleDecl particle = createUnboundedModelGroupParticle();
0601: XSModelGroupImpl sequence = new XSModelGroupImpl();
0602: sequence.fCompositor = XSModelGroupImpl.MODELGROUP_SEQUENCE;
0603: sequence.fParticleCount = 1;
0604: sequence.fParticles = new XSParticleDecl[1];
0605: sequence.fParticles[0] = createAnyLaxWildcardParticle();
0606: particle.fValue = sequence;
0607: return particle;
0608: }
0609:
0610: private XSParticleDecl createAnyLaxWildcardParticle() {
0611: XSParticleDecl particle = new XSParticleDecl();
0612: particle.fMinOccurs = 1;
0613: particle.fMaxOccurs = 1;
0614: particle.fType = XSParticleDecl.PARTICLE_WILDCARD;
0615:
0616: XSWildcardDecl anyWC = new XSWildcardDecl();
0617: anyWC.fNamespaceList = null;
0618: anyWC.fType = XSWildcard.NSCONSTRAINT_ANY;
0619: anyWC.fProcessContents = XSWildcard.PC_LAX;
0620:
0621: particle.fValue = anyWC;
0622: return particle;
0623: }
0624: }
0625:
0626: // Grammar methods
0627:
0628: // return the XMLGrammarDescription corresponding to this
0629: // object
0630: public XMLGrammarDescription getGrammarDescription() {
0631: return fGrammarDescription;
0632: } // getGrammarDescription(): XMLGrammarDescription
0633:
0634: // DTDGrammar methods
0635: public boolean isNamespaceAware() {
0636: return true;
0637: } // isNamespaceAware():boolean
0638:
0639: Vector fImported = null;
0640:
0641: public void setImportedGrammars(Vector importedGrammars) {
0642: fImported = importedGrammars;
0643: }
0644:
0645: public Vector getImportedGrammars() {
0646: return fImported;
0647: }
0648:
0649: /**
0650: * Returns this grammar's target namespace.
0651: */
0652: public final String getTargetNamespace() {
0653: return fTargetNamespace;
0654: } // getTargetNamespace():String
0655:
0656: /**
0657: * register one global attribute
0658: */
0659: public void addGlobalAttributeDecl(XSAttributeDecl decl) {
0660: fGlobalAttrDecls.put(decl.fName, decl);
0661: }
0662:
0663: /**
0664: * register one global attribute group
0665: */
0666: public void addGlobalAttributeGroupDecl(XSAttributeGroupDecl decl) {
0667: fGlobalAttrGrpDecls.put(decl.fName, decl);
0668: }
0669:
0670: /**
0671: * register one global element
0672: */
0673: public void addGlobalElementDecl(XSElementDecl decl) {
0674: fGlobalElemDecls.put(decl.fName, decl);
0675:
0676: // if there is a substitution group affiliation, store in an array,
0677: // for further constraint checking: UPA, PD, EDC
0678: if (decl.fSubGroup != null) {
0679: if (fSubGroupCount == fSubGroups.length)
0680: fSubGroups = resize(fSubGroups, fSubGroupCount
0681: + INC_SIZE);
0682: fSubGroups[fSubGroupCount++] = decl;
0683: }
0684: }
0685:
0686: /**
0687: * register one global group
0688: */
0689: public void addGlobalGroupDecl(XSGroupDecl decl) {
0690: fGlobalGroupDecls.put(decl.fName, decl);
0691: }
0692:
0693: /**
0694: * register one global notation
0695: */
0696: public void addGlobalNotationDecl(XSNotationDecl decl) {
0697: fGlobalNotationDecls.put(decl.fName, decl);
0698: }
0699:
0700: /**
0701: * register one global type
0702: */
0703: public void addGlobalTypeDecl(XSTypeDefinition decl) {
0704: fGlobalTypeDecls.put(decl.getName(), decl);
0705: }
0706:
0707: /**
0708: * register one identity constraint
0709: */
0710: public final void addIDConstraintDecl(XSElementDecl elmDecl,
0711: IdentityConstraint decl) {
0712: elmDecl.addIDConstraint(decl);
0713: fGlobalIDConstraintDecls.put(decl.getIdentityConstraintName(),
0714: decl);
0715: }
0716:
0717: /**
0718: * get one global attribute
0719: */
0720: public final XSAttributeDecl getGlobalAttributeDecl(String declName) {
0721: return (XSAttributeDecl) fGlobalAttrDecls.get(declName);
0722: }
0723:
0724: /**
0725: * get one global attribute group
0726: */
0727: public final XSAttributeGroupDecl getGlobalAttributeGroupDecl(
0728: String declName) {
0729: return (XSAttributeGroupDecl) fGlobalAttrGrpDecls.get(declName);
0730: }
0731:
0732: /**
0733: * get one global element
0734: */
0735: public final XSElementDecl getGlobalElementDecl(String declName) {
0736: return (XSElementDecl) fGlobalElemDecls.get(declName);
0737: }
0738:
0739: /**
0740: * get one global group
0741: */
0742: public final XSGroupDecl getGlobalGroupDecl(String declName) {
0743: return (XSGroupDecl) fGlobalGroupDecls.get(declName);
0744: }
0745:
0746: /**
0747: * get one global notation
0748: */
0749: public final XSNotationDecl getGlobalNotationDecl(String declName) {
0750: return (XSNotationDecl) fGlobalNotationDecls.get(declName);
0751: }
0752:
0753: /**
0754: * get one global type
0755: */
0756: public final XSTypeDefinition getGlobalTypeDecl(String declName) {
0757: return (XSTypeDefinition) fGlobalTypeDecls.get(declName);
0758: }
0759:
0760: /**
0761: * get one identity constraint
0762: */
0763: public final IdentityConstraint getIDConstraintDecl(String declName) {
0764: return (IdentityConstraint) fGlobalIDConstraintDecls
0765: .get(declName);
0766: }
0767:
0768: /**
0769: * get one identity constraint
0770: */
0771: public final boolean hasIDConstraints() {
0772: return fGlobalIDConstraintDecls.getLength() > 0;
0773: }
0774:
0775: // array to store complex type decls
0776: private static final int INITIAL_SIZE = 16;
0777: private static final int INC_SIZE = 16;
0778:
0779: private int fCTCount = 0;
0780: private XSComplexTypeDecl[] fComplexTypeDecls = new XSComplexTypeDecl[INITIAL_SIZE];
0781: private SimpleLocator[] fCTLocators = new SimpleLocator[INITIAL_SIZE];
0782:
0783: // an array to store groups being redefined by restriction
0784: // even-numbered elements are the derived groups, odd-numbered ones their bases
0785: private static final int REDEFINED_GROUP_INIT_SIZE = 2;
0786: private int fRGCount = 0;
0787: private XSGroupDecl[] fRedefinedGroupDecls = new XSGroupDecl[REDEFINED_GROUP_INIT_SIZE];
0788: private SimpleLocator[] fRGLocators = new SimpleLocator[REDEFINED_GROUP_INIT_SIZE / 2];
0789:
0790: // a flag to indicate whether we have checked the 3 constraints on this
0791: // grammar.
0792: boolean fFullChecked = false;
0793:
0794: /**
0795: * add one complex type decl: for later constraint checking
0796: */
0797: public void addComplexTypeDecl(XSComplexTypeDecl decl,
0798: SimpleLocator locator) {
0799: if (fCTCount == fComplexTypeDecls.length) {
0800: fComplexTypeDecls = resize(fComplexTypeDecls, fCTCount
0801: + INC_SIZE);
0802: fCTLocators = resize(fCTLocators, fCTCount + INC_SIZE);
0803: }
0804: fCTLocators[fCTCount] = locator;
0805: fComplexTypeDecls[fCTCount++] = decl;
0806: }
0807:
0808: /**
0809: * add a group redefined by restriction: for later constraint checking
0810: */
0811: public void addRedefinedGroupDecl(XSGroupDecl derived,
0812: XSGroupDecl base, SimpleLocator locator) {
0813: if (fRGCount == fRedefinedGroupDecls.length) {
0814: // double array size each time.
0815: fRedefinedGroupDecls = resize(fRedefinedGroupDecls,
0816: fRGCount << 1);
0817: fRGLocators = resize(fRGLocators, fRGCount);
0818: }
0819: fRGLocators[fRGCount / 2] = locator;
0820: fRedefinedGroupDecls[fRGCount++] = derived;
0821: fRedefinedGroupDecls[fRGCount++] = base;
0822: }
0823:
0824: /**
0825: * get all complex type decls: for later constraint checking
0826: */
0827: final XSComplexTypeDecl[] getUncheckedComplexTypeDecls() {
0828: if (fCTCount < fComplexTypeDecls.length) {
0829: fComplexTypeDecls = resize(fComplexTypeDecls, fCTCount);
0830: fCTLocators = resize(fCTLocators, fCTCount);
0831: }
0832: return fComplexTypeDecls;
0833: }
0834:
0835: /**
0836: * get the error locator of all complex type decls
0837: */
0838: final SimpleLocator[] getUncheckedCTLocators() {
0839: if (fCTCount < fCTLocators.length) {
0840: fComplexTypeDecls = resize(fComplexTypeDecls, fCTCount);
0841: fCTLocators = resize(fCTLocators, fCTCount);
0842: }
0843: return fCTLocators;
0844: }
0845:
0846: /**
0847: * get all redefined groups: for later constraint checking
0848: */
0849: final XSGroupDecl[] getRedefinedGroupDecls() {
0850: if (fRGCount < fRedefinedGroupDecls.length) {
0851: fRedefinedGroupDecls = resize(fRedefinedGroupDecls,
0852: fRGCount);
0853: fRGLocators = resize(fRGLocators, fRGCount / 2);
0854: }
0855: return fRedefinedGroupDecls;
0856: }
0857:
0858: /**
0859: * get the error locator of all redefined groups
0860: */
0861: final SimpleLocator[] getRGLocators() {
0862: if (fRGCount < fRedefinedGroupDecls.length) {
0863: fRedefinedGroupDecls = resize(fRedefinedGroupDecls,
0864: fRGCount);
0865: fRGLocators = resize(fRGLocators, fRGCount / 2);
0866: }
0867: return fRGLocators;
0868: }
0869:
0870: /**
0871: * after the first-round checking, some types don't need to be checked
0872: * against UPA again. here we trim the array to the proper size.
0873: */
0874: final void setUncheckedTypeNum(int newSize) {
0875: fCTCount = newSize;
0876: fComplexTypeDecls = resize(fComplexTypeDecls, fCTCount);
0877: fCTLocators = resize(fCTLocators, fCTCount);
0878: }
0879:
0880: // used to store all substitution group information declared in
0881: // this namespace
0882: private int fSubGroupCount = 0;
0883: private XSElementDecl[] fSubGroups = new XSElementDecl[INITIAL_SIZE];
0884:
0885: /**
0886: * get all substitution group information: for the 3 constraint checking
0887: */
0888: final XSElementDecl[] getSubstitutionGroups() {
0889: if (fSubGroupCount < fSubGroups.length)
0890: fSubGroups = resize(fSubGroups, fSubGroupCount);
0891: return fSubGroups;
0892: }
0893:
0894: // anyType and anySimpleType: because there are so many places where
0895: // we need direct access to these two types
0896: public final static XSComplexTypeDecl fAnyType = new XSAnyType();
0897:
0898: private static class XSAnyType extends XSComplexTypeDecl {
0899: public XSAnyType() {
0900: fName = SchemaSymbols.ATTVAL_ANYTYPE;
0901: super .fTargetNamespace = SchemaSymbols.URI_SCHEMAFORSCHEMA;
0902: fBaseType = this ;
0903: fDerivedBy = XSConstants.DERIVATION_RESTRICTION;
0904: fContentType = XSComplexTypeDecl.CONTENTTYPE_MIXED;
0905:
0906: fParticle = null;
0907: fAttrGrp = null;
0908: }
0909:
0910: // overridden methods
0911: public void setValues(String name, String targetNamespace,
0912: XSTypeDefinition baseType, short derivedBy,
0913: short schemaFinal, short block, short contentType,
0914: boolean isAbstract, XSAttributeGroupDecl attrGrp,
0915: XSSimpleType simpleType, XSParticleDecl particle) {
0916: // don't allow this.
0917: }
0918:
0919: public void setName(String name) {
0920: // don't allow this.
0921: }
0922:
0923: public void setIsAbstractType() {
0924: // null implementation
0925: }
0926:
0927: public void setContainsTypeID() {
0928: // null implementation
0929: }
0930:
0931: public void setIsAnonymous() {
0932: // null implementation
0933: }
0934:
0935: public void reset() {
0936: // null implementation
0937: }
0938:
0939: public XSObjectList getAttributeUses() {
0940: return new XSObjectListImpl(null, 0);
0941: }
0942:
0943: public XSAttributeGroupDecl getAttrGrp() {
0944: XSWildcardDecl wildcard = new XSWildcardDecl();
0945: wildcard.fProcessContents = XSWildcardDecl.PC_LAX;
0946: XSAttributeGroupDecl attrGrp = new XSAttributeGroupDecl();
0947: attrGrp.fAttributeWC = wildcard;
0948: return attrGrp;
0949: }
0950:
0951: public XSWildcard getAttributeWildcard() {
0952: XSWildcardDecl wildcard = new XSWildcardDecl();
0953: wildcard.fProcessContents = XSWildcardDecl.PC_LAX;
0954: return wildcard;
0955: }
0956:
0957: public XSParticle getParticle() {
0958: // the wildcard used in anyType (content and attribute)
0959: // the spec will change strict to skip for anyType
0960: XSWildcardDecl wildcard = new XSWildcardDecl();
0961: wildcard.fProcessContents = XSWildcardDecl.PC_LAX;
0962: // the particle for the content wildcard
0963: XSParticleDecl particleW = new XSParticleDecl();
0964: particleW.fMinOccurs = 0;
0965: particleW.fMaxOccurs = SchemaSymbols.OCCURRENCE_UNBOUNDED;
0966: particleW.fType = XSParticleDecl.PARTICLE_WILDCARD;
0967: particleW.fValue = wildcard;
0968: // the model group of a sequence of the above particle
0969: XSModelGroupImpl group = new XSModelGroupImpl();
0970: group.fCompositor = XSModelGroupImpl.MODELGROUP_SEQUENCE;
0971: group.fParticleCount = 1;
0972: group.fParticles = new XSParticleDecl[1];
0973: group.fParticles[0] = particleW;
0974: // the content of anyType: particle of the above model group
0975: XSParticleDecl particleG = new XSParticleDecl();
0976: particleG.fType = XSParticleDecl.PARTICLE_MODELGROUP;
0977: particleG.fValue = group;
0978:
0979: return particleG;
0980: }
0981:
0982: public XSObjectList getAnnotations() {
0983: return null;
0984: }
0985: }
0986:
0987: private static class BuiltinAttrDecl extends XSAttributeDecl {
0988: public BuiltinAttrDecl(String name, String tns,
0989: XSSimpleType type, short scope) {
0990: fName = name;
0991: super .fTargetNamespace = tns;
0992: fType = type;
0993: fScope = scope;
0994: }
0995:
0996: public void setValues(String name, String targetNamespace,
0997: XSSimpleType simpleType, short constraintType,
0998: short scope, ValidatedInfo valInfo,
0999: XSComplexTypeDecl enclosingCT) {
1000: // ignore this call.
1001: }
1002:
1003: public void reset() {
1004: // also ignore this call.
1005: }
1006:
1007: public XSAnnotation getAnnotation() {
1008: return null;
1009: }
1010: } // class BuiltinAttrDecl
1011:
1012: // the grammars to hold components of the schema namespace
1013: public final static BuiltinSchemaGrammar SG_SchemaNS = new BuiltinSchemaGrammar(
1014: GRAMMAR_XS);
1015:
1016: public final static Schema4Annotations SG_Schema4Annotations = new Schema4Annotations();
1017:
1018: public final static XSSimpleType fAnySimpleType = (XSSimpleType) SG_SchemaNS
1019: .getGlobalTypeDecl(SchemaSymbols.ATTVAL_ANYSIMPLETYPE);
1020:
1021: // the grammars to hold components of the schema-instance namespace
1022: public final static BuiltinSchemaGrammar SG_XSI = new BuiltinSchemaGrammar(
1023: GRAMMAR_XSI);
1024:
1025: static final XSComplexTypeDecl[] resize(
1026: XSComplexTypeDecl[] oldArray, int newSize) {
1027: XSComplexTypeDecl[] newArray = new XSComplexTypeDecl[newSize];
1028: System.arraycopy(oldArray, 0, newArray, 0, Math.min(
1029: oldArray.length, newSize));
1030: return newArray;
1031: }
1032:
1033: static final XSGroupDecl[] resize(XSGroupDecl[] oldArray,
1034: int newSize) {
1035: XSGroupDecl[] newArray = new XSGroupDecl[newSize];
1036: System.arraycopy(oldArray, 0, newArray, 0, Math.min(
1037: oldArray.length, newSize));
1038: return newArray;
1039: }
1040:
1041: static final XSElementDecl[] resize(XSElementDecl[] oldArray,
1042: int newSize) {
1043: XSElementDecl[] newArray = new XSElementDecl[newSize];
1044: System.arraycopy(oldArray, 0, newArray, 0, Math.min(
1045: oldArray.length, newSize));
1046: return newArray;
1047: }
1048:
1049: static final SimpleLocator[] resize(SimpleLocator[] oldArray,
1050: int newSize) {
1051: SimpleLocator[] newArray = new SimpleLocator[newSize];
1052: System.arraycopy(oldArray, 0, newArray, 0, Math.min(
1053: oldArray.length, newSize));
1054: return newArray;
1055: }
1056:
1057: // XSNamespaceItem methods
1058:
1059: // the max index / the max value of XSObject type
1060: private static final short MAX_COMP_IDX = XSTypeDefinition.SIMPLE_TYPE;
1061: private static final boolean[] GLOBAL_COMP = { false, // null
1062: true, // attribute
1063: true, // element
1064: true, // type
1065: false, // attribute use
1066: true, // attribute group
1067: true, // group
1068: false, // model group
1069: false, // particle
1070: false, // wildcard
1071: false, // idc
1072: true, // notation
1073: false, // annotation
1074: false, // facet
1075: false, // multi value facet
1076: true, // complex type
1077: true // simple type
1078: };
1079:
1080: // store a certain kind of components from all namespaces
1081: private XSNamedMap[] fComponents = null;
1082:
1083: // store the documents and their locations contributing to this namespace
1084: // REVISIT: use StringList and XSObjectList for there fields.
1085: private Vector fDocuments = null;
1086: private Vector fLocations = null;
1087:
1088: public synchronized void addDocument(Object document,
1089: String location) {
1090: if (fDocuments == null) {
1091: fDocuments = new Vector();
1092: fLocations = new Vector();
1093: }
1094: fDocuments.addElement(document);
1095: fLocations.addElement(location);
1096: }
1097:
1098: /**
1099: * [schema namespace]
1100: * @see <a href="http://www.w3.org/TR/xmlschema-1/#nsi-schema_namespace">[schema namespace]</a>
1101: * @return The target namespace of this item.
1102: */
1103: public String getSchemaNamespace() {
1104: return fTargetNamespace;
1105: }
1106:
1107: // annotation support
1108: synchronized DOMParser getDOMParser() {
1109: if (fDOMParser != null) {
1110: DOMParser parser = (DOMParser) fDOMParser.get();
1111: if (parser != null) {
1112: return parser;
1113: }
1114: }
1115: // REVISIT: when schema handles XML 1.1, will need to
1116: // revisit this (and the practice of not prepending an XML decl to the annotation string
1117: XML11Configuration config = new XML11Configuration(fSymbolTable);
1118: // note that this should never produce errors or require
1119: // entity resolution, so just a barebones configuration with
1120: // a couple of feature set will do fine
1121: config.setFeature(Constants.SAX_FEATURE_PREFIX
1122: + Constants.NAMESPACES_FEATURE, true);
1123: config.setFeature(Constants.SAX_FEATURE_PREFIX
1124: + Constants.VALIDATION_FEATURE, false);
1125:
1126: DOMParser parser = new DOMParser(config);
1127: try {
1128: parser.setFeature(Constants.XERCES_FEATURE_PREFIX
1129: + Constants.DEFER_NODE_EXPANSION_FEATURE, false);
1130: } catch (SAXException exc) {
1131: }
1132: fDOMParser = new SoftReference(parser);
1133: return parser;
1134: }
1135:
1136: synchronized SAXParser getSAXParser() {
1137: if (fSAXParser != null) {
1138: SAXParser parser = (SAXParser) fSAXParser.get();
1139: if (parser != null) {
1140: return parser;
1141: }
1142: }
1143: // REVISIT: when schema handles XML 1.1, will need to
1144: // revisit this (and the practice of not prepending an XML decl to the annotation string
1145: XML11Configuration config = new XML11Configuration(fSymbolTable);
1146: // note that this should never produce errors or require
1147: // entity resolution, so just a barebones configuration with
1148: // a couple of feature set will do fine
1149: config.setFeature(Constants.SAX_FEATURE_PREFIX
1150: + Constants.NAMESPACES_FEATURE, true);
1151: config.setFeature(Constants.SAX_FEATURE_PREFIX
1152: + Constants.VALIDATION_FEATURE, false);
1153: SAXParser parser = new SAXParser(config);
1154: fSAXParser = new SoftReference(parser);
1155: return parser;
1156: }
1157:
1158: /**
1159: * [schema components]: a list of top-level components, i.e. element
1160: * declarations, attribute declarations, etc.
1161: * @param objectType The type of the declaration, i.e.
1162: * <code>ELEMENT_DECLARATION</code>. Note that
1163: * <code>XSTypeDefinition.SIMPLE_TYPE</code> and
1164: * <code>XSTypeDefinition.COMPLEX_TYPE</code> can also be used as the
1165: * <code>objectType</code> to retrieve only complex types or simple
1166: * types, instead of all types.
1167: * @return A list of top-level definition of the specified type in
1168: * <code>objectType</code> or an empty <code>XSNamedMap</code> if no
1169: * such definitions exist.
1170: */
1171: public synchronized XSNamedMap getComponents(short objectType) {
1172: if (objectType <= 0 || objectType > MAX_COMP_IDX
1173: || !GLOBAL_COMP[objectType]) {
1174: return XSNamedMapImpl.EMPTY_MAP;
1175: }
1176:
1177: if (fComponents == null)
1178: fComponents = new XSNamedMap[MAX_COMP_IDX + 1];
1179:
1180: // get the hashtable for this type of components
1181: if (fComponents[objectType] == null) {
1182: SymbolHash table = null;
1183: switch (objectType) {
1184: case XSConstants.TYPE_DEFINITION:
1185: case XSTypeDefinition.COMPLEX_TYPE:
1186: case XSTypeDefinition.SIMPLE_TYPE:
1187: table = fGlobalTypeDecls;
1188: break;
1189: case XSConstants.ATTRIBUTE_DECLARATION:
1190: table = fGlobalAttrDecls;
1191: break;
1192: case XSConstants.ELEMENT_DECLARATION:
1193: table = fGlobalElemDecls;
1194: break;
1195: case XSConstants.ATTRIBUTE_GROUP:
1196: table = fGlobalAttrGrpDecls;
1197: break;
1198: case XSConstants.MODEL_GROUP_DEFINITION:
1199: table = fGlobalGroupDecls;
1200: break;
1201: case XSConstants.NOTATION_DECLARATION:
1202: table = fGlobalNotationDecls;
1203: break;
1204: }
1205:
1206: // for complex/simple types, create a special implementation,
1207: // which take specific types out of the hash table
1208: if (objectType == XSTypeDefinition.COMPLEX_TYPE
1209: || objectType == XSTypeDefinition.SIMPLE_TYPE) {
1210: fComponents[objectType] = new XSNamedMap4Types(
1211: fTargetNamespace, table, objectType);
1212: } else {
1213: fComponents[objectType] = new XSNamedMapImpl(
1214: fTargetNamespace, table);
1215: }
1216: }
1217:
1218: return fComponents[objectType];
1219: }
1220:
1221: /**
1222: * Convenience method. Returns a top-level simple or complex type
1223: * definition.
1224: * @param name The name of the definition.
1225: * @return An <code>XSTypeDefinition</code> or null if such definition
1226: * does not exist.
1227: */
1228: public XSTypeDefinition getTypeDefinition(String name) {
1229: return getGlobalTypeDecl(name);
1230: }
1231:
1232: /**
1233: * Convenience method. Returns a top-level attribute declaration.
1234: * @param name The name of the declaration.
1235: * @return A top-level attribute declaration or null if such declaration
1236: * does not exist.
1237: */
1238: public XSAttributeDeclaration getAttributeDeclaration(String name) {
1239: return getGlobalAttributeDecl(name);
1240: }
1241:
1242: /**
1243: * Convenience method. Returns a top-level element declaration.
1244: * @param name The name of the declaration.
1245: * @return A top-level element declaration or null if such declaration
1246: * does not exist.
1247: */
1248: public XSElementDeclaration getElementDeclaration(String name) {
1249: return getGlobalElementDecl(name);
1250: }
1251:
1252: /**
1253: * Convenience method. Returns a top-level attribute group definition.
1254: * @param name The name of the definition.
1255: * @return A top-level attribute group definition or null if such
1256: * definition does not exist.
1257: */
1258: public XSAttributeGroupDefinition getAttributeGroup(String name) {
1259: return getGlobalAttributeGroupDecl(name);
1260: }
1261:
1262: /**
1263: * Convenience method. Returns a top-level model group definition.
1264: *
1265: * @param name The name of the definition.
1266: * @return A top-level model group definition definition or null if such
1267: * definition does not exist.
1268: */
1269: public XSModelGroupDefinition getModelGroupDefinition(String name) {
1270: return getGlobalGroupDecl(name);
1271: }
1272:
1273: /**
1274: * Convenience method. Returns a top-level notation declaration.
1275: *
1276: * @param name The name of the declaration.
1277: * @return A top-level notation declaration or null if such declaration
1278: * does not exist.
1279: */
1280: public XSNotationDeclaration getNotationDeclaration(String name) {
1281: return getGlobalNotationDecl(name);
1282: }
1283:
1284: /**
1285: * [document location]
1286: * @see <a href="http://www.w3.org/TR/xmlschema-1/#sd-document_location">[document location]</a>
1287: * @return a list of document information item
1288: */
1289: public StringList getDocumentLocations() {
1290: return new StringListImpl(fLocations);
1291: }
1292:
1293: /**
1294: * Return an <code>XSModel</code> that represents components in this schema
1295: * grammar.
1296: *
1297: * @return an <code>XSModel</code> representing this schema grammar
1298: */
1299: public XSModel toXSModel() {
1300: return new XSModelImpl(new SchemaGrammar[] { this });
1301: }
1302:
1303: public XSModel toXSModel(XSGrammar[] grammars) {
1304: if (grammars == null || grammars.length == 0)
1305: return toXSModel();
1306:
1307: int len = grammars.length;
1308: boolean hasSelf = false;
1309: for (int i = 0; i < len; i++) {
1310: if (grammars[i] == this ) {
1311: hasSelf = true;
1312: break;
1313: }
1314: }
1315:
1316: SchemaGrammar[] gs = new SchemaGrammar[hasSelf ? len : len + 1];
1317: for (int i = 0; i < len; i++)
1318: gs[i] = (SchemaGrammar) grammars[i];
1319: if (!hasSelf)
1320: gs[len] = this ;
1321: return new XSModelImpl(gs);
1322: }
1323:
1324: /**
1325: * @see org.apache.xerces.xs.XSNamespaceItem#getAnnotations()
1326: */
1327: public XSObjectList getAnnotations() {
1328: return new XSObjectListImpl(fAnnotations, fNumAnnotations);
1329: }
1330:
1331: public void addAnnotation(XSAnnotationImpl annotation) {
1332: if (annotation == null)
1333: return;
1334: if (fAnnotations == null) {
1335: fAnnotations = new XSAnnotationImpl[2];
1336: } else if (fNumAnnotations == fAnnotations.length) {
1337: XSAnnotationImpl[] newArray = new XSAnnotationImpl[fNumAnnotations << 1];
1338: System.arraycopy(fAnnotations, 0, newArray, 0,
1339: fNumAnnotations);
1340: fAnnotations = newArray;
1341: }
1342: fAnnotations[fNumAnnotations++] = annotation;
1343: }
1344:
1345: } // class SchemaGrammar
|