Package org.exolab.castor.xml.schema
Class Schema
java.lang.Object
org.exolab.castor.xml.schema.Structure
org.exolab.castor.xml.schema.Annotated
org.exolab.castor.xml.schema.Schema
- All Implemented Interfaces:
Serializable
A class representing an XML Schema Definition. This class also
contains some Factory methods for creating Top-Level structures.
- Version:
- $Revision: 8667 $ $Date: 2006-04-26 13:58:52 -0600 (Wed, 26 Apr 2006) $
- Author:
- Keith Visco
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The Namespace supported by the W3C XML Schema Recommendation.static final String
The Namespace supported by the W3C XML Schema Recommendation for the built-in types: xsi:type, xsi:nil, and xsi:schemaLocation.Fields inherited from class org.exolab.castor.xml.schema.Structure
ANNOTATION, ANYTYPE, APPINFO, ATTRIBUTE, ATTRIBUTE_GROUP, COMPLEX_CONTENT, COMPLEX_TYPE, DOCUMENTATION, ELEMENT, FACET, GROUP, IDENTITY_FIELD, IDENTITY_SELECTOR, KEY, KEYREF, LIST, MODELGROUP, MODELGROUP_REF, REDEFINE, SCHEMA, SIMPLE_CONTENT, SIMPLE_TYPE, UNION, UNIQUE, UNKNOWN, WILDCARD
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAttribute
(AttributeDecl attribute) Adds the given attribute definition to this Schema definitionvoid
addAttributeGroup
(AttributeGroupDecl attrGroup) Adds the given attribute group definition to this Schema definition.void
addComplexType
(ComplexType complexType) Adds the given Complextype definition to this Schema defintionvoid
addElementDecl
(ElementDecl elementDecl) Adds the given Element declaration to this Schema defintionvoid
addImportedSchema
(Schema schema) Adds the given Schema definition to this Schema definition as an imported schenmavoid
addInclude
(String include) Indicates that the given XML Schema file has been processed via an invalid input: '<'xs:include>void
addModelGroup
(ModelGroup group) Adds the given Group declaration to this Schema definitionvoid
addNamespace
(String prefix, String ns) Adds to the namespaces declared in this Schemavoid
addRedefineSchema
(RedefineSchema schema) Adds the given redefinition of structures to this Schema definition.void
addSimpleType
(SimpleType simpleType) Adds the given SimpletType definition to this Schema defintionvoid
cacheIncludedSchema
(Schema schema) Caches the given Schema definition as an included XML Schema of this Schema definition.Creates a new ComplexType using this Schema as the owning Schema document.createComplexType
(String name) Creates a new ComplexType using this Schema as the owning Schema document.createSimpleType
(String name, String baseName, String derivation) Creates a new SimpleType using this Schema as the owning Schema document.createSimpleType
(String name, SimpleType baseType) Creates a new SimpleType using this Schema as the owning Schema document.getAttribute
(String name) Returns the top-level Attribute associated with the given name.Returns the attributeFormDefault property of this Schema.getAttributeGroup
(String name) Returns the AttributeGroup associated with the given name.Returns an Enumeration of all top-level AttributeGroup declarationsReturns an Enumeration of all top-level Attribute declarationsReturns the default BlockList for this Schema.getBuiltInTypeName
(int builtInTypeCode) Gets a built in type's name given its code.getCachedIncludedSchema
(String schemaLocation) Returns the cached included schema with the given SchemaLocationReturns an enumeration of all the included schemas that are cached in this XML Schema Definition.getComplexType
(String name) Returns the ComplexType of associated with the given nameReturns an Enumeration of all top-level ComplexType declarationsgetElementDecl
(String name) Returns the ElementDecl of associated with the given nameReturns an Enumeration of all top-level element declarationsReturns the elementFormDefault property of this Schema.Returns the default FinalList for this Schema.getId()
Returns the Id for this Schema, as specified by the Id attribute, or null if no Id exists.Returns the imported schemas of this schemaReturns the imported schema with the given namespacegetImportedSchema
(String ns, boolean localOnly) Returns the imported schema with the given namespaceprotected Schema
Returns the master schema in which this instance of schema is used at runtime.getModelGroup
(String name) Returns the ModeGroup of associated with the given nameReturns an Enumeration of all top-level ModelGroup declarationsfinal String
getNamespace
(String prefix) Returns the namespace associated with the given prefix.getNamespacePrefix
(String namespace) Returns the namespace prefix associated with the given namespace.Returns the namespaces declared for this SchemaReturns an enumeration of redefined schemas.getRedefineSchema
(String schemaLocation) Returns the redefined schema corresponding schemaLocation.Returns the schemaLocation hint provided of this schemaReturns the namespace of the XML Schema
Note: This is not the same as targetNamespace.getSimpleType
(String name) Returns the SimpleType associated with the given name, or null if no such SimpleType exists.getSimpleType
(String name, String namespace) Returns the SimpleType associated with the given name and namespace, or null if no such SimpleType exists.Returns an Enumeration of all SimpleType declarationsshort
Returns the type of this Schema StructureReturns the target namespace for this Schema, or null if no namespace has been defined.Returns the first simple or complex type which name equals TypeNameReturns the version information of the XML Schema definition represented by this Schema instance.boolean
includeProcessed
(String includeFile) Returns True if the given XML Schema has already been included via invalid input: '<'xs:include>boolean
isKnownNamespace
(String namespaceURL) Returns True if the namespace is known to this schemaboolean
removeAttribute
(AttributeDecl attribute) Removes the given top level Attribute from this Schemaboolean
Removes the given AttributeGroup definition from this Schemaboolean
removeCachedIncludedSchema
(Schema schema) Removes the given cached included schema from this Schema definition's list of cached included schema.boolean
removeComplexType
(ComplexType complexType) Removes the given top level ComplexType from this Schemaboolean
removeElement
(ElementDecl element) Removes the given top level Element from this Schemaboolean
removeGroup
(ModelGroup group) Removes the given top level ModelGroup definition from this Schemaboolean
removeImportedSchema
(Schema schema) Removes the given Schema definition from this Schema definition's list of imported schenmaboolean
removeNamespace
(String prefix) Removes the namespace from the set of namespace declarations for this Schema definition.boolean
removeRedefineSchema
(RedefineSchema schema) Removes the given redefined structure from this Schema definition's list of redefinitions.boolean
removeSimpleType
(SimpleType simpleType) Removes the given top level SimpleType from this Schemavoid
setAttributeFormDefault
(Form attributeFormDefault) Sets the attributeFormDefault property of this Schema.void
setBlockDefault
(String block) Sets the default Block values for this Schema.void
setBlockDefault
(BlockList block) Sets the default BlockList for this Schema.void
setElementFormDefault
(Form elementFormDefault) Sets the elementFormDefault property of this Schema.void
setFinalDefault
(String finalValues) Sets the default final values for this Schema.void
setFinalDefault
(FinalList finalList) Sets the default FinalList for this Schema.void
Sets the Id for this Schemaprotected void
setMasterSchema
(Schema masterSchema) Sets the master schema in which this instance of schema is used at runtime.void
setSchemaLocation
(String schemaLocation) Set the schemaLocation for this schema.void
setTargetNamespace
(String targetNamespace) Sets the target namespace for this Schemavoid
setVersion
(String version) Sets the version information for the XML Schema defintion represented by this Schema instance.void
validate()
Checks the validity of thisSchema
definition.Methods inherited from class org.exolab.castor.xml.schema.Annotated
addAnnotation, getAnnotations, removeAnnotation
-
Field Details
-
DEFAULT_SCHEMA_NS
The Namespace supported by the W3C XML Schema Recommendation.- See Also:
-
XSI_NAMESPACE
The Namespace supported by the W3C XML Schema Recommendation for the built-in types: xsi:type, xsi:nil, and xsi:schemaLocation.- See Also:
-
-
Constructor Details
-
Schema
public Schema()Creates a new Schema definition -
Schema
Creates a new Schema definition- Parameters:
schemaNS
- the namespace of the XML Schema itself. Note this is not the same as the targetNamespace.
-
Schema
Creates a new Schema definition- Parameters:
prefix
- the desired namespace prefix for the schemaNS.schemaNamespace
- the namespace of the XML Schema itself. Note this is not the same as the targetNamespace.
-
-
Method Details
-
addAttribute
Adds the given attribute definition to this Schema definition- Parameters:
attribute
- the AttributeDecl to add- Throws:
SchemaException
-
addAttributeGroup
Adds the given attribute group definition to this Schema definition.- Parameters:
attrGroup
- the AttributeGroupDecl to add- Throws:
SchemaException
- if an AttributeGroupDecl already exisits with the same name
-
addComplexType
Adds the given Complextype definition to this Schema defintion- Parameters:
complexType
- the Complextype to add to this Schema- Throws:
SchemaException
- if the Complextype does not have a name or if another Complextype already exists with the same name
-
addElementDecl
Adds the given Element declaration to this Schema defintion- Parameters:
elementDecl
- the ElementDecl to add to this SchemaDef- Throws:
SchemaException
- when an ElementDecl already exists with the same name as the given ElementDecl
-
addModelGroup
Adds the given Group declaration to this Schema definition- Parameters:
group
- the Group to add to this SchemaDef- Throws:
SchemaException
- when an Group already exists with the same name as the given Group
-
addRedefineSchema
Adds the given redefinition of structures to this Schema definition. This structure is mainly used to allow the writing of an XML schema that contains redefinitions. The validation process is permissive since the method won't check that the XML Schema is already imported nor will it check that the redefined structures exist.- Parameters:
schema
- the Group to add to this SchemaDef- Throws:
SchemaException
- when an redefintion already exists with the same name as the given ElementDecl
-
addImportedSchema
Adds the given Schema definition to this Schema definition as an imported schenma- Parameters:
schema
- the Schema to add to this Schema as an imported schema- Throws:
SchemaException
- if the Schema already exists
-
cacheIncludedSchema
Caches the given Schema definition as an included XML Schema of this Schema definition.- Parameters:
schema
- the Schema to add to this Schema as a cached included schema.- Throws:
SchemaException
- if the Schema already exists
-
addNamespace
Adds to the namespaces declared in this Schema -
addSimpleType
Adds the given SimpletType definition to this Schema defintion- Parameters:
simpleType
- the SimpleType to add to this Schema- Throws:
SchemaException
- if the SimpleType does not have a name or if another SimpleType already exists with the same name
-
createComplexType
Creates a new ComplexType using this Schema as the owning Schema document. A call to #addComplexType must still be made in order to add the complexType to this Schema.- Returns:
- the new ComplexType
-
createComplexType
Creates a new ComplexType using this Schema as the owning Schema document. A call to #addComplexType must still be made in order to add the complexType to this Schema.- Parameters:
name
- the name of the ComplexType- Returns:
- the new ComplexType
-
createSimpleType
Creates a new SimpleType using this Schema as the owning Schema document. A call to #addSimpleType must till be made in order to add the SimpleType to this Schema.- Parameters:
name
- the name of the SimpleTypebaseName
- the name of the SimpleType's base typederivation
- the name of the derivation method (""/"list"/"restriction")- Returns:
- the new SimpleType.
-
createSimpleType
Creates a new SimpleType using this Schema as the owning Schema document. A call to #addSimpleType must till be made in order to add the SimpleType to this Schema if the type is to be global.- Parameters:
name
- the name of the SimpleTypebaseType
- the base type of the SimpleType to create- Returns:
- the new SimpleType.
-
getAttributeFormDefault
Returns the attributeFormDefault property of this Schema.- Returns:
- the attributeFormDefault property of this Schema, or null if no default Form was set. If no default Form has been set, the user should assume Form.Unqualified.
-
getAttributes
Returns an Enumeration of all top-level Attribute declarations- Returns:
- an Enumeration of all top-level Attribute declarations
-
getAttribute
Returns the top-level Attribute associated with the given name.- Returns:
- the Attribute associated with the given name, or null if no Attribute association is found.
-
getAttributeGroups
Returns an Enumeration of all top-level AttributeGroup declarations- Returns:
- an Enumeration of all top-level AttributeGroup declarations
-
getAttributeGroup
Returns the AttributeGroup associated with the given name.- Returns:
- the AttributeGroup associated with the given name, or null if no AttributeGroup association is found.
-
getBlockDefault
Returns the default BlockList for this Schema.- Returns:
- the default BlockList for this Schema.
-
getBuiltInTypeName
Gets a built in type's name given its code. -
getComplexType
Returns the ComplexType of associated with the given name- Returns:
- the ComplexType of associated with the given name, or null if no ComplexType with the given name was found.
-
getComplexTypes
Returns an Enumeration of all top-level ComplexType declarations- Returns:
- an Enumeration of all top-level ComplexType declarations
-
getElementDecl
Returns the ElementDecl of associated with the given name- Returns:
- the ElementDecl of associated with the given name, or null if no ElementDecl with the given name was found.
-
getElementDecls
Returns an Enumeration of all top-level element declarations- Returns:
- an Enumeration of all top-level element declarations
-
getElementFormDefault
Returns the elementFormDefault property of this Schema.- Returns:
- the elementFormDefault property of this Schema, or null if no default Form was set. If no default Form has been set, the user should assume Form.Unqualified.
-
getFinalDefault
Returns the default FinalList for this Schema.- Returns:
- final the default FinalList for this Schema.
-
getSimpleType
Returns the SimpleType associated with the given name, or null if no such SimpleType exists.- Parameters:
name
- the name of the SimpleType. The name may be a QName (contain a namespace prefix).- Returns:
- the SimpleType associated with the given name, or null if no such SimpleType exists.
-
getSimpleType
Returns the SimpleType associated with the given name and namespace, or null if no such SimpleType exists.- Parameters:
name
- the name of the simpleType. It is an error if this name contains a prefix, it must be an NCName.namespace
- the namespace URI of the simpleType.- Returns:
- the SimpleType, or null if no such SimpleType exists.
-
getSimpleTypes
Returns an Enumeration of all SimpleType declarations- Returns:
- an Enumeration of all SimpleType declarations
-
getSchemaLocation
Returns the schemaLocation hint provided of this schema- Returns:
- the schemaLocation hint provided of this schema
-
getModelGroup
Returns the ModeGroup of associated with the given name- Returns:
- the ModelGroup of associated with the given name, or null if no ModelGroup with the given name was found.
-
getModelGroups
Returns an Enumeration of all top-level ModelGroup declarations- Returns:
- an Enumeration of all top-level ModelGroup declarations
-
getId
Returns the Id for this Schema, as specified by the Id attribute, or null if no Id exists.- Returns:
- the Id for this Scheam, or null if no Id exists
-
getImportedSchema
Returns the imported schemas of this schema- Returns:
- the hashtable of the imported schemas
-
getImportedSchema
Returns the imported schema with the given namespace- Parameters:
ns
- the namespace of the imported schema to return- Returns:
- the imported schema
-
getRedefineSchema
Returns an enumeration of redefined schemas.- Returns:
- an enumeration of redefined schemas.
-
getRedefineSchema
Returns the redefined schema corresponding schemaLocation.- Parameters:
schemaLocation
- the string corresponding to the schemaLocation.- Returns:
- the redefined schema corresponding schemaLocation.
-
getCachedIncludedSchema
Returns the cached included schema with the given SchemaLocation- Parameters:
schemaLocation
- the schemaLocation value used as a key to store the cached included XML schema- Returns:
- the cached included XML schema
-
getCachedIncludedSchemas
Returns an enumeration of all the included schemas that are cached in this XML Schema Definition.- Returns:
- an enumeration of all the included schemas that are cached in this XML Schema Definition.
-
getImportedSchema
Returns the imported schema with the given namespace- Parameters:
ns
- the namespace of the imported schema to returnlocalOnly
- a boolean that indicates only local imports should be searched.- Returns:
- the imported schema
-
getNamespace
Returns the namespace associated with the given prefix.- Returns:
- the namespace associated with the given prefix, or null if no associated namespace exists.
-
getNamespaces
Returns the namespaces declared for this Schema- Returns:
- the namespaces declared for this Schema
-
addInclude
Indicates that the given XML Schema file has been processed via an invalid input: '<'xs:include> -
includeProcessed
Returns True if the given XML Schema has already been included via invalid input: '<'xs:include>- Returns:
- True if the file specified has already been processed
-
getSchemaNamespace
Returns the namespace of the XML Schema
Note: This is not the same as targetNamespace. This is the namespace of "XML Schema" itself and not the namespace of the schema that is represented by this object model (see #getTargetNamespace).- Returns:
- the namespace of the XML Schema
-
getTargetNamespace
Returns the target namespace for this Schema, or null if no namespace has been defined.- Returns:
- the target namespace for this Schema, or null if no namespace has been defined
-
getVersion
Returns the version information of the XML Schema definition represented by this Schema instance.- Returns:
- the version information of the XML Schema definition, or null if no version information exists.
-
isKnownNamespace
Returns True if the namespace is known to this schema- Parameters:
namespaceURL
- the namespace URL- Returns:
- True if the namespace was declared in the schema
-
removeComplexType
Removes the given top level ComplexType from this Schema- Parameters:
complexType
- the ComplexType to remove- Returns:
- true if the complexType has been removed, or false if the complexType wasn't top level or didn't exist in this Schema
-
removeElement
Removes the given top level Element from this Schema- Parameters:
element
- the ElementDecl to remove- Returns:
- true if the ElementDecl has been removed, or false if the ElementDecl wasn't top level or didn't exist in this Schema
-
removeAttribute
Removes the given top level Attribute from this Schema- Parameters:
attribute
- the AttributeDecl to remove- Returns:
- true if the AttributeDecl has been removed, or false if the AttributeDecl wasn't top level or didn't exist in this Schema
-
removeGroup
Removes the given top level ModelGroup definition from this Schema- Parameters:
group
- the ModelGroup definition to remove- Returns:
- true if the ModelGroup definition has been removed, or false if the ModelGroup definition wasn't top level or didn't exist in this Schema.
-
removeAttributeGroup
Removes the given AttributeGroup definition from this Schema- Parameters:
group
- the AttributeGroup definition to remove- Returns:
- true if the AttributeGroup definition has been removed.
-
removeCachedIncludedSchema
Removes the given cached included schema from this Schema definition's list of cached included schema.- Parameters:
schema
- the Schema to remove from this Schema's redefinition list- Returns:
- true if the Schema was removed, otherwise false
-
removeImportedSchema
Removes the given Schema definition from this Schema definition's list of imported schenma- Parameters:
schema
- the Schema to remove from this Schema's import list- Returns:
- true if the Schema was removed, otherwise false
-
removeNamespace
Removes the namespace from the set of namespace declarations for this Schema definition.- Parameters:
prefix
- the namespace prefix of the namespace to remove.
-
removeRedefineSchema
Removes the given redefined structure from this Schema definition's list of redefinitions.- Parameters:
schema
- the Schema to remove from this Schema's redefinition list- Returns:
- true if the Schema was removed, otherwise false
-
removeSimpleType
Removes the given top level SimpleType from this Schema- Parameters:
simpleType
- the SimpleType to remove- Returns:
- true if the SimpleType has been removed, or false if the SimpleType wasn't top level or didn't exist in this Schema
-
setAttributeFormDefault
Sets the attributeFormDefault property of this Schema.- Parameters:
attributeFormDefault
- the Form value of the attributeFormDefault property for this Schema.
-
setBlockDefault
Sets the default BlockList for this Schema.- Parameters:
block
- the default BlockList to set for this Schema.
-
setBlockDefault
Sets the default Block values for this Schema.- Parameters:
block
- the default Block values to set for this Schema.
-
setElementFormDefault
Sets the elementFormDefault property of this Schema.- Parameters:
elementFormDefault
- the Form value of the elementFormDefault property for this Schema.
-
setFinalDefault
Sets the default FinalList for this Schema.- Parameters:
finalList
- the default FinalList to set for this Schema.
-
setFinalDefault
Sets the default final values for this Schema.- Parameters:
finalValues
- the default final values to set for this Schema.
-
setSchemaLocation
Set the schemaLocation for this schema. This is useful when this schema has been imported by another schema- Parameters:
schemaLocation
- the location hint for this Schema
-
getType
Returns the first simple or complex type which name equals TypeName -
setId
Sets the Id for this Schema- Parameters:
id
- the Id for this Schema
-
setTargetNamespace
Sets the target namespace for this Schema- Parameters:
targetNamespace
- the target namespace for this Schema- See Also:
-
- "§ 2.7 XML Schema Part 1: Structures"
-
setVersion
Sets the version information for the XML Schema defintion represented by this Schema instance.- Parameters:
version
- the version for this XML Schema defination.
-
getStructureType
public short getStructureType()Returns the type of this Schema Structure- Specified by:
getStructureType
in classStructure
- Returns:
- the type of this Schema Structure
-
validate
Checks the validity of thisSchema
definition.- Specified by:
validate
in classStructure
- Throws:
ValidationException
- when thisSchema
definition is invalid.
-
getNamespacePrefix
Returns the namespace prefix associated with the given namespace. If more than one prefix has been associated, the first one found will be returned.- Returns:
- the namespace prefix associaed with the given namespace.
-
getMasterSchema
Returns the master schema in which this instance of schema is used at runtime. This method is meant to be used at runtime.- Returns:
- the master schema in which this instance of schema is used at runtime. This method is meant to be used at runtime.
-
setMasterSchema
Sets the master schema in which this instance of schema is used at runtime. This method is meant to be used at runtime. A master schema is a schema in which this instance of Schema is included, redefined or imported.- Parameters:
masterSchema
- the master schema in which this instance of schema is used at runtime. This method is meant to be used at runtime.
-