0001: /**
0002: * Redistribution and use of this software and associated documentation
0003: * ("Software"), with or without modification, are permitted provided
0004: * that the following conditions are met:
0005: *
0006: * 1. Redistributions of source code must retain copyright
0007: * statements and notices. Redistributions must also contain a
0008: * copy of this document.
0009: *
0010: * 2. Redistributions in binary form must reproduce the
0011: * above copyright notice, this list of conditions and the
0012: * following disclaimer in the documentation and/or other
0013: * materials provided with the distribution.
0014: *
0015: * 3. The name "Exolab" must not be used to endorse or promote
0016: * products derived from this Software without prior written
0017: * permission of Intalio, Inc. For written permission,
0018: * please contact info@exolab.org.
0019: *
0020: * 4. Products derived from this Software may not be called "Exolab"
0021: * nor may "Exolab" appear in their names without prior written
0022: * permission of Intalio, Inc. Exolab is a registered
0023: * trademark of Intalio, Inc.
0024: *
0025: * 5. Due credit should be given to the Exolab Project
0026: * (http://www.exolab.org/).
0027: *
0028: * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
0029: * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
0030: * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
0031: * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
0032: * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
0033: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
0034: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
0035: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
0036: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
0037: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0038: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
0039: * OF THE POSSIBILITY OF SUCH DAMAGE.
0040: *
0041: * Copyright 1999-2003 (C) Intalio, Inc. All Rights Reserved.
0042: *
0043: * $Id: Schema.java 6230 2006-09-19 07:56:07Z wguttmn $
0044: */package org.exolab.castor.xml.schema;
0045:
0046: import org.exolab.castor.xml.Namespaces;
0047: import org.exolab.castor.xml.ValidationException;
0048:
0049: import java.util.Vector;
0050: import java.util.Hashtable;
0051: import java.util.Enumeration;
0052:
0053: /**
0054: * A class representing an XML Schema Definition. This class also
0055: * contains some Factory methods for creating Top-Level structures.
0056: *
0057: * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a>
0058: * @version $Revision: 6230 $ $Date: 2006-04-26 13:58:52 -0600 (Wed, 26 Apr 2006) $
0059: */
0060: public class Schema extends Annotated {
0061: /** SerialVersionUID */
0062: private static final long serialVersionUID = -8130246250710502508L;
0063:
0064: //-----------------------------/
0065: //- Class Fields / Constants -/
0066: //-----------------------------/
0067:
0068: /*
0069: // Old schema namespaces, left here for
0070: // reference
0071:
0072: April 2000 Working Draft Namespace
0073: = "http://www.w3.org/1999/XMLSchema";
0074:
0075: October 2000 Candidate Release Namespace
0076: = "http://www.w3.org/2000/10/XMLSchema";
0077:
0078: */
0079:
0080: /**
0081: * The Namespace supported by the W3C XML Schema
0082: * Recommendation.
0083: */
0084: public static final String DEFAULT_SCHEMA_NS = "http://www.w3.org/2001/XMLSchema";
0085:
0086: /**
0087: * The Namespace supported by the W3C XML Schema
0088: * Recommendation for the built-in types:
0089: * xsi:type, xsi:nil, and xsi:schemaLocation.
0090: */
0091: public static final String XSI_NAMESPACE = "http://www.w3.org/2001/XMLSchema-instance";
0092:
0093: /**
0094: * Null argument error message
0095: */
0096: private static final String NULL_ARGUMENT = "A null argument was passed to "
0097: + Schema.class.getName() + "#";
0098:
0099: /**
0100: * The SimpleTypesFactory used by this Schema
0101: */
0102: private static SimpleTypesFactory simpleTypesFactory = new SimpleTypesFactory();
0103:
0104: //--------------------/
0105: //- Member Variables -/
0106: //--------------------/
0107:
0108: /**
0109: * The attributeFormDefault property
0110: **/
0111: private Form _attributeFormDefault = null;
0112:
0113: /**
0114: * The global AttribteGroups for this Schema
0115: **/
0116: private Hashtable _attributeGroups = null;
0117:
0118: /**
0119: * The global attributes for this Schema
0120: **/
0121: private Hashtable _attributes = null;
0122:
0123: /**
0124: * The value of the block attribute.
0125: **/
0126: private BlockList _block = null;
0127:
0128: /**
0129: * A list of defined architypes
0130: **/
0131: private Hashtable _complexTypes = null;
0132:
0133: /**
0134: * The elementFormDefault attribute for this Schema
0135: **/
0136: private Form _elementFormDefault = null;
0137:
0138: /**
0139: * A list of defined elements
0140: **/
0141: private Hashtable _elements = null;
0142:
0143: /**
0144: * The value of the final attribute.
0145: **/
0146: private FinalList _final = null;
0147:
0148: /**
0149: * A list of defined top-levels groups
0150: */
0151: private Hashtable _groups = null;
0152:
0153: /**
0154: * A list of defined <redefine>
0155: */
0156: private Hashtable _redefineSchemas = null;
0157:
0158: /**
0159: * The ID for this Schema
0160: **/
0161: private String _id = null;
0162:
0163: /**
0164: * A list of imported schemas
0165: **/
0166: private Hashtable _importedSchemas = null;
0167:
0168: /**
0169: * A list of included schemas meant to be used only
0170: * when the cache mechanism is enabled.
0171: **/
0172: private Hashtable _cachedincludedSchemas = null;
0173:
0174: /**
0175: * A list of XML Schema files included in this schema
0176: **/
0177: private Vector _includedSchemas = null;
0178:
0179: /**
0180: * A list of namespaces declared in this schema
0181: */
0182: private Namespaces _namespaces = null;
0183:
0184: /**
0185: * The schemaLocation hint provided in the 'import' tag.
0186: * By default the schemaLocation is the locator of the SaxUnmarshaller
0187: **/
0188: private String _schemaLocation = null;
0189:
0190: /**
0191: * The namespace of this XML Schema (ie the namespace
0192: * of the W3C Schema supported by this Schema).
0193: **/
0194: private String _schemaNamespace = null;
0195:
0196: /**
0197: * A list of defined SimpleTypes
0198: **/
0199: private Hashtable _simpleTypes = null;
0200:
0201: /**
0202: * The targetNamespace for this Schema
0203: **/
0204: private String _targetNamespace = null;
0205:
0206: /**
0207: * The version information as specified by the version
0208: * attribute
0209: **/
0210: private String _version = null;
0211:
0212: /**
0213: * A reference to the master schema used when this
0214: * instance of Schema is used in another schema
0215: * (redefine, include or import)
0216: */
0217: private Schema _masterSchema = null;
0218:
0219: //----------------/
0220: //- Constructors -/
0221: //----------------/
0222:
0223: /**
0224: * Creates a new Schema definition
0225: */
0226: public Schema() {
0227: this (null, DEFAULT_SCHEMA_NS);
0228: } //-- Schema
0229:
0230: /**
0231: * Creates a new Schema definition
0232: *
0233: * @param schemaNS the namespace of the XML Schema itself. Note
0234: * this is not the same as the targetNamespace.
0235: */
0236: public Schema(String schemaNS) {
0237: this (null, schemaNS);
0238: } //-- Schema
0239:
0240: /**
0241: * Creates a new Schema definition
0242: *
0243: * @param prefix the desired namespace prefix for the schemaNS.
0244: * @param schemaNS the namespace of the XML Schema itself. Note
0245: * this is not the same as the targetNamespace.
0246: */
0247: public Schema(String prefix, String schemaNS) {
0248: super ();
0249:
0250: _attributes = new Hashtable();
0251: _attributeGroups = new Hashtable();
0252: _complexTypes = new Hashtable();
0253: _simpleTypes = new Hashtable();
0254: _elements = new Hashtable();
0255: _groups = new Hashtable();
0256: _importedSchemas = new Hashtable();
0257: _includedSchemas = new Vector();
0258: _namespaces = new Namespaces();
0259: _redefineSchemas = new Hashtable();
0260: _cachedincludedSchemas = new Hashtable();
0261:
0262: _schemaNamespace = schemaNS;
0263: if (_schemaNamespace == null) {
0264: _schemaNamespace = DEFAULT_SCHEMA_NS;
0265: }
0266:
0267: //-- declare default namespace bindings
0268: if (prefix == null)
0269: prefix = "";
0270: addNamespace(prefix, _schemaNamespace);
0271:
0272: init();
0273: } //-- ScehamDef
0274:
0275: private void init() {
0276:
0277: } //-- init
0278:
0279: /**
0280: * Adds the given attribute definition to this Schema definition
0281: *
0282: * @param attribute the AttributeDecl to add
0283: * @exception SchemaException if an AttributeDecl
0284: * already exisits with the same name
0285: **/
0286: public void addAttribute(AttributeDecl attribute)
0287: throws SchemaException {
0288: if (attribute == null)
0289: return;
0290:
0291: String name = attribute.getName();
0292:
0293: if (attribute.getSchema() != this ) {
0294: String err = "invalid attempt to add an AttributeDecl which ";
0295: err += "belongs to a different Schema; " + name;
0296: throw new SchemaException(err);
0297: }
0298:
0299: if ((name == null) && (attribute.isReference())) {
0300: String err = "Error attempting to add a top-level AttributeDecl that "
0301: + "is a reference. Top-level attributes can only be attribute declarations: "
0302: + attribute.getName(false);
0303: throw new SchemaException(err);
0304: }
0305: //-- we check if the attribute is not already present in the schema
0306: //-- the attribute can be already added
0307: //-- the attribute can be part of a schema redefinition
0308: //-- the attribute can be part of a cached included schema
0309: Object obj = getAttribute(name);
0310:
0311: if (obj == attribute)
0312: return;
0313:
0314: if (obj != null) {
0315: String err = "Error attempting to add an AttributeDecl to this "
0316: + "Schema definition, an AttributeDecl already exists with "
0317: + "the given name: ";
0318: throw new SchemaException(err + name);
0319: }
0320:
0321: _attributes.put(name, attribute);
0322: //--set the parent
0323: attribute.setParent(this );
0324: } //-- addAttribute
0325:
0326: /**
0327: * Adds the given attribute group definition to this Schema
0328: * definition.
0329: *
0330: * @param attrGroup the AttributeGroupDecl to add
0331: * @exception SchemaException if an AttributeGroupDecl
0332: * already exisits with the same name
0333: **/
0334: public void addAttributeGroup(AttributeGroupDecl attrGroup)
0335: throws SchemaException {
0336: if (attrGroup == null)
0337: return;
0338:
0339: String name = attrGroup.getName();
0340:
0341: //-- handle namespace prefix, if necessary
0342: int idx = name.indexOf(':');
0343: if (idx >= 0) {
0344: String nsPrefix = name.substring(0, idx);
0345: name = name.substring(idx + 1);
0346: String ns = _namespaces.getNamespaceURI(nsPrefix);
0347: if (ns == null) {
0348: String err = "addAttributeGroup: ";
0349: err += "Namespace prefix not recognized '" + nsPrefix
0350: + "'";
0351: throw new IllegalArgumentException(err);
0352: }
0353: if (!ns.equals(_targetNamespace)) {
0354: String err = "AttributeGroup has different namespace "
0355: + "than this Schema definition.";
0356: throw new IllegalArgumentException(err);
0357: }
0358: }
0359:
0360: if (attrGroup.getSchema() != this ) {
0361: String err = "invalid attempt to add an AttributeGroup which ";
0362: err += "belongs to a different Schema; " + name;
0363: throw new SchemaException(err);
0364: }
0365:
0366: Object obj = getAttributeGroup(name);
0367:
0368: if (obj == attrGroup)
0369: return;
0370: boolean redefine = attrGroup.isRedefined();
0371:
0372: if (obj != null && !redefine) {
0373: String err = "Error attempting to add an AttributeGroup to this "
0374: + "Schema definition, an AttributeGroup already exists with "
0375: + "the given name: ";
0376: throw new SchemaException(err + name);
0377: }
0378:
0379: _attributeGroups.put(name, attrGroup);
0380:
0381: } //-- addAttributeGroup
0382:
0383: /**
0384: * Adds the given Complextype definition to this Schema defintion
0385: * @param complexType the Complextype to add to this Schema
0386: * @exception SchemaException if the Complextype does not have
0387: * a name or if another Complextype already exists with the same name
0388: **/
0389: public synchronized void addComplexType(ComplexType complexType)
0390: throws SchemaException {
0391:
0392: String name = complexType.getName();
0393:
0394: if (name == null) {
0395: String err = "a global ComplexType must contain a name.";
0396: throw new SchemaException(err);
0397: }
0398: if (complexType.getSchema() != this ) {
0399: String err = "invalid attempt to add an ComplexType which ";
0400: err += "belongs to a different Schema; type name: " + name;
0401: throw new SchemaException(err);
0402: }
0403: //-- we check if the complexType is not already present in the schema
0404: //-- the complexType can be already added
0405: //-- the complexType can be part of a schema redefinition
0406: //-- the complexType can be part of a cached included schema
0407: if (getComplexType(name) != null && !complexType.isRedefined()) {
0408: String err = "a ComplexType already exists with the given name: ";
0409: throw new SchemaException(err + name);
0410: }
0411: _complexTypes.put(name, complexType);
0412: complexType.setParent(this );
0413:
0414: } //-- addComplextype
0415:
0416: /**
0417: * Adds the given Element declaration to this Schema defintion
0418: * @param elementDecl the ElementDecl to add to this SchemaDef
0419: * @exception SchemaException when an ElementDecl already
0420: * exists with the same name as the given ElementDecl
0421: **/
0422: public void addElementDecl(ElementDecl elementDecl)
0423: throws SchemaException {
0424:
0425: String name = elementDecl.getName(true);
0426:
0427: if ((name == null) && (elementDecl.isReference())) {
0428: String err = "Error attempting to add a top-level Element that "
0429: + "is a reference. Top-level elements can only be element declarations: "
0430: + elementDecl.getName(false);
0431: throw new SchemaException(err);
0432: }
0433:
0434: if (name == null) {
0435: String err = "an element declaration must contain a name.";
0436: throw new SchemaException(err);
0437: }
0438: if (getElementDecl(name) != null) {
0439: String err = "an element declaration already exists with the given name: ";
0440: throw new SchemaException(err + name);
0441: }
0442:
0443: _elements.put(name, elementDecl);
0444: elementDecl.setParent(this );
0445:
0446: } //-- addElementDecl
0447:
0448: /**
0449: * Adds the given Group declaration to this Schema definition
0450: * @param group the Group to add to this SchemaDef
0451: * @exception SchemaException when an Group already
0452: * exists with the same name as the given Group
0453: **/
0454: public void addModelGroup(ModelGroup group) throws SchemaException {
0455:
0456: String name = group.getName();
0457:
0458: if (name == null) {
0459: String err = "a group declaration must contain a name.";
0460: throw new SchemaException(err);
0461: }
0462:
0463: if (getModelGroup(name) != null && !group.isRedefined()) {
0464: String err = "a group declaration already exists with the given name: ";
0465: throw new SchemaException(err + name);
0466: }
0467:
0468: _groups.put(name, group);
0469: group.setParent(this );
0470: } //-- addModelGroup
0471:
0472: /**
0473: * Adds the given redefinition of structures to this Schema definition.
0474: * This structure is mainly used to allow the writing of an XML schema that
0475: * contains redefinitions. The validation process is permissive since the method
0476: * won't check that the XML Schema is already imported nor will it check that the
0477: * redefined structures exist.
0478: *
0479: * @param schema the Group to add to this SchemaDef
0480: * @exception SchemaException when an redefintion already
0481: * exists with the same name as the given ElementDecl
0482: **/
0483: public void addRedefineSchema(RedefineSchema schema)
0484: throws SchemaException {
0485:
0486: String uri = schema.getSchemaLocation();
0487:
0488: if ((uri == null) && (schema.hasRedefinition())) {
0489: String err = "A <redefine> structure with no 'schemaLocation' attribute must contain only <annotation> elements";
0490: throw new SchemaException(err);
0491: }
0492: if (_redefineSchemas.get(uri) != null) {
0493: String err = "The redefinition for schema:" + uri
0494: + " can only be used once.";
0495: throw new SchemaException(err);
0496: }
0497:
0498: _redefineSchemas.put(uri, schema);
0499: } //-- addModelGroup
0500:
0501: /**
0502: * Adds the given Schema definition to this Schema definition as an imported schenma
0503: * @param schema the Schema to add to this Schema as an imported schema
0504: * @exception SchemaException if the Schema already exists
0505: */
0506: public synchronized void addImportedSchema(Schema schema)
0507: throws SchemaException {
0508: String targetNamespace = schema.getTargetNamespace();
0509: if (targetNamespace == null)
0510: targetNamespace = "";
0511: if (_importedSchemas.get(targetNamespace) != null) {
0512: String err = "a Schema has already been imported with the given namespace: ";
0513: throw new SchemaException(err + targetNamespace);
0514: }
0515: _importedSchemas.put(targetNamespace, schema);
0516: } //-- addImportedSchema
0517:
0518: /**
0519: * Caches the given Schema definition as an included XML Schema of this
0520: * Schema definition.
0521: *
0522: * @param schema the Schema to add to this Schema as a cached included schema.
0523: * @exception SchemaException if the Schema already exists
0524: */
0525: public synchronized void cacheIncludedSchema(Schema schema)
0526: throws SchemaException {
0527: String schemaLocation = schema.getSchemaLocation();
0528: if (schemaLocation == null)
0529: schemaLocation = "";
0530: if (_cachedincludedSchemas.get(schemaLocation) != null) {
0531: String err = "a Schema has already been included with the given schemaLocation: ";
0532: throw new SchemaException(err + schemaLocation);
0533: }
0534: _cachedincludedSchemas.put(schemaLocation, schema);
0535: } //-- addImportedSchema
0536:
0537: /**
0538: * Adds to the namespaces declared in this Schema
0539: */
0540: public void addNamespace(String prefix, String ns) {
0541: _namespaces.addNamespace(prefix, ns);
0542: } //-- setNamespaces
0543:
0544: /**
0545: * Adds the given SimpletType definition to this Schema defintion
0546: * @param simpleType the SimpleType to add to this Schema
0547: * @exception SchemaException if the SimpleType does not have
0548: * a name or if another SimpleType already exists with the same name
0549: **/
0550: public synchronized void addSimpleType(SimpleType simpleType)
0551: throws SchemaException {
0552:
0553: String name = simpleType.getName();
0554:
0555: if ((name == null) || (name.length() == 0)) {
0556: String err = "No name found for top-level SimpleType. "
0557: + " A top-level SimpleType must have a name.";
0558: throw new SchemaException(err);
0559: }
0560:
0561: if (simpleType.getSchema() != this ) {
0562: String err = "invalid attempt to add a SimpleType which ";
0563: err += "belongs to a different Schema; type name: " + name;
0564: throw new SchemaException(err);
0565: }
0566: if (getSimpleType(name, _targetNamespace) != null
0567: && !simpleType.isRedefined()) {
0568: String err = "a SimpleType already exists with the given name: ";
0569: throw new SchemaException(err + name);
0570: }
0571: simpleType.setParent(this );
0572: _simpleTypes.put(name, simpleType);
0573:
0574: } //-- addSimpleType
0575:
0576: /**
0577: * Creates a new ComplexType using this Schema as the owning Schema
0578: * document. A call to #addComplexType must still be made in order
0579: * to add the complexType to this Schema.
0580: * @return the new ComplexType
0581: **/
0582: public ComplexType createComplexType() {
0583: return new ComplexType(this );
0584: } //-- createComplexType
0585:
0586: /**
0587: * Creates a new ComplexType using this Schema as the owning Schema
0588: * document. A call to #addComplexType must still be made in order
0589: * to add the complexType to this Schema.
0590: * @param name the name of the ComplexType
0591: * @return the new ComplexType
0592: **/
0593: public ComplexType createComplexType(String name) {
0594: return new ComplexType(this , name);
0595: } //-- createComplexType
0596:
0597: /**
0598: * Creates a new SimpleType using this Schema as the owning Schema
0599: * document. A call to #addSimpleType must till be made in order
0600: * to add the SimpleType to this Schema.
0601: * @param name the name of the SimpleType
0602: * @param baseName the name of the SimpleType's base type
0603: * @param derivation the name of the derivation method (""/"list"/"restriction")
0604: * @return the new SimpleType.
0605: **/
0606: public SimpleType createSimpleType(String name, String baseName,
0607: String derivation) {
0608: return simpleTypesFactory.createUserSimpleType(this , name,
0609: baseName, derivation, true);
0610: } //-- createSimpleType
0611:
0612: /**
0613: * Creates a new SimpleType using this Schema as the owning Schema
0614: * document. A call to #addSimpleType must till be made in order
0615: * to add the SimpleType to this Schema if the type is to be global.
0616: * @param name the name of the SimpleType
0617: * @param baseType the base type of the SimpleType to create
0618: * @return the new SimpleType.
0619: **/
0620: public SimpleType createSimpleType(String name, SimpleType baseType) {
0621: return simpleTypesFactory.createUserSimpleType(this , name,
0622: baseType, "restriction");
0623: } //-- createSimpleType
0624:
0625: /**
0626: * Returns the attributeFormDefault property of this Schema.
0627: *
0628: * @return the attributeFormDefault property of this Schema, or null
0629: * if no default Form was set. If no default Form has been set, the
0630: * user should assume Form.Unqualified.
0631: **/
0632: public Form getAttributeFormDefault() {
0633: return _attributeFormDefault;
0634: } //-- getAttributeFormDefault
0635:
0636: /**
0637: * Returns an Enumeration of all top-level Attribute declarations
0638: * @return an Enumeration of all top-level Attribute declarations
0639: **/
0640: public Enumeration getAttributes() {
0641: Vector result = new Vector(_attributes.size() * 2);
0642: Enumeration tempAtt = _attributes.elements();
0643: while (tempAtt.hasMoreElements()) {
0644: result.add(tempAtt.nextElement());
0645: }
0646:
0647: Enumeration cachedincluded = _cachedincludedSchemas.elements();
0648: while (cachedincluded.hasMoreElements()) {
0649: Schema tempSchema = (Schema) cachedincluded.nextElement();
0650: tempAtt = tempSchema.getAttributes();
0651: while (tempAtt.hasMoreElements()) {
0652: result.add(tempAtt.nextElement());
0653: }
0654: }
0655:
0656: Enumeration redefinition = _redefineSchemas.elements();
0657: while (redefinition.hasMoreElements()) {
0658: Schema tempSchema = ((RedefineSchema) redefinition
0659: .nextElement()).getOriginalSchema();
0660: //-- a redefinition doesn't always contain a schema
0661: if (tempSchema != null) {
0662: //-- Sets the master schema
0663: //-- The master schema will help resolving the links at runtime between
0664: //-- an structure and its type.
0665: tempSchema.setMasterSchema(this );
0666: tempAtt = tempSchema.getAttributes();
0667: while (tempAtt.hasMoreElements()) {
0668: result.add(tempAtt.nextElement());
0669: }
0670: }
0671: }
0672:
0673: return result.elements();
0674: } //-- getAttributes
0675:
0676: /**
0677: * Returns the top-level Attribute associated with the given name.
0678: *
0679: * @return the Attribute associated with the given name,
0680: * or null if no Attribute association is found.
0681: **/
0682: public AttributeDecl getAttribute(String name) {
0683:
0684: //-- Null?
0685: if (name == null) {
0686: String err = NULL_ARGUMENT + "getAttribute: ";
0687: err += "'name' cannot be null.";
0688: throw new IllegalArgumentException(err);
0689: }
0690:
0691: //-- Namespace prefix?
0692: String canonicalName = name;
0693: String nsprefix = "";
0694: String ns = _targetNamespace;
0695: int colon = name.indexOf(':');
0696: if (colon != -1) {
0697: canonicalName = name.substring(colon + 1);
0698: nsprefix = name.substring(0, colon);
0699: ns = _namespaces.getNamespaceURI(nsprefix);
0700: if (ns == null) {
0701: String err = "getAttribute: ";
0702: err += "Namespace prefix not recognized '" + name + "'";
0703: throw new IllegalArgumentException(err);
0704: }
0705: }
0706:
0707: if ((ns == null) || (ns.equals(_targetNamespace))) {
0708: AttributeDecl tempAtt = (AttributeDecl) _attributes
0709: .get(canonicalName);
0710: if (tempAtt == null) {
0711: Enumeration cacheIncluded = _cachedincludedSchemas
0712: .elements();
0713: boolean found = false;
0714: while (cacheIncluded.hasMoreElements() && !found) {
0715: Schema temp = (Schema) cacheIncluded.nextElement();
0716: tempAtt = temp.getAttribute(canonicalName);
0717: if (tempAtt != null)
0718: found = true;
0719: }
0720:
0721: //--look in the redefinition
0722: if (!found) {
0723: Enumeration redefinition = _redefineSchemas
0724: .elements();
0725: while (redefinition.hasMoreElements() && !found) {
0726: redefinition.nextElement();
0727: Schema tempSchema = ((RedefineSchema) redefinition
0728: .nextElement()).getOriginalSchema();
0729: if (tempSchema != null) {
0730: //-- Sets the master schema
0731: //-- The master schema will help resolving the links at runtime between
0732: //-- an structure and its type.
0733: tempSchema.setMasterSchema(this );
0734: tempAtt = tempSchema
0735: .getAttribute(canonicalName);
0736: if (tempAtt != null)
0737: found = true;
0738: }
0739: }
0740: }
0741: }
0742: return tempAtt;
0743: }
0744: Schema schema = getImportedSchema(ns);
0745: if (schema != null) {
0746: AttributeDecl att = schema.getAttribute(canonicalName);
0747: return att;
0748: }
0749:
0750: return null;
0751:
0752: } //-- getAttribute
0753:
0754: /**
0755: * Returns an Enumeration of all top-level AttributeGroup declarations
0756: * @return an Enumeration of all top-level AttributeGroup declarations
0757: **/
0758: public Enumeration getAttributeGroups() {
0759: Vector result = new Vector(_attributeGroups.size() * 2);
0760: Enumeration tempAtt = _attributeGroups.elements();
0761: while (tempAtt.hasMoreElements()) {
0762: result.add(tempAtt.nextElement());
0763: }
0764:
0765: Enumeration cachedincluded = _cachedincludedSchemas.elements();
0766: while (cachedincluded.hasMoreElements()) {
0767: Schema tempSchema = (Schema) cachedincluded.nextElement();
0768: tempAtt = tempSchema.getAttributeGroups();
0769: while (tempAtt.hasMoreElements()) {
0770: result.add(tempAtt.nextElement());
0771: }
0772: }
0773:
0774: Enumeration redefinition = _redefineSchemas.elements();
0775: while (redefinition.hasMoreElements()) {
0776: RedefineSchema redefine = (RedefineSchema) redefinition
0777: .nextElement();
0778: //1-- Add the AttributeGroups from the RedefineSchema
0779: tempAtt = redefine.enumerateAttributeGroups();
0780: while (tempAtt.hasMoreElements()) {
0781: AttributeGroupDecl tempGroup = (AttributeGroupDecl) tempAtt
0782: .nextElement();
0783: result.add(tempGroup);
0784: }
0785:
0786: //2-- Add the AttributeGroups from the Original Schema of the
0787: //-- RedefineSchema Structure by making sure that the AttributeGroups
0788: //-- are not redefined.
0789: Schema tempSchema = redefine.getOriginalSchema();
0790: //-- a redefinition doesn't always contain a schema
0791: if (tempSchema != null) {
0792: //-- Sets the master schema
0793: //-- The master schema will help resolving the links at runtime between
0794: //-- a structure and its type.
0795: tempSchema.setMasterSchema(this );
0796: tempAtt = tempSchema.getAttributeGroups();
0797: while (tempAtt.hasMoreElements()) {
0798: AttributeGroup tempGroup = (AttributeGroup) tempAtt
0799: .nextElement();
0800: boolean alreadyRedefined = true;
0801: if (tempGroup instanceof AttributeGroupDecl)
0802: alreadyRedefined = redefine
0803: .hasAttributeGroupRedefinition(((AttributeGroupDecl) tempGroup)
0804: .getName());
0805: if (!alreadyRedefined)
0806: result.add(tempGroup);
0807: }
0808: }
0809: }
0810:
0811: return result.elements();
0812: } //-- getAttributeGroups
0813:
0814: /**
0815: * Returns the AttributeGroup associated with the given name.
0816: *
0817: * @return the AttributeGroup associated with the given name,
0818: * or null if no AttributeGroup association is found.
0819: **/
0820: public AttributeGroup getAttributeGroup(String name) {
0821:
0822: //-- Null?
0823: if (name == null) {
0824: String err = NULL_ARGUMENT + "getAttributeGroup: ";
0825: err += "'name' cannot be null.";
0826: throw new IllegalArgumentException(err);
0827: }
0828:
0829: AttributeGroup result = null;
0830: //-- Namespace prefix?
0831: String canonicalName = name;
0832: String nsprefix = "";
0833: String ns = _targetNamespace;
0834: int colon = name.indexOf(':');
0835: if (colon != -1) {
0836: canonicalName = name.substring(colon + 1);
0837: nsprefix = name.substring(0, colon);
0838: ns = _namespaces.getNamespaceURI(nsprefix);
0839: if (ns == null) {
0840: String err = "getAttributeGroup: ";
0841: err += "Namespace prefix not recognized '" + name + "'";
0842: throw new IllegalArgumentException(err);
0843: }
0844: }
0845:
0846: if ((ns == null) || (ns.equals(_targetNamespace))) {
0847: result = (AttributeGroup) _attributeGroups
0848: .get(canonicalName);
0849:
0850: if (result == null) {
0851: Enumeration cacheIncluded = _cachedincludedSchemas
0852: .elements();
0853: boolean found = false;
0854: while (cacheIncluded.hasMoreElements() && !found) {
0855: Schema temp = (Schema) cacheIncluded.nextElement();
0856: result = temp.getAttributeGroup(canonicalName);
0857: if (result != null)
0858: found = true;
0859: }
0860:
0861: //--we look in the redefinitions
0862: if (!found) {
0863: //-- Search through the redefinition:
0864: Enumeration redefinitions = getRedefineSchema();
0865: while (redefinitions.hasMoreElements() && !found) {
0866: RedefineSchema redefine = (RedefineSchema) redefinitions
0867: .nextElement();
0868:
0869: //-- the AttributeGroup can be redefined
0870: if (redefine
0871: .hasAttributeGroupRedefinition(canonicalName)) {
0872: result = redefine
0873: .getAttributeGroup(canonicalName);
0874: if (result != null)
0875: found = true;
0876: break;
0877: }
0878:
0879: //-- or if can be part of the Original Schema of the Redefined structures.
0880: Schema schema = redefine.getOriginalSchema();
0881: if (schema != null) {
0882: //-- Sets the master schema
0883: //-- The master schema will help resolving the links at runtime between
0884: //-- an structure and its type.
0885: schema.setMasterSchema(this );
0886: result = schema.getAttributeGroup(name);
0887: }
0888: }
0889: }//--end of redefinition
0890: }//--result == null
0891: } else {
0892: Schema schema = getImportedSchema(ns);
0893: if (schema != null)
0894: result = schema.getAttributeGroup(canonicalName);
0895: }
0896:
0897: return result;
0898:
0899: } //-- getAttributeGroup
0900:
0901: /**
0902: * Returns the default BlockList for this Schema.
0903: *
0904: * @return the default BlockList for this Schema.
0905: **/
0906: public BlockList getBlockDefault() {
0907: return _block;
0908: } //-- getBlockDefault
0909:
0910: /**
0911: * Gets a built in type's name given its code.
0912: */
0913: public String getBuiltInTypeName(int builtInTypeCode) {
0914: return simpleTypesFactory.getBuiltInTypeName(builtInTypeCode);
0915: } //-- getBuiltInTypeName
0916:
0917: /**
0918: * Returns the ComplexType of associated with the given name
0919: * @return the ComplexType of associated with the given name, or
0920: * null if no ComplexType with the given name was found.
0921: **/
0922: public ComplexType getComplexType(String name) {
0923:
0924: //-- Null?
0925: if (name == null) {
0926: String err = NULL_ARGUMENT + "getComplexType: ";
0927: err += "'name' cannot be null.";
0928: throw new IllegalArgumentException(err);
0929: }
0930: ComplexType result = null;
0931: //-- Namespace prefix?
0932: String canonicalName = name;
0933: String nsprefix = "";
0934: String ns = _targetNamespace;
0935: int colon = name.indexOf(':');
0936: if (colon != -1) {
0937: canonicalName = name.substring(colon + 1);
0938: nsprefix = name.substring(0, colon);
0939: ns = _namespaces.getNamespaceURI(nsprefix);
0940: if (ns == null) {
0941: String err = "getComplexType: ";
0942: err += "Namespace prefix not recognized '" + name + "'";
0943: throw new IllegalArgumentException(err);
0944: }
0945: }
0946:
0947: //-- Get GetComplexType object
0948: if ((ns == null) || (ns.equals(_targetNamespace))) {
0949: result = (ComplexType) _complexTypes.get(canonicalName);
0950: if (result == null) {
0951: boolean found = false;
0952: //-- check for any included schemas that are cached
0953: Enumeration cacheIncluded = _cachedincludedSchemas
0954: .elements();
0955: while (cacheIncluded.hasMoreElements() && !found) {
0956: Schema temp = (Schema) cacheIncluded.nextElement();
0957: result = temp.getComplexType(canonicalName);
0958: if (result != null)
0959: found = true;
0960: }
0961: if (!found) {
0962: //--we might face a redefinition
0963: Enumeration redefinitions = getRedefineSchema();
0964: while (redefinitions.hasMoreElements()
0965: && result == null) {
0966: RedefineSchema redefine = (RedefineSchema) redefinitions
0967: .nextElement();
0968: //-- the ComplexType can be redefined
0969: if (redefine
0970: .hasComplexTypeRedefinition(canonicalName)) {
0971: result = redefine
0972: .getComplexType(canonicalName);
0973:
0974: if (result != null)
0975: found = true;
0976: break;
0977: }
0978:
0979: Schema schema = redefine.getOriginalSchema();
0980: if (schema != null) {
0981: //-- Sets the master schema
0982: //-- The master schema will help resolving the links at runtime between
0983: //-- an structure and its type.
0984: schema.setMasterSchema(this );
0985: result = schema
0986: .getComplexType(canonicalName);
0987: }
0988: }
0989: }
0990:
0991: }
0992: } else {
0993: Schema schema = getImportedSchema(ns);
0994: if (schema != null) {
0995: result = schema.getComplexType(canonicalName);
0996: }
0997: }
0998:
0999: return result;
1000:
1001: } //-- getComplexType
1002:
1003: /**
1004: * Returns an Enumeration of all top-level ComplexType declarations
1005: * @return an Enumeration of all top-level ComplexType declarations
1006: **/
1007: public Enumeration getComplexTypes() {
1008: Vector result = new Vector(_complexTypes.size() * 2);
1009: Enumeration tempEnum = _complexTypes.elements();
1010: while (tempEnum.hasMoreElements()) {
1011: result.add(tempEnum.nextElement());
1012: }
1013:
1014: Enumeration cachedincluded = _cachedincludedSchemas.elements();
1015: while (cachedincluded.hasMoreElements()) {
1016: Schema tempSchema = (Schema) cachedincluded.nextElement();
1017: tempEnum = tempSchema.getComplexTypes();
1018: while (tempEnum.hasMoreElements()) {
1019: result.add(tempEnum.nextElement());
1020: }
1021: }
1022:
1023: Enumeration redefinition = _redefineSchemas.elements();
1024: while (redefinition.hasMoreElements()) {
1025: RedefineSchema redefine = (RedefineSchema) redefinition
1026: .nextElement();
1027: //1-- Add the ComplexType from the RedefineSchema
1028: tempEnum = redefine.enumerateComplexTypes();
1029: while (tempEnum.hasMoreElements()) {
1030: result.add(tempEnum.nextElement());
1031: }
1032:
1033: Schema tempSchema = redefine.getOriginalSchema();
1034: //-- a redefinition doesn't always contain a schema
1035: if (tempSchema != null) {
1036: //-- Sets the master schema
1037: //-- The master schema will help resolving the links at runtime between
1038: //-- an structure and its type.
1039: tempSchema.setMasterSchema(this );
1040: tempEnum = tempSchema.getComplexTypes();
1041: while (tempEnum.hasMoreElements()) {
1042: ComplexType tempType = (ComplexType) tempEnum
1043: .nextElement();
1044: if (!redefine.hasComplexTypeRedefinition(tempType
1045: .getName()))
1046: result.add(tempType);
1047: }
1048: }
1049: }
1050:
1051: return result.elements();
1052:
1053: } //-- getComplextypes
1054:
1055: /**
1056: * Returns the ElementDecl of associated with the given name
1057: * @return the ElementDecl of associated with the given name, or
1058: * null if no ElementDecl with the given name was found.
1059: **/
1060: public ElementDecl getElementDecl(String name) {
1061:
1062: String ns = null;
1063: if (name == null) {
1064: String err = NULL_ARGUMENT + "getElementDecl: ";
1065: err += " 'name' can not be null";
1066: throw new IllegalArgumentException(err);
1067: }
1068: ElementDecl result = null;
1069: int idx = name.indexOf(':');
1070: if (idx >= 0) {
1071: String nsPrefix = name.substring(0, idx);
1072: name = name.substring(idx + 1);
1073: ns = _namespaces.getNamespaceURI(nsPrefix);
1074: if (ns == null) {
1075: String err = "getElementDecl: ";
1076: err += "Namespace prefix not recognized '" + nsPrefix
1077: + "'";
1078: throw new IllegalArgumentException(err);
1079: }
1080: }
1081:
1082: if ((ns == null) || (ns.equals(_targetNamespace))) {
1083: result = (ElementDecl) _elements.get(name);
1084: if (result == null) {
1085: //-- check for any included schemas that are cached
1086: Enumeration cacheIncluded = _cachedincludedSchemas
1087: .elements();
1088: boolean found = false;
1089: while (cacheIncluded.hasMoreElements() && !found) {
1090: Schema temp = (Schema) cacheIncluded.nextElement();
1091: result = temp.getElementDecl(name);
1092: if (result != null)
1093: found = true;
1094: }
1095: //--look in the redefinition
1096: if (!found) {
1097: Enumeration redefinition = _redefineSchemas
1098: .elements();
1099: while (redefinition.hasMoreElements() && !found) {
1100: Schema schema = ((RedefineSchema) redefinition
1101: .nextElement()).getOriginalSchema();
1102: if (schema != null) {
1103: //-- Sets the master schema
1104: //-- The master schema will help resolving the links at runtime between
1105: //-- an structure and its type.
1106: schema.setMasterSchema(this );
1107: result = schema.getElementDecl(name);
1108: if (result != null)
1109: found = true;
1110: }
1111: }
1112: }
1113: }
1114: } else {
1115: Schema schema = getImportedSchema(ns);
1116: if (schema != null) {
1117: result = schema.getElementDecl(name);
1118: }
1119: }
1120:
1121: return result;
1122: } //--getElementDecl
1123:
1124: /**
1125: * Returns an Enumeration of all top-level element declarations
1126: * @return an Enumeration of all top-level element declarations
1127: **/
1128: public Enumeration getElementDecls() {
1129: Vector result = new Vector(_elements.size() * 2);
1130: Enumeration tempEnum = _elements.elements();
1131: while (tempEnum.hasMoreElements()) {
1132: result.add(tempEnum.nextElement());
1133: }
1134:
1135: Enumeration cachedincluded = _cachedincludedSchemas.elements();
1136: while (cachedincluded.hasMoreElements()) {
1137: Schema tempSchema = (Schema) cachedincluded.nextElement();
1138: tempEnum = tempSchema.getElementDecls();
1139: while (tempEnum.hasMoreElements()) {
1140: result.add(tempEnum.nextElement());
1141: }
1142: }
1143:
1144: Enumeration redefinition = _redefineSchemas.elements();
1145: while (redefinition.hasMoreElements()) {
1146: RedefineSchema redefine = (RedefineSchema) redefinition
1147: .nextElement();
1148: Schema tempSchema = redefine.getOriginalSchema();
1149: //-- a redefinition doesn't always contain a schema
1150: if (tempSchema != null) {
1151: //-- Sets the master schema
1152: //-- The master schema will help resolving the links at runtime between
1153: //-- an structure and its type.
1154: tempSchema.setMasterSchema(this );
1155: tempEnum = tempSchema.getElementDecls();
1156: while (tempEnum.hasMoreElements()) {
1157: result.add(tempEnum.nextElement());
1158: }
1159: }
1160: }
1161:
1162: return result.elements();
1163: } //-- getElementDecls
1164:
1165: /**
1166: * Returns the elementFormDefault property of this Schema.
1167: *
1168: * @return the elementFormDefault property of this Schema, or null
1169: * if no default Form was set. If no default Form has been set, the
1170: * user should assume Form.Unqualified.
1171: **/
1172: public Form getElementFormDefault() {
1173: return _elementFormDefault;
1174: } //-- getElementFormDefault
1175:
1176: /**
1177: * Returns the default FinalList for this Schema.
1178: *
1179: * @return final the default FinalList for this Schema.
1180: **/
1181: public FinalList getFinalDefault() {
1182: return _final;
1183: } //-- getFinalDefault
1184:
1185: /**
1186: * Returns the SimpleType associated with the given name,
1187: * or null if no such SimpleType exists.
1188: *
1189: * @param name the name of the SimpleType. The name may
1190: * be a QName (contain a namespace prefix).
1191: * @return the SimpleType associated with the given name,
1192: * or null if no such SimpleType exists.
1193: **/
1194: public SimpleType getSimpleType(String name) {
1195:
1196: //-- name must not be null
1197: if (name == null) {
1198: String err = NULL_ARGUMENT + "getSimpleType: ";
1199: err += "'name' cannot be null.";
1200: throw new IllegalArgumentException(err);
1201: }
1202:
1203: //-- Handle namespace resolution?
1204: String nsPrefix = "";
1205: String ns = null;
1206: int colon = name.indexOf(':');
1207: if (colon >= 0) {
1208: nsPrefix = name.substring(0, colon);
1209: name = name.substring(colon + 1);
1210: ns = _namespaces.getNamespaceURI(nsPrefix);
1211: if (ns == null) {
1212: String err = "getSimpleType: ";
1213: err += "Namespace prefix not recognised '" + nsPrefix
1214: + "'";
1215: err += "for simpleType:" + name;
1216: throw new IllegalArgumentException(err);
1217: }
1218: } else {
1219: ns = _namespaces.getNamespaceURI(nsPrefix);
1220: }
1221:
1222: //--if at this point, there is no namespace
1223: //--then we assume it is the targetNamespace
1224: if (ns == null)
1225: ns = _targetNamespace;
1226:
1227: return getSimpleType(name, ns);
1228:
1229: } //-- getSimpleType
1230:
1231: /**
1232: * Returns the SimpleType associated with the given name
1233: * and namespace, or null if no such SimpleType exists.
1234: *
1235: * @param name the name of the simpleType. It is an error
1236: * if this name contains a prefix, it must be an NCName.
1237: * @param namespace the namespace URI of the simpleType.
1238: * @return the SimpleType, or null if no such SimpleType exists.
1239: **/
1240: public SimpleType getSimpleType(String name, String namespace) {
1241:
1242: //-- name must not be null
1243: if (name == null) {
1244: String err = NULL_ARGUMENT + "getSimpleType: ";
1245: err += "'name' cannot be null.";
1246: throw new IllegalArgumentException(err);
1247: }
1248:
1249: //--Is the declaration in the default namespace (if any)
1250: boolean isDefaultNS = false;
1251: if (namespace == null) {
1252: namespace = _namespaces.getNamespaceURI("");
1253: isDefaultNS = true;
1254: }
1255:
1256: //-- Get SimpleType object
1257: SimpleType result = null;
1258: if ((namespace == null) || (isDefaultNS)) {
1259:
1260: //-- first check user-defined types
1261: result = (SimpleType) _simpleTypes.get(name);
1262: if (result != null) {
1263: //-- resolve deferred type if necessary
1264: if (result.getType() != result) {
1265: //-- can result.getType ever return null?
1266: //-- We can check, just in case.
1267: if (result.getType() != null) {
1268: result = (SimpleType) result.getType();
1269: result.setParent(this );
1270: _simpleTypes.put(name, result);
1271: }
1272: }
1273: }
1274: //-- otherwise try built-in types
1275: else {
1276: result = simpleTypesFactory.getBuiltInType(name);
1277: //if we have a built-in type not declared in the good namespace -> Exception
1278: if ((result != null)
1279: && (!_schemaNamespace.equals(namespace))) {
1280: String err = "getSimpleType: the simple type '"
1281: + name
1282: + "' has not been declared in XML Schema namespace.";
1283: throw new IllegalArgumentException(err);
1284: }
1285: }
1286: } else if (namespace.equals(_schemaNamespace)) {
1287: result = simpleTypesFactory.getBuiltInType(name);
1288: if (result == null) {
1289: String err = "getSimpleType: the simple type '"
1290: + name
1291: + "' is not a built-in type as defined in XML Schema specification.";
1292: throw new IllegalArgumentException(err);
1293: }
1294: } else if (namespace.equals(_targetNamespace)) {
1295: result = (SimpleType) _simpleTypes.get(name);
1296: if (result != null) {
1297: //-- resolve deferred type if necessary
1298: if (result.getType() != result) {
1299: //-- can result.getType ever return null?
1300: //-- We can check, just in case.
1301: if (result.getType() != null) {
1302: result = (SimpleType) result.getType();
1303: result.setParent(this );
1304: _simpleTypes.put(name, result);
1305: }
1306: }
1307: }
1308: if (result == null) {
1309: //-- check the cached included schema
1310: Enumeration cacheIncluded = _cachedincludedSchemas
1311: .elements();
1312: boolean found = false;
1313: while (cacheIncluded.hasMoreElements() && !found) {
1314: Schema temp = (Schema) cacheIncluded.nextElement();
1315: result = temp.getSimpleType(name, namespace);
1316: if (result != null)
1317: found = true;
1318: }
1319: if (!found) {
1320: //--we might face a redefinition
1321: Enumeration redefinitions = getRedefineSchema();
1322: while (redefinitions.hasMoreElements()
1323: && result == null) {
1324: RedefineSchema redefine = (RedefineSchema) redefinitions
1325: .nextElement();
1326: //-- the SimpleType can be redefined
1327: if (redefine.hasSimpleTypeRedefinition(name)) {
1328: result = redefine.getSimpleType(name);
1329: if (result != null)
1330: found = true;
1331: break;
1332: }
1333:
1334: Schema schema = redefine.getOriginalSchema();
1335: if (schema != null) {
1336: //-- Sets the master schema
1337: //-- The master schema will help resolving the links at runtime between
1338: //-- an structure and its type.
1339: schema.setMasterSchema(this );
1340: result = schema.getSimpleType(name,
1341: namespace);
1342: }
1343: }
1344: }
1345: }
1346: } else {
1347: Schema schema = getImportedSchema(namespace);
1348: if (schema != null) {
1349: result = schema.getSimpleType(name, namespace);
1350: }
1351: }
1352:
1353: //-- Result could be a deferredSimpleType => getType will resolve it
1354: if (result != null)
1355: result = (SimpleType) result.getType();
1356:
1357: return result;
1358: } //-- getSimpleType
1359:
1360: /**
1361: * Returns an Enumeration of all SimpleType declarations
1362: * @return an Enumeration of all SimpleType declarations
1363: **/
1364: public Enumeration getSimpleTypes() {
1365:
1366: //-- clean up "deferred types" if necessary
1367: Enumeration enumeration = _simpleTypes.elements();
1368: while (enumeration.hasMoreElements()) {
1369: SimpleType type = (SimpleType) enumeration.nextElement();
1370: if (type != type.getType()) {
1371: //-- resolve deferred type if necessary
1372: if (type.getType() != null) {
1373: String name = type.getName();
1374: type = (SimpleType) type.getType();
1375: type.setParent(this );
1376: _simpleTypes.put(name, type);
1377: }
1378: }
1379: }
1380: Vector result = new Vector(_simpleTypes.size() * 2);
1381: Enumeration tempEnum = _simpleTypes.elements();
1382: while (tempEnum.hasMoreElements()) {
1383: result.add(tempEnum.nextElement());
1384: }
1385:
1386: Enumeration cachedincluded = _cachedincludedSchemas.elements();
1387: while (cachedincluded.hasMoreElements()) {
1388: Schema tempSchema = (Schema) cachedincluded.nextElement();
1389: tempEnum = tempSchema.getSimpleTypes();
1390: while (tempEnum.hasMoreElements()) {
1391: result.add(tempEnum.nextElement());
1392: }
1393: }
1394:
1395: Enumeration redefinition = _redefineSchemas.elements();
1396: while (redefinition.hasMoreElements()) {
1397: RedefineSchema redefine = (RedefineSchema) redefinition
1398: .nextElement();
1399: //1-- Add the SimpleType from the RedefineSchema
1400: tempEnum = redefine.enumerateSimpleTypes();
1401: while (tempEnum.hasMoreElements()) {
1402: result.add(tempEnum.nextElement());
1403: }
1404:
1405: Schema tempSchema = redefine.getOriginalSchema();
1406: //-- a redefinition doesn't always contain a schema
1407: if (tempSchema != null) {
1408: //-- Sets the master schema
1409: //-- The master schema will help resolving the links at runtime between
1410: //-- an structure and its type.
1411: tempSchema.setMasterSchema(this );
1412: tempEnum = tempSchema.getSimpleTypes();
1413: while (tempEnum.hasMoreElements()) {
1414: SimpleType tempType = (SimpleType) tempEnum
1415: .nextElement();
1416: if (!redefine.hasSimpleTypeRedefinition(tempType
1417: .getName()))
1418: result.add(tempType);
1419: }
1420: }
1421: }
1422:
1423: return result.elements();
1424: } //-- getSimpleTypes
1425:
1426: /**
1427: * Returns the schemaLocation hint provided of this schema
1428: * @return the schemaLocation hint provided of this schema
1429: */
1430: public String getSchemaLocation() {
1431: return _schemaLocation;
1432: }
1433:
1434: /**
1435: * Returns the ModeGroup of associated with the given name
1436: * @return the ModelGroup of associated with the given name, or
1437: * null if no ModelGroup with the given name was found.
1438: **/
1439: public ModelGroup getModelGroup(String name) {
1440:
1441: String ns = null;
1442: if (name == null) {
1443: String err = NULL_ARGUMENT + "getModelGroup: ";
1444: err += " 'name' can not be null";
1445: throw new IllegalArgumentException(err);
1446: }
1447: ModelGroup result = null;
1448: int idx = name.indexOf(':');
1449: if (idx >= 0) {
1450: String nsPrefix = name.substring(0, idx);
1451: name = name.substring(idx + 1);
1452: ns = _namespaces.getNamespaceURI(nsPrefix);
1453: if (ns == null) {
1454: String err = "getModelGroup: ";
1455: err += "Namespace prefix not recognized '" + nsPrefix
1456: + "'";
1457: throw new IllegalArgumentException(err);
1458: }
1459: }
1460:
1461: if ((ns == null) || (ns.equals(_targetNamespace))) {
1462: result = (ModelGroup) _groups.get(name);
1463: if (result == null) {
1464: //-- check for any included schemas that are cached
1465: Enumeration cacheIncluded = _cachedincludedSchemas
1466: .elements();
1467: boolean found = false;
1468: while (cacheIncluded.hasMoreElements() && !found) {
1469: Schema temp = (Schema) cacheIncluded.nextElement();
1470: result = temp.getModelGroup(name);
1471: if (result != null)
1472: found = true;
1473: }
1474:
1475: if (!found) {
1476: //--we might face a redefinition
1477: Enumeration redefinitions = getRedefineSchema();
1478: while (redefinitions.hasMoreElements()
1479: && result == null) {
1480: RedefineSchema redefine = (RedefineSchema) redefinitions
1481: .nextElement();
1482: //-- the ModelGroup can be redefined
1483: if (redefine.hasGroupRedefinition(name)) {
1484: result = redefine.getModelGroup(name);
1485: if (result != null)
1486: found = true;
1487: break;
1488: }
1489:
1490: Schema schema = redefine.getOriginalSchema();
1491: if (schema != null) {
1492: //-- Sets the master schema
1493: //-- The master schema will help resolving the links at runtime between
1494: //-- an structure and its type.
1495: schema.setMasterSchema(this );
1496: result = schema.getModelGroup(name);
1497: }
1498: }
1499: }
1500: }
1501: } else {
1502: Schema schema = getImportedSchema(ns);
1503: if (schema != null) {
1504: result = schema.getModelGroup(name);
1505: }
1506: }
1507:
1508: return result;
1509: } //--getModelGroup
1510:
1511: /**
1512: * Returns an Enumeration of all top-level ModelGroup declarations
1513: * @return an Enumeration of all top-level ModelGroup declarations
1514: **/
1515: public Enumeration getModelGroups() {
1516: Vector result = new Vector(_groups.size() * 2);
1517: Enumeration tempEnum = _groups.elements();
1518: while (tempEnum.hasMoreElements()) {
1519: result.add(tempEnum.nextElement());
1520: }
1521:
1522: Enumeration cachedincluded = _cachedincludedSchemas.elements();
1523: while (cachedincluded.hasMoreElements()) {
1524: Schema tempSchema = (Schema) cachedincluded.nextElement();
1525: tempEnum = tempSchema.getModelGroups();
1526: while (tempEnum.hasMoreElements()) {
1527: result.add(tempEnum.nextElement());
1528: }
1529: }
1530: Enumeration redefinition = _redefineSchemas.elements();
1531: while (redefinition.hasMoreElements()) {
1532: RedefineSchema redefine = (RedefineSchema) redefinition
1533: .nextElement();
1534: //1-- Add the AttributeGroups from the RedefineSchema
1535: tempEnum = redefine.enumerateGroups();
1536: while (tempEnum.hasMoreElements()) {
1537: result.add(tempEnum.nextElement());
1538: }
1539:
1540: Schema tempSchema = redefine.getOriginalSchema();
1541: //-- a redefinition doesn't always contain a schema
1542: if (tempSchema != null) {
1543: //-- Sets the master schema
1544: //-- The master schema will help resolving the links at runtime between
1545: //-- an structure and its type.
1546: tempSchema.setMasterSchema(this );
1547:
1548: tempEnum = tempSchema.getModelGroups();
1549: while (tempEnum.hasMoreElements()) {
1550: ModelGroup tempGroup = (ModelGroup) tempEnum
1551: .nextElement();
1552: if (!redefine.hasGroupRedefinition(tempGroup
1553: .getName()))
1554: result.add(tempGroup);
1555: }
1556: }
1557: }
1558:
1559: return result.elements();
1560: } //-- getmodelGroup
1561:
1562: /**
1563: * Returns the Id for this Schema, as specified by the
1564: * Id attribute, or null if no Id exists.
1565: *
1566: * @return the Id for this Scheam, or null if no Id exists
1567: **/
1568: public String getId() {
1569: return _id;
1570: } //-- getId
1571:
1572: /**
1573: * Returns the imported schemas of this schema
1574: * @return the hashtable of the imported schemas
1575: */
1576: public Enumeration getImportedSchema() {
1577: return _importedSchemas.elements();
1578: }
1579:
1580: /**
1581: * Returns the imported schema with the given namespace
1582: *
1583: * @param ns the namespace of the imported schema to return
1584: * @return the imported schema
1585: */
1586: public Schema getImportedSchema(String ns) {
1587: return getImportedSchema(ns, null);
1588: } //-- getImportedSchema
1589:
1590: /**
1591: * Returns an enumeration of redefined schemas.
1592: * @return an enumeration of redefined schemas.
1593: */
1594: public Enumeration getRedefineSchema() {
1595: return _redefineSchemas.elements();
1596: }
1597:
1598: /**
1599: * Returns the redefined schema corresponding schemaLocation.
1600: * @param schemaLocation the string corresponding to the schemaLocation.
1601: * @return the redefined schema corresponding schemaLocation.
1602: */
1603: public RedefineSchema getRedefineSchema(String schemaLocation) {
1604: RedefineSchema result = (RedefineSchema) _redefineSchemas
1605: .get(schemaLocation);
1606: return result;
1607: }
1608:
1609: /**
1610: * Returns the cached included schema with the given SchemaLocation
1611: *
1612: * @param schemaLocation the schemaLocation value used as a key to store the
1613: * cached included XML schema
1614: * @return the cached included XML schema
1615: */
1616: public Schema getCachedIncludedSchema(String schemaLocation) {
1617: return (Schema) _cachedincludedSchemas.get(schemaLocation);
1618: } //-- getCachedIncludedSchema
1619:
1620: /**
1621: * Returns an enumeration of all the included schemas that are cached
1622: * in this XML Schema Definition.
1623: *
1624: * @return an enumeration of all the included schemas that are cached
1625: * in this XML Schema Definition.
1626: *
1627: */
1628: public Enumeration getCachedIncludedSchemas() {
1629: return _cachedincludedSchemas.elements();
1630: } //-- getCachedIncludedSchemas
1631:
1632: /**
1633: * Returns the imported schema with the given namespace
1634: *
1635: * @param ns the namespace of the imported schema to return
1636: * @param localOnly a boolean that indicates only local imports
1637: * should be searched.
1638: * @return the imported schema
1639: */
1640: public Schema getImportedSchema(String ns, boolean localOnly) {
1641: if (localOnly)
1642: return (Schema) _importedSchemas.get(ns);
1643: return getImportedSchema(ns, null);
1644: } //-- getImportedSchema
1645:
1646: /**
1647: * Returns the imported schema with the given namespace
1648: *
1649: * @param ns the namespace of the imported schema to return
1650: * @return the imported schema
1651: */
1652: private Schema getImportedSchema(String ns, Schema caller) {
1653:
1654: //-- Check for recursive calls
1655: if (caller == this )
1656: return null;
1657: //-- Associate caller if necessary
1658: if (caller == null)
1659: caller = this ;
1660:
1661: Schema result = (Schema) _importedSchemas.get(ns);
1662: //--maybe we are the schema imported is at
1663: //--a depth > 1
1664: if (result == null) {
1665: Enumeration schemas = _importedSchemas.elements();
1666: while (schemas.hasMoreElements()) {
1667: Schema temp = (Schema) schemas.nextElement();
1668: result = temp.getImportedSchema(ns, caller);
1669: if (result != null)
1670: break;
1671: }
1672: }
1673: return result;
1674: } //-- getImportedSchema
1675:
1676: /**
1677: * Returns the namespace associated with the given prefix.
1678: *
1679: * @return the namespace associated with the given prefix,
1680: * or null if no associated namespace exists.
1681: */
1682: public final String getNamespace(String prefix) {
1683: if (prefix == null)
1684: prefix = "";
1685: return _namespaces.getNamespaceURI(prefix);
1686: } //-- getNamespace
1687:
1688: /**
1689: * Returns the namespaces declared for this Schema
1690: *
1691: * @return the namespaces declared for this Schema
1692: */
1693: public Namespaces getNamespaces() {
1694: return _namespaces;
1695: } //-- getNamespaces
1696:
1697: /**
1698: * Indicates that the given XML Schema file has been processed via an <xs:include>
1699: */
1700: public void addInclude(String include) {
1701: _includedSchemas.addElement(include);
1702: } //-- addInclude
1703:
1704: /**
1705: * Returns True if the given XML Schema has already been included via <xs:include>
1706: * @return True if the file specified has already been processed
1707: */
1708: public boolean includeProcessed(String includeFile) {
1709: return _includedSchemas.contains(includeFile);
1710: } //-- includeProcessed
1711:
1712: /**
1713: * Returns the namespace of the XML Schema
1714: * <BR />
1715: * Note: This is not the same as targetNamespace. This is
1716: * the namespace of "XML Schema" itself and not the namespace of the
1717: * schema that is represented by this object model
1718: * (see #getTargetNamespace).
1719: * @return the namespace of the XML Schema
1720: *
1721: **/
1722: public String getSchemaNamespace() {
1723: return _schemaNamespace;
1724: } //-- getSchemaNamespace
1725:
1726: /**
1727: * Returns the target namespace for this Schema, or null if no
1728: * namespace has been defined.
1729: * @return the target namespace for this Schema, or null if no
1730: * namespace has been defined
1731: **/
1732: public String getTargetNamespace() {
1733: return this ._targetNamespace;
1734: } //-- getTargetNamespace
1735:
1736: /**
1737: * Returns the version information of the XML Schema definition
1738: * represented by this Schema instance.
1739: *
1740: * @return the version information of the XML Schema
1741: * definition, or null if no version information exists.
1742: **/
1743: public String getVersion() {
1744: return _version;
1745: } //-- getVersion
1746:
1747: /**
1748: * Returns True if the namespace is known to this schema
1749: * @param namespaceURL the namespace URL
1750: * @return True if the namespace was declared in the schema
1751: */
1752: public boolean isKnownNamespace(String namespaceURL) {
1753: return (_namespaces.getNamespacePrefix(namespaceURL) != null);
1754: }
1755:
1756: /**
1757: * Removes the given top level ComplexType from this Schema
1758: * @param complexType the ComplexType to remove
1759: * @return true if the complexType has been removed, or
1760: * false if the complexType wasn't top level or
1761: * didn't exist in this Schema
1762: **/
1763: public boolean removeComplexType(ComplexType complexType) {
1764: boolean result = false;
1765: if (complexType.isTopLevel()) {
1766: if (_complexTypes.contains(complexType)) {
1767: _complexTypes.remove(complexType.getName());
1768: complexType.setParent(null);
1769: result = true;
1770: }
1771: if (!result) {
1772: //--check the cached included schemas
1773: Enumeration cacheIncluded = _cachedincludedSchemas
1774: .elements();
1775: while (cacheIncluded.hasMoreElements() && !result) {
1776: Schema temp = (Schema) cacheIncluded.nextElement();
1777: result = temp.removeComplexType(complexType);
1778: }
1779: //--Still false?
1780: if (!result) {
1781: //--check the redefinition
1782: Enumeration redefinitions = getRedefineSchema();
1783: while (redefinitions.hasMoreElements() && !result) {
1784: RedefineSchema redefine = (RedefineSchema) redefinitions
1785: .nextElement();
1786: result = redefine
1787: .removeComplexType(complexType);
1788: }
1789: }
1790: }
1791: }
1792: return result;
1793: } //-- removeComplexType
1794:
1795: /**
1796: * Removes the given top level Element from this Schema
1797: * @param element the ElementDecl to remove
1798: * @return true if the ElementDecl has been removed, or
1799: * false if the ElementDecl wasn't top level or
1800: * didn't exist in this Schema
1801: **/
1802: public boolean removeElement(ElementDecl element) {
1803: boolean result = false;
1804: if (_elements.contains(element)) {
1805: _elements.remove(element.getName());
1806: result = true;
1807: }
1808: if (!result) {
1809: //--check the cached included schemas
1810: Enumeration cacheIncluded = _cachedincludedSchemas
1811: .elements();
1812: while (cacheIncluded.hasMoreElements() && !result) {
1813: Schema temp = (Schema) cacheIncluded.nextElement();
1814: result = temp.removeElement(element);
1815: }
1816: }
1817: return result;
1818: } //-- removeElement
1819:
1820: /**
1821: * Removes the given top level Attribute from this Schema
1822: * @param attribute the AttributeDecl to remove
1823: * @return true if the AttributeDecl has been removed, or
1824: * false if the AttributeDecl wasn't top level or
1825: * didn't exist in this Schema
1826: */
1827: public boolean removeAttribute(AttributeDecl attribute) {
1828: boolean result = false;
1829: if (_attributes.contains(attribute)) {
1830: _attributes.remove(attribute.getName());
1831: result = true;
1832: }
1833: if (result == false) {
1834: //--check the cached included schemas
1835: Enumeration cacheIncluded = _cachedincludedSchemas
1836: .elements();
1837: while (cacheIncluded.hasMoreElements() && !result) {
1838: Schema temp = (Schema) cacheIncluded.nextElement();
1839: result = temp.removeAttribute(attribute);
1840: }
1841: }
1842: return false;
1843: } //-- removeAttribute
1844:
1845: /**
1846: * Removes the given top level ModelGroup definition from this Schema
1847: * @param group the ModelGroup definition to remove
1848: * @return true if the ModelGroup definition has been removed, or
1849: * false if the ModelGroup definition wasn't top level or
1850: * didn't exist in this Schema.
1851: */
1852: public boolean removeGroup(ModelGroup group) {
1853: boolean result = false;
1854: if (_groups.contains(group)) {
1855: _groups.remove(group.getName());
1856: result = true;
1857: }
1858: if (!result) {
1859: //--check the cached included schemas
1860: Enumeration cacheIncluded = _cachedincludedSchemas
1861: .elements();
1862: while (cacheIncluded.hasMoreElements() && !result) {
1863: Schema temp = (Schema) cacheIncluded.nextElement();
1864: result = temp.removeGroup(group);
1865: }
1866:
1867: if (!result) {
1868: //--check the redefinition
1869: Enumeration redefinitions = getRedefineSchema();
1870: while (redefinitions.hasMoreElements() && !result) {
1871: RedefineSchema redefine = (RedefineSchema) redefinitions
1872: .nextElement();
1873: result = redefine.removeGroup(group);
1874: }
1875: }
1876: }
1877:
1878: return result;
1879: } //-- removeGroup
1880:
1881: /**
1882: * Removes the given AttributeGroup definition from this Schema
1883: * @param group the AttributeGroup definition to remove
1884: * @return true if the AttributeGroup definition has been removed.
1885: */
1886: public boolean removeAttributeGroup(AttributeGroupDecl group) {
1887: boolean result = false;
1888: if (_attributeGroups.contains(group)) {
1889: _attributeGroups.remove(group.getName());
1890: result = true;
1891: }
1892: if (result == false) {
1893: //--check the cached included schemas
1894: Enumeration cacheIncluded = _cachedincludedSchemas
1895: .elements();
1896: while (cacheIncluded.hasMoreElements() && !result) {
1897: Schema temp = (Schema) cacheIncluded.nextElement();
1898: result = temp.removeAttributeGroup(group);
1899: }
1900:
1901: if (!result) {
1902: //--check the redefinition
1903: Enumeration redefinitions = getRedefineSchema();
1904: while (redefinitions.hasMoreElements() && !result) {
1905: RedefineSchema redefine = (RedefineSchema) redefinitions
1906: .nextElement();
1907: result = redefine.removeAttributeGroup(group);
1908: }
1909: }
1910: }
1911:
1912: return result;
1913: } //-- removeGroup
1914:
1915: /**
1916: * Removes the given cached included schema from this Schema definition's
1917: * list of cached included schema.
1918: *
1919: * @param schema the Schema to remove from this Schema's redefinition list
1920: *
1921: * @return true if the Schema was removed, otherwise false
1922: */
1923: public synchronized boolean removeCachedIncludedSchema(Schema schema) {
1924: if (schema == null)
1925: return false;
1926: String schemaLocation = schema.getSchemaLocation();
1927: Schema tmp = (Schema) _cachedincludedSchemas
1928: .get(schemaLocation);
1929: if (schema.equals(tmp)) {
1930: _cachedincludedSchemas.remove(schemaLocation);
1931: return true;
1932: }
1933: return false;
1934: } //-- removeImportedSchema
1935:
1936: /**
1937: * Removes the given Schema definition from this Schema definition's
1938: * list of imported schenma
1939: *
1940: * @param schema the Schema to remove from this Schema's import list
1941: *
1942: * @return true if the Schema was removed, otherwise false
1943: */
1944: public synchronized boolean removeImportedSchema(Schema schema) {
1945: if (schema == null)
1946: return false;
1947: String targetNamespace = schema.getTargetNamespace();
1948: if (targetNamespace == null)
1949: targetNamespace = "";
1950: Schema tmp = (Schema) _importedSchemas.get(targetNamespace);
1951: if (schema.equals(tmp)) {
1952: _importedSchemas.remove(targetNamespace);
1953: return true;
1954: }
1955: return false;
1956: } //-- removeImportedSchema
1957:
1958: /**
1959: * Removes the namespace from the set of namespace declarations for
1960: * this Schema definition.
1961: *
1962: * @param prefix the namespace prefix of the namespace to remove.
1963: */
1964: public boolean removeNamespace(String prefix) {
1965: if (prefix == null)
1966: prefix = "";
1967: return _namespaces.removeNamespace(prefix);
1968: } //-- removeNamespace
1969:
1970: /**
1971: * Removes the given redefined structure from this Schema definition's
1972: * list of redefinitions.
1973: *
1974: * @param schema the Schema to remove from this Schema's redefinition list
1975: *
1976: * @return true if the Schema was removed, otherwise false
1977: */
1978: public synchronized boolean removeRedefineSchema(
1979: RedefineSchema schema) {
1980: if (schema == null)
1981: return false;
1982: String schemaLocation = schema.getSchemaLocation();
1983: RedefineSchema tmp = (RedefineSchema) _redefineSchemas
1984: .get(schemaLocation);
1985: if (schema.equals(tmp)) {
1986: _redefineSchemas.remove(schemaLocation);
1987: return true;
1988: }
1989: return false;
1990: } //-- removeRedefineSchema
1991:
1992: /**
1993: * Removes the given top level SimpleType from this Schema
1994: * @param simpleType the SimpleType to remove
1995: * @return true if the SimpleType has been removed, or
1996: * false if the SimpleType wasn't top level or
1997: * didn't exist in this Schema
1998: **/
1999: public boolean removeSimpleType(SimpleType simpleType) {
2000: boolean result = false;
2001: if (_simpleTypes.contains(simpleType)) {
2002: _simpleTypes.remove(simpleType.getName());
2003: result = true;
2004: }
2005: if (result == false) {
2006: //--check the cached included schemas
2007: Enumeration cacheIncluded = _cachedincludedSchemas
2008: .elements();
2009: while (cacheIncluded.hasMoreElements() && !result) {
2010: Schema temp = (Schema) cacheIncluded.nextElement();
2011: result = temp.removeSimpleType(simpleType);
2012: }
2013:
2014: if (!result) {
2015: //--check the redefinition
2016: Enumeration redefinitions = getRedefineSchema();
2017: while (redefinitions.hasMoreElements() && !result) {
2018: RedefineSchema redefine = (RedefineSchema) redefinitions
2019: .nextElement();
2020: result = redefine.removeSimpleType(simpleType);
2021: }
2022: }
2023: }
2024: return result;
2025: } //-- removeSimpleType
2026:
2027: /**
2028: * Sets the attributeFormDefault property of this Schema.
2029: *
2030: * @param attributeFormDefault the Form value of the attributeFormDefault
2031: * property for this Schema.
2032: **/
2033: public void setAttributeFormDefault(Form attributeFormDefault) {
2034: _attributeFormDefault = attributeFormDefault;
2035: } //-- setAttributeFormDefault
2036:
2037: /**
2038: * Sets the default BlockList for this Schema.
2039: *
2040: * @param block the default BlockList to set for this Schema.
2041: **/
2042: public void setBlockDefault(BlockList block) {
2043: _block = block;
2044: } //-- setBlockDefault
2045:
2046: /**
2047: * Sets the default Block values for this Schema.
2048: *
2049: * @param block the default Block values to set for this Schema.
2050: **/
2051: public void setBlockDefault(String block) {
2052: _block = new BlockList(block);
2053: } //-- setBlockDefault
2054:
2055: /**
2056: * Sets the elementFormDefault property of this Schema.
2057: *
2058: * @param elementFormDefault the Form value of the elementFormDefault
2059: * property for this Schema.
2060: **/
2061: public void setElementFormDefault(Form elementFormDefault) {
2062: _elementFormDefault = elementFormDefault;
2063: } //-- setElementFormDefault
2064:
2065: /**
2066: * Sets the default FinalList for this Schema.
2067: *
2068: * @param finalList the default FinalList to set for this Schema.
2069: **/
2070: public void setFinalDefault(FinalList finalList) {
2071: _final = finalList;
2072: } //-- setFinalDefault
2073:
2074: /**
2075: * Sets the default final values for this Schema.
2076: *
2077: * @param finalValues the default final values to set for this Schema.
2078: **/
2079: public void setFinalDefault(String finalValues) {
2080: _final = new FinalList(finalValues);
2081: } //-- setFinalDefault
2082:
2083: /**
2084: * Set the schemaLocation for this schema. This is useful
2085: * when this schema has been imported by another schema
2086: * @param schemaLocation the location hint for this Schema
2087: */
2088: public void setSchemaLocation(String schemaLocation) {
2089: _schemaLocation = schemaLocation;
2090: }
2091:
2092: /**
2093: * Returns the first simple or complex type which name equals TypeName
2094: */
2095: public XMLType getType(String typeName) {
2096: //-- Null?
2097: if (typeName == null) {
2098: String err = NULL_ARGUMENT + "Schema#getType: ";
2099: err += "'name' cannot be null.";
2100: throw new IllegalArgumentException(err);
2101: }
2102:
2103: XMLType result = null;
2104:
2105: String localName = typeName;
2106: String prefix = "";
2107: String ns = null;
2108:
2109: int colon = typeName.indexOf(':');
2110:
2111: if (colon >= 0) {
2112: localName = typeName.substring(colon + 1);
2113: prefix = typeName.substring(0, colon);
2114: ns = _namespaces.getNamespaceURI(prefix);
2115: if (ns == null) {
2116: String err = "Schema#getType: ";
2117: err += "Namespace prefix not recognised '" + typeName
2118: + "'";
2119: throw new IllegalArgumentException(err);
2120: }
2121: }
2122:
2123: //-- use default namespace if necessary
2124: if (ns == null) {
2125: ns = _namespaces.getNamespaceURI(prefix);
2126: }
2127:
2128: //--if at this point, there is no namespace
2129: //--then we assume it is the targetNamespace
2130: if (ns == null) {
2131: //--SHOULD WE THROW AN EXCEPTION?
2132: ns = _targetNamespace;
2133: }
2134:
2135: //1--support for anyType
2136: if (localName.equals(SchemaNames.ANYTYPE)) {
2137: //--if 'anyType' in the default schema namespace-->type is anyType
2138: if (ns.equals(DEFAULT_SCHEMA_NS)) {
2139: result = new AnyType(this );
2140: }
2141: }//--anyType
2142:
2143: IllegalArgumentException exception = null;
2144: //2--look for a simpleType
2145: if (result == null) {
2146: try {
2147: result = getSimpleType(localName, ns);
2148: } catch (IllegalArgumentException iox) {
2149: exception = iox;
2150: }
2151: }
2152:
2153: //3--look for a complexType
2154: if (result == null) {
2155: try {
2156: result = getComplexType(typeName);
2157: } catch (IllegalArgumentException iox) {
2158: exception = iox;
2159: }
2160: }
2161:
2162: if ((result == null) && (exception != null))
2163: throw exception;
2164:
2165: return result;
2166: }
2167:
2168: /**
2169: * Sets the Id for this Schema
2170: *
2171: * @param id the Id for this Schema
2172: **/
2173: public void setId(String id) {
2174: this ._id = id;
2175: } //-- setId
2176:
2177: /**
2178: * Sets the target namespace for this Schema
2179: * @param targetNamespace the target namespace for this Schema
2180: * @see "§ 2.7 XML Schema Part 1: Structures"
2181: **/
2182: public void setTargetNamespace(String targetNamespace) {
2183: if (targetNamespace != null) {
2184: targetNamespace = targetNamespace.trim();
2185: if (targetNamespace.length() == 0)
2186: throw new IllegalStateException(
2187: "an empty string is not a valid namespace.");
2188: }
2189: _targetNamespace = targetNamespace;
2190: } //-- setTargetNamespace
2191:
2192: /**
2193: * Sets the version information for the XML Schema defintion
2194: * represented by this Schema instance.
2195: *
2196: * @param version the version for this XML Schema defination.
2197: **/
2198: public void setVersion(String version) {
2199: _version = version;
2200: } //-- setVersion
2201:
2202: /** Gets the type factory, package private */
2203: static SimpleTypesFactory getTypeFactory() {
2204: return simpleTypesFactory;
2205: }
2206:
2207: //-------------------------------/
2208: //- Implementation of Structure -/
2209: //-------------------------------/
2210:
2211: /**
2212: * Returns the type of this Schema Structure
2213: * @return the type of this Schema Structure
2214: **/
2215: public short getStructureType() {
2216: return Structure.SCHEMA;
2217: } //-- getStructureType
2218:
2219: /**
2220: * Checks the validity of this Schema definition.
2221: *
2222: * @throws ValidationException when this Schema definition
2223: * is invalid.
2224: **/
2225: public void validate() throws ValidationException {
2226:
2227: //-- Note: This method needs to be completed.
2228:
2229: //-- top-level complexTypes
2230: Enumeration enumeration = _complexTypes.elements();
2231: while (enumeration.hasMoreElements()) {
2232: ComplexType type = (ComplexType) enumeration.nextElement();
2233: type.validate();
2234: }
2235: //-- top-level simpleTypes
2236: enumeration = _simpleTypes.elements();
2237: while (enumeration.hasMoreElements()) {
2238: SimpleType type = (SimpleType) enumeration.nextElement();
2239: type.validate();
2240: }
2241:
2242: //-- top-level elements
2243: enumeration = _elements.elements();
2244: while (enumeration.hasMoreElements()) {
2245: ((ElementDecl) enumeration.nextElement()).validate();
2246: }
2247:
2248: //-- top-level attributes
2249: enumeration = _attributes.elements();
2250: while (enumeration.hasMoreElements()) {
2251: ((AttributeDecl) enumeration.nextElement()).validate();
2252: }
2253:
2254: //-- top-level groups
2255: enumeration = _groups.elements();
2256: while (enumeration.hasMoreElements()) {
2257: ((Group) enumeration.nextElement()).validate();
2258: }
2259: //-- top-level attribute groups
2260:
2261: } //-- validate
2262:
2263: //-- private methods:
2264:
2265: /**
2266: * Returns the namespace prefix associated with the
2267: * given namespace. If more than one prefix has been
2268: * associated, the first one found will be returned.
2269: *
2270: * @return the namespace prefix associaed with the
2271: * given namespace.
2272: **/
2273: protected String getNamespacePrefix(String namespace) {
2274: return _namespaces.getNamespacePrefix(namespace);
2275: }
2276:
2277: /**
2278: * Returns the master schema in which this instance of schema
2279: * is used at runtime. This method is meant to be used at runtime.
2280: *
2281: * @return the master schema in which this instance of schema
2282: * is used at runtime. This method is meant to be used at runtime.
2283: */
2284: protected Schema getMasterSchema() {
2285: return _masterSchema;
2286: }
2287:
2288: /**
2289: * Sets the master schema in which this instance of schema
2290: * is used at runtime. This method is meant to be used at runtime.
2291: * A master schema is a schema in which this instance of Schema is
2292: * included, redefined or imported.
2293: *
2294: * @param masterSchema the master schema in which this instance of schema
2295: * is used at runtime. This method is meant to be used at runtime.
2296: */
2297: protected void setMasterSchema(Schema masterSchema) {
2298: _masterSchema = masterSchema;
2299: }
2300:
2301: } //-- Schema
|