org.exolab.castor.xml.schema
Class Schema

java.lang.Object
  extended byorg.exolab.castor.xml.schema.Structure
      extended byorg.exolab.castor.xml.schema.Annotated
          extended byorg.exolab.castor.xml.schema.Schema
All Implemented Interfaces:
java.io.Serializable

public class Schema
extends Annotated

A class representing an XML Schema Definition. This class also contains some Factory methods for creating Top-Level structures.

Version:
$Revision: 1.3 $ $Date: 2003/03/03 18:13:37 $
Author:
Keith Visco
See Also:
Serialized Form

Field Summary
static java.lang.String DEFAULT_SCHEMA_NS
          The Namespace supported by the W3C XML Schema Recommendation.
static java.lang.String XSI_NAMESPACE
          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
Schema()
          Creates a new Schema definition
Schema(java.lang.String schemaNS)
          Creates a new Schema definition
Schema(java.lang.String prefix, java.lang.String schemaNS)
          Creates a new Schema definition
 
Method Summary
 void addAttribute(AttributeDecl attribute)
          Adds the given attribute definition to this Schema definition
 void 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 defintion
 void addElementDecl(ElementDecl elementDecl)
          Adds the given Element declaration to this Schema defintion
 void addImportedSchema(Schema schema)
          Adds the given Schema definition to this Schema definition as an imported schenma
 void addInclude(java.lang.String include)
          Indicates that the given XML Schema file has been processed via an
 void addModelGroup(ModelGroup group)
          Adds the given Group declaration to this Schema definition
 void addNamespace(java.lang.String prefix, java.lang.String ns)
          Adds to the namespaces declared in this Schema
 void addSimpleType(SimpleType simpleType)
          Adds the given SimpletType definition to this Schema defintion
 ComplexType createComplexType()
          Creates a new ComplexType using this Schema as the owning Schema document.
 ComplexType createComplexType(java.lang.String name)
          Creates a new ComplexType using this Schema as the owning Schema document.
 SimpleType createSimpleType(java.lang.String name, SimpleType baseType)
          Creates a new SimpleType using this Schema as the owning Schema document.
 SimpleType createSimpleType(java.lang.String name, java.lang.String baseName, java.lang.String derivation)
          Creates a new SimpleType using this Schema as the owning Schema document.
 AttributeDecl getAttribute(java.lang.String name)
          Returns the top-level Attribute associated with the given name.
 Form getAttributeFormDefault()
          Returns the attributeFormDefault property of this Schema.
 AttributeGroup getAttributeGroup(java.lang.String name)
          Returns the AttributeGroup associated with the given name.
 java.util.Enumeration getAttributeGroups()
          Returns an Enumeration of all top-level AttributeGroup declarations
 java.util.Enumeration getAttributes()
          Returns an Enumeration of all top-level Attribute declarations
 BlockList getBlockDefault()
          Returns the default BlockList for this Schema.
 java.lang.String getBuiltInTypeName(int builtInTypeCode)
          Gets a built in type's name given its code.
 ComplexType getComplexType(java.lang.String name)
          Returns the ComplexType of associated with the given name
 java.util.Enumeration getComplexTypes()
          Returns an Enumeration of all top-level ComplexType declarations
 ElementDecl getElementDecl(java.lang.String name)
          Returns the ElementDecl of associated with the given name
 java.util.Enumeration getElementDecls()
          Returns an Enumeration of all top-level element declarations
 Form getElementFormDefault()
          Returns the elementFormDefault property of this Schema.
 FinalList getFinalDefault()
          Returns the default FinalList for this Schema.
 java.lang.String getId()
          Returns the Id for this Schema, as specified by the Id attribute, or null if no Id exists.
 java.util.Enumeration getImportedSchema()
          Returns the imported schemas of this schema
 Schema getImportedSchema(java.lang.String ns)
          Returns an imported schema by its namespace
 ModelGroup getModelGroup(java.lang.String name)
          Returns the ModeGroup of associated with the given name
 java.util.Enumeration getModelGroups()
          Returns an Enumeration of all top-level ModelGroup declarations
 java.lang.String getNamespace(java.lang.String prefix)
          Returns the namespace associated with the given prefix.
protected  java.lang.String getNamespacePrefix(java.lang.String namespace)
          Returns the namespace prefix associated with the given namespace.
 java.util.Hashtable getNamespaces()
          Returns the namespaces declared for this Schema
 java.lang.String getSchemaLocation()
          Returns the schemaLocation hint provided of this schema
 java.lang.String getSchemaNamespace()
          Returns the namespace of the XML Schema
Note: This is not the same as targetNamespace.
 SimpleType getSimpleType(java.lang.String name)
          Returns the SimpleType associated with the given name, or null if no such SimpleType exists.
 SimpleType getSimpleType(java.lang.String name, java.lang.String namespace)
          Returns the SimpleType associated with the given name and namespace, or null if no such SimpleType exists.
 java.util.Enumeration getSimpleTypes()
          Returns an Enumeration of all SimpleType declarations
 short getStructureType()
          Returns the type of this Schema Structure
 java.lang.String getTargetNamespace()
          Returns the target namespace for this Schema, or null if no namespace has been defined.
 XMLType getType(java.lang.String typeName)
          Returns the first simple or complex type which name equals TypeName
(package private) static SimpleTypesFactory getTypeFactory()
          Gets the type factory, package private
 java.lang.String getVersion()
          Returns the version information of the XML Schema definition represented by this Schema instance.
 boolean includeProcessed(java.lang.String includeFile)
          Returns True if the given XML Schema has already been included via
 boolean isKnownNamespace(java.lang.String namespaceURL)
          Returns True if the namespace is known to this schema
 boolean removeAttribute(AttributeDecl attribute)
          Removes the given top level Attribute from this Schema
 boolean removeComplexType(ComplexType complexType)
          Removes the given top level ComplexType from this Schema
 boolean removeElement(ElementDecl element)
          Removes the given top level Element from this Schema
 boolean removeGroup(ModelGroup group)
          Removes the given top level ModelGroup definition from this Schema
 boolean removeNamespace(java.lang.String prefix)
          Removes the namespace from the set of namespace declarations for this Schema definition.
 boolean removeSimpleType(SimpleType simpleType)
          Removes the given top level SimpleType from this Schema
 void setAttributeFormDefault(Form attributeFormDefault)
          Sets the attributeFormDefault property of this Schema.
 void setBlockDefault(BlockList block)
          Sets the default BlockList for this Schema.
 void setBlockDefault(java.lang.String block)
          Sets the default Block values for this Schema.
 void setElementFormDefault(Form elementFormDefault)
          Sets the elementFormDefault property of this Schema.
 void setFinalDefault(FinalList finalList)
          Sets the default FinalList for this Schema.
 void setFinalDefault(java.lang.String finalValues)
          Sets the default final values for this Schema.
 void setId(java.lang.String id)
          Sets the Id for this Schema
 void setSchemaLocation(java.lang.String schemaLocation)
          Set the schemaLocation for this schema.
 void setTargetNamespace(java.lang.String targetNamespace)
          Sets the target namespace for this Schema
 void setVersion(java.lang.String version)
          Sets the version information for the XML Schema defintion represented by this Schema instance.
 void validate()
          Checks the validity of this Schema defintion.
 
Methods inherited from class org.exolab.castor.xml.schema.Annotated
addAnnotation, getAnnotations, removeAnnotation
 
Methods inherited from class org.exolab.castor.xml.schema.Structure
isValid
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_SCHEMA_NS

public static final java.lang.String DEFAULT_SCHEMA_NS
The Namespace supported by the W3C XML Schema Recommendation.

See Also:
Constant Field Values

XSI_NAMESPACE

public static final java.lang.String 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:
Constant Field Values
Constructor Detail

Schema

public Schema()
Creates a new Schema definition


Schema

public Schema(java.lang.String schemaNS)
Creates a new Schema definition

Parameters:
schemaNS - the namespace of the XML Schema itself. Note this is not the same as the targetNamespace.

Schema

public Schema(java.lang.String prefix,
              java.lang.String schemaNS)
Creates a new Schema definition

Parameters:
prefix - the desired namespace prefix for the schemaNS.
schemaNS - the namespace of the XML Schema itself. Note this is not the same as the targetNamespace.
Method Detail

addAttribute

public void addAttribute(AttributeDecl attribute)
                  throws SchemaException
Adds the given attribute definition to this Schema definition

Parameters:
attribute - the AttributeDecl to add
Throws:
SchemaException - if an AttributeDecl already exisits with the same name

addAttributeGroup

public void addAttributeGroup(AttributeGroupDecl attrGroup)
                       throws SchemaException
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

public void addComplexType(ComplexType complexType)
                    throws SchemaException
Adds the given Complextype definition to this Schema defintion

Throws:
SchemaException - if the Complextype does not have a name or if another Complextype already exists with the same name

addElementDecl

public void addElementDecl(ElementDecl elementDecl)
                    throws SchemaException
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

public void addModelGroup(ModelGroup group)
                   throws SchemaException
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 ElementDecl

addImportedSchema

public void addImportedSchema(Schema schema)
                       throws SchemaException
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

addNamespace

public void addNamespace(java.lang.String prefix,
                         java.lang.String ns)
Adds to the namespaces declared in this Schema


addSimpleType

public void addSimpleType(SimpleType simpleType)
                   throws SchemaException
Adds the given SimpletType definition to this Schema defintion

Throws:
SchemaException - if the SimpleType does not have a name or if another SimpleType already exists with the same name

createComplexType

public 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.

Returns:
the new ComplexType

createComplexType

public ComplexType createComplexType(java.lang.String name)
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

public SimpleType createSimpleType(java.lang.String name,
                                   java.lang.String baseName,
                                   java.lang.String derivation)
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 SimpleType
baseName - the name of the SimpleType's base type
derivation - the name of the derivation method (""/"list"/"restriction")
Returns:
the new SimpleType.

createSimpleType

public SimpleType createSimpleType(java.lang.String name,
                                   SimpleType baseType)
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 SimpleType
baseType - the base type of the SimpleType to create
Returns:
the new SimpleType.

getAttributeFormDefault

public Form 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

public java.util.Enumeration getAttributes()
Returns an Enumeration of all top-level Attribute declarations

Returns:
an Enumeration of all top-level Attribute declarations

getAttribute

public AttributeDecl getAttribute(java.lang.String name)
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

public java.util.Enumeration getAttributeGroups()
Returns an Enumeration of all top-level AttributeGroup declarations

Returns:
an Enumeration of all top-level AttributeGroup declarations

getAttributeGroup

public AttributeGroup getAttributeGroup(java.lang.String name)
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

public BlockList getBlockDefault()
Returns the default BlockList for this Schema.

Returns:
the default BlockList for this Schema.

getBuiltInTypeName

public java.lang.String getBuiltInTypeName(int builtInTypeCode)
Gets a built in type's name given its code.


getComplexType

public ComplexType getComplexType(java.lang.String name)
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

public java.util.Enumeration getComplexTypes()
Returns an Enumeration of all top-level ComplexType declarations

Returns:
an Enumeration of all top-level ComplexType declarations

getElementDecl

public ElementDecl getElementDecl(java.lang.String name)
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

public java.util.Enumeration getElementDecls()
Returns an Enumeration of all top-level element declarations

Returns:
an Enumeration of all top-level element declarations

getElementFormDefault

public Form 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

public FinalList getFinalDefault()
Returns the default FinalList for this Schema.

Returns:
final the default FinalList for this Schema.

getSimpleType

public SimpleType getSimpleType(java.lang.String name)
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

public SimpleType getSimpleType(java.lang.String name,
                                java.lang.String namespace)
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

public java.util.Enumeration getSimpleTypes()
Returns an Enumeration of all SimpleType declarations

Returns:
an Enumeration of all SimpleType declarations

getSchemaLocation

public java.lang.String getSchemaLocation()
Returns the schemaLocation hint provided of this schema

Returns:
the schemaLocation hint provided of this schema

getModelGroup

public ModelGroup getModelGroup(java.lang.String name)
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

public java.util.Enumeration getModelGroups()
Returns an Enumeration of all top-level ModelGroup declarations

Returns:
an Enumeration of all top-level ModelGroup declarations

getId

public java.lang.String 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

public java.util.Enumeration getImportedSchema()
Returns the imported schemas of this schema

Returns:
the hashtable of the imported schemas

getImportedSchema

public Schema getImportedSchema(java.lang.String ns)
Returns an imported schema by its namespace

Returns:
The imported schema

getNamespace

public final java.lang.String getNamespace(java.lang.String prefix)
Returns the namespace associated with the given prefix.

Returns:
the namespace associated with the given prefix, or null if no associated namespace exists.

getNamespaces

public java.util.Hashtable getNamespaces()
Returns the namespaces declared for this Schema

Returns:
the namespaces declared for this Schema

addInclude

public void addInclude(java.lang.String include)
Indicates that the given XML Schema file has been processed via an


includeProcessed

public boolean includeProcessed(java.lang.String includeFile)
Returns True if the given XML Schema has already been included via

Returns:
True if the file specified has already been processed

getSchemaNamespace

public java.lang.String 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

public java.lang.String 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

public java.lang.String 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

public boolean isKnownNamespace(java.lang.String namespaceURL)
Returns True if the namespace is known to this schema

Returns:
True if the namespace was declared in the schema

removeComplexType

public boolean removeComplexType(ComplexType complexType)
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

public boolean removeElement(ElementDecl element)
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

public boolean removeAttribute(AttributeDecl attribute)
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

public boolean removeGroup(ModelGroup group)
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.

removeNamespace

public boolean removeNamespace(java.lang.String prefix)
Removes the namespace from the set of namespace declarations for this Schema definition.

Parameters:
prefix - the namespace prefix of the namespace to remove.

removeSimpleType

public boolean removeSimpleType(SimpleType simpleType)
Removes the given top level SimpleType from this Schema

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

public void setAttributeFormDefault(Form attributeFormDefault)
Sets the attributeFormDefault property of this Schema.

Parameters:
attributeFormDefault - the Form value of the attributeFormDefault property for this Schema.

setBlockDefault

public void setBlockDefault(BlockList block)
Sets the default BlockList for this Schema.

Parameters:
block - the default BlockList to set for this Schema.

setBlockDefault

public void setBlockDefault(java.lang.String block)
Sets the default Block values for this Schema.

Parameters:
block - the default Block values to set for this Schema.

setElementFormDefault

public void setElementFormDefault(Form elementFormDefault)
Sets the elementFormDefault property of this Schema.

Parameters:
elementFormDefault - the Form value of the elementFormDefault property for this Schema.

setFinalDefault

public void setFinalDefault(FinalList finalList)
Sets the default FinalList for this Schema.


setFinalDefault

public void setFinalDefault(java.lang.String finalValues)
Sets the default final values for this Schema.

Parameters:
finalValues - the default final values to set for this Schema.

setSchemaLocation

public void setSchemaLocation(java.lang.String schemaLocation)
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

public XMLType getType(java.lang.String typeName)
Returns the first simple or complex type which name equals TypeName


setId

public void setId(java.lang.String id)
Sets the Id for this Schema

Parameters:
id - the Id for this Schema

setTargetNamespace

public void setTargetNamespace(java.lang.String targetNamespace)
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

public void setVersion(java.lang.String version)
Sets the version information for the XML Schema defintion represented by this Schema instance.


getTypeFactory

static SimpleTypesFactory getTypeFactory()
Gets the type factory, package private


getStructureType

public short getStructureType()
Returns the type of this Schema Structure

Specified by:
getStructureType in class Structure
Returns:
the type of this Schema Structure

validate

public void validate()
              throws ValidationException
Checks the validity of this Schema defintion.

Specified by:
validate in class Structure
Throws:
ValidationException - when this Schema definition is invalid.

getNamespacePrefix

protected java.lang.String getNamespacePrefix(java.lang.String namespace)
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.


Intalio Inc. (C) 1999-2003. All rights reserved http://www.intalio.com