org.apache.ws.commons.schema
Class XmlSchema

java.lang.Object
  extended by org.apache.ws.commons.schema.XmlSchemaObject
      extended by org.apache.ws.commons.schema.XmlSchemaAnnotated
          extended by org.apache.ws.commons.schema.XmlSchema
All Implemented Interfaces:
NamespaceContextOwner, XmlSchemaObjectBase

public class XmlSchema
extends XmlSchemaAnnotated
implements NamespaceContextOwner

Contains the definition of a schema. All XML Schema definition language (XSD) elements are children of the schema element.


Constructor Summary
XmlSchema()
          Create a schema that is not a member of a collection and has no target namespace or system ID.
XmlSchema(String namespace, String systemId, XmlSchemaCollection parent)
          Create a new schema with a target namespace and system ID, and record it as a member of a schema collection.
XmlSchema(String namespace, XmlSchemaCollection parent)
          Create a new schema in a collection with a target namespace.
 
Method Summary
 Document[] getAllSchemas()
          Return an array of DOM documents consisting of this schema and any schemas that it references.
 XmlSchemaAttribute getAttributeByName(QName name)
          Retrieve a global attribute by its QName.
protected  XmlSchemaAttribute getAttributeByName(QName name, boolean deep, Stack<XmlSchema> schemaStack)
           
 XmlSchemaAttribute getAttributeByName(String name)
          Look for an attribute by its local name.
 XmlSchemaForm getAttributeFormDefault()
           
 XmlSchemaAttributeGroup getAttributeGroupByName(QName name)
          Retrieve an attribute group by QName.
protected  XmlSchemaAttributeGroup getAttributeGroupByName(QName name, boolean deep, Stack<XmlSchema> schemaStack)
           
 Map<QName,XmlSchemaAttributeGroup> getAttributeGroups()
          Return a map containing all the defined attribute groups of this schema.
 Map<QName,XmlSchemaAttribute> getAttributes()
          Return a map containing all the defined attributes of this schema.
 XmlSchemaDerivationMethod getBlockDefault()
          Return the default block value for this schema.
 XmlSchemaElement getElementByName(QName name)
          Look for a element by its QName.
protected  XmlSchemaElement getElementByName(QName name, boolean deep, Stack<XmlSchema> schemaStack)
           
 XmlSchemaElement getElementByName(String name)
          get an element by its local name.
 XmlSchemaForm getElementFormDefault()
           
 Map<QName,XmlSchemaElement> getElements()
          Return a map containing all the defined elements of this schema.
 List<XmlSchemaExternal> getExternals()
          Return all of the includes, imports, and redefines for this schema.
 XmlSchemaDerivationMethod getFinalDefault()
           
 XmlSchemaGroup getGroupByName(QName name)
          Retrieve a group by QName.
protected  XmlSchemaGroup getGroupByName(QName name, boolean deep, Stack<XmlSchema> schemaStack)
           
 Map<QName,XmlSchemaGroup> getGroups()
          Return a map containing all the defined groups of this schema.
 String getInputEncoding()
          Return the character encoding for this schema.
 List<XmlSchemaObject> getItems()
          Return all of the global items in this schema.
If org.apache.ws.commons.schema.protectReadOnlyCollections is 'true', this will return a map that checks at runtime.
 String getLogicalTargetNamespace()
          Return the logical target namespace.
 NamespacePrefixList getNamespaceContext()
          Returns the objects namespace context.
 XmlSchemaNotation getNotationByName(QName name)
          Retrieve a notation by QName.
protected  XmlSchemaNotation getNotationByName(QName name, boolean deep, Stack<XmlSchema> schemaStack)
           
 Map<QName,XmlSchemaNotation> getNotations()
          Return a map containing all the defined notations of this schema.
 XmlSchemaCollection getParent()
          Return the parent XmlSchemaCollection.
 Document getSchemaDocument()
          Retrieve a DOM tree for this one schema, independent of any included or related schemas.
 String getSchemaNamespacePrefix()
           
 Map<QName,XmlSchemaType> getSchemaTypes()
          Return a map containing all the defined types of this schema.
 String getTargetNamespace()
          Return the declared target namespace of this schema.
 XmlSchemaType getTypeByName(QName name)
          Search this schema, and its peers in its parent collection, for a schema type specified by QName.
protected  XmlSchemaType getTypeByName(QName name, boolean deep, Stack<XmlSchema> schemaStack)
          Protected method that allows safe (non-recursive schema loading).
 XmlSchemaType getTypeByName(String name)
          Retrieve a named type from this schema.
 String getVersion()
          Return the declared XML Schema version of this schema.
 void setAttributeFormDefault(XmlSchemaForm value)
          Set the default attribute form for this schema.
 void setBlockDefault(XmlSchemaDerivationMethod blockDefault)
          Set the default block value for this schema.
 void setElementFormDefault(XmlSchemaForm elementFormDefault)
          Set the default element form for this schema.
 void setFinalDefault(XmlSchemaDerivationMethod finalDefault)
          Set the default 'final' value for this schema.
 void setInputEncoding(String encoding)
          Set the character encoding name for the schema.
 void setNamespaceContext(NamespacePrefixList namespaceContext)
          Sets the schema elements namespace context.
 void setSchemaNamespacePrefix(String schemaNamespacePrefix)
          Set the namespace prefix corresponding to the target namespace.
 void setTargetNamespace(String targetNamespace)
          Set the target namespace for this schema.
 String toString()
           
 void write(OutputStream out)
          Serialize the schema as XML to the specified stream using the encoding established with setInputEncoding(String).
 void write(OutputStream out, Map<String,String> options)
          Serialize the schema as XML to the specified stream using the encoding established with setInputEncoding(String).
 void write(Writer writer)
          Serialize the schema to a Writer.
 void write(Writer writer, Map<String,String> options)
          Serialize the schema to a Writer.
 
Methods inherited from class org.apache.ws.commons.schema.XmlSchemaAnnotated
getAnnotation, getId, getUnhandledAttributes, setAnnotation, setId, setUnhandledAttributes
 
Methods inherited from class org.apache.ws.commons.schema.XmlSchemaObject
addMetaInfo, equals, getLineNumber, getLinePosition, getMetaInfoMap, getSourceURI, hashCode, setLineNumber, setLinePosition, setMetaInfoMap, setSourceURI
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XmlSchema

public XmlSchema()
Create a schema that is not a member of a collection and has no target namespace or system ID.


XmlSchema

public XmlSchema(String namespace,
                 String systemId,
                 XmlSchemaCollection parent)
Create a new schema with a target namespace and system ID, and record it as a member of a schema collection.

Parameters:
namespace - the target namespace.
systemId - the system ID for the schema. This is used to resolve references to other schemas.
parent - the parent collection.

XmlSchema

public XmlSchema(String namespace,
                 XmlSchemaCollection parent)
Create a new schema in a collection with a target namespace.

Parameters:
namespace - the target namespace.
parent - the containing collection.
Method Detail

getAllSchemas

public Document[] getAllSchemas()
Return an array of DOM documents consisting of this schema and any schemas that it references. Referenced schemas are only returned if the XmlSchemaExternal objects corresponding to them have their 'schema' fields filled in.

Returns:
DOM documents.

getAttributeByName

public XmlSchemaAttribute getAttributeByName(QName name)
Retrieve a global attribute by its QName.

Parameters:
name -
Returns:
the attribute.

getAttributeByName

public XmlSchemaAttribute getAttributeByName(String name)
Look for an attribute by its local name.

Parameters:
name -
Returns:
the attribute

getAttributeFormDefault

public XmlSchemaForm getAttributeFormDefault()
Returns:
the default attribute form for this schema.

getAttributeGroupByName

public XmlSchemaAttributeGroup getAttributeGroupByName(QName name)
Retrieve an attribute group by QName.

Parameters:
name -
Returns:

getAttributeGroups

public Map<QName,XmlSchemaAttributeGroup> getAttributeGroups()
Return a map containing all the defined attribute groups of this schema. The keys are QNames, where the namespace will always be the target namespace of this schema. This makes it easier to look up items for cross-schema references.
If org.apache.ws.commons.schema.protectReadOnlyCollections is 'true', this will return a map that checks at runtime.

Returns:
the map of attribute groups.

getAttributes

public Map<QName,XmlSchemaAttribute> getAttributes()
Return a map containing all the defined attributes of this schema. The keys are QNames, where the namespace will always be the target namespace of this schema. This makes it easier to look up items for cross-schema references.
If org.apache.ws.commons.schema.protectReadOnlyCollections is 'true', this will return a map that checks at runtime.

Returns:
the map of attributes.

getBlockDefault

public XmlSchemaDerivationMethod getBlockDefault()
Return the default block value for this schema.

Returns:
the default block value.

getElementByName

public XmlSchemaElement getElementByName(QName name)
Look for a element by its QName.

Parameters:
name -
Returns:
the element.

getElementByName

public XmlSchemaElement getElementByName(String name)
get an element by its local name.

Parameters:
name -
Returns:
the element.

getElementFormDefault

public XmlSchemaForm getElementFormDefault()
Returns:
the default element form for this schema.

getElements

public Map<QName,XmlSchemaElement> getElements()
Return a map containing all the defined elements of this schema. The keys are QNames, where the namespace will always be the target namespace of this schema. This makes it easier to look up items for cross-schema references.
If org.apache.ws.commons.schema.protectReadOnlyCollections is 'true', this will return a map that checks at runtime

Returns:
the map of elements.

getExternals

public List<XmlSchemaExternal> getExternals()
Return all of the includes, imports, and redefines for this schema.
If org.apache.ws.commons.schema.protectReadOnlyCollections is 'true', this will return a list that checks at runtime

Returns:
a list of the objects representing includes, imports, and redefines.

getFinalDefault

public XmlSchemaDerivationMethod getFinalDefault()
Returns:
the default 'final' value for this schema.

getGroupByName

public XmlSchemaGroup getGroupByName(QName name)
Retrieve a group by QName.

Parameters:
name -
Returns:

getGroups

public Map<QName,XmlSchemaGroup> getGroups()
Return a map containing all the defined groups of this schema. The keys are QNames, where the namespace will always be the target namespace of this schema. This makes it easier to look up items for cross-schema references.
If org.apache.ws.commons.schema.protectReadOnlyCollections is 'true', this will return a map that checks at runtime

Returns:
the map of groups.

getInputEncoding

public String getInputEncoding()
Return the character encoding for this schema. This will only be present if either the schema was read from an XML document or there was a call to setInputEncoding(String).

Returns:

getItems

public List<XmlSchemaObject> getItems()
Return all of the global items in this schema.
If org.apache.ws.commons.schema.protectReadOnlyCollections is 'true', this will return a map that checks at runtime.

Returns:
all of the global items from this schema.

getLogicalTargetNamespace

public String getLogicalTargetNamespace()
Return the logical target namespace. If a schema document has no target namespace, but it is referenced via an xs:include or xs:redefine, its logical target namespace is the target namespace of the including schema.

Returns:
the logical target namespace.

getNamespaceContext

public NamespacePrefixList getNamespaceContext()
Returns the objects namespace context.

Specified by:
getNamespaceContext in interface NamespaceContextOwner

getNotationByName

public XmlSchemaNotation getNotationByName(QName name)
Retrieve a notation by QName.

Parameters:
name -
Returns:
the notation

getNotations

public Map<QName,XmlSchemaNotation> getNotations()
Return a map containing all the defined notations of this schema. The keys are QNames, where the namespace will always be the target namespace of this schema. This makes it easier to look up items for cross-schema references.
If org.apache.ws.commons.schema.protectReadOnlyCollections is 'true', this will return a map that checks at runtime.

Returns:
the map of notations.

getParent

public XmlSchemaCollection getParent()
Return the parent XmlSchemaCollection. If this schema was not initialized in a collection the return value will be null.

Returns:
the parent collection.

getSchemaDocument

public Document getSchemaDocument()
                           throws XmlSchemaSerializer.XmlSchemaSerializerException
Retrieve a DOM tree for this one schema, independent of any included or related schemas.

Returns:
The DOM document.
Throws:
XmlSchemaSerializer.XmlSchemaSerializerException

getSchemaNamespacePrefix

public String getSchemaNamespacePrefix()
Returns:
the namespace prefix for the target namespace.

getSchemaTypes

public Map<QName,XmlSchemaType> getSchemaTypes()
Return a map containing all the defined types of this schema. The keys are QNames, where the namespace will always be the target namespace of this schema. This makes it easier to look up items for cross-schema references.

Returns:
the map of types.

getTargetNamespace

public String getTargetNamespace()
Return the declared target namespace of this schema.

Returns:
the namespace URI.
See Also:
getLogicalTargetNamespace()

getTypeByName

public XmlSchemaType getTypeByName(QName name)
Search this schema, and its peers in its parent collection, for a schema type specified by QName.

Parameters:
name - the type name.
Returns:
the type.

getTypeByName

public XmlSchemaType getTypeByName(String name)
Retrieve a named type from this schema.

Parameters:
name -
Returns:
the type.

getVersion

public String getVersion()
Return the declared XML Schema version of this schema. XmlSchema supports only version 1.0.

Returns:

setAttributeFormDefault

public void setAttributeFormDefault(XmlSchemaForm value)
Set the default attribute form for this schema.

Parameters:
value - the form. This may not be null.

setBlockDefault

public void setBlockDefault(XmlSchemaDerivationMethod blockDefault)
Set the default block value for this schema.

Parameters:
blockDefault - the new block value.

setElementFormDefault

public void setElementFormDefault(XmlSchemaForm elementFormDefault)
Set the default element form for this schema.

Parameters:
elementFormDefault - the element form. This may not be null.

setFinalDefault

public void setFinalDefault(XmlSchemaDerivationMethod finalDefault)
Set the default 'final' value for this schema. The value may not be null.

Parameters:
finalDefault - the new final value.

setInputEncoding

public void setInputEncoding(String encoding)
Set the character encoding name for the schema. This is typically set when reading a schema from an XML file, so that it can be written back out in the same encoding.

Parameters:
encoding - Character encoding name.

setNamespaceContext

public void setNamespaceContext(NamespacePrefixList namespaceContext)
Sets the schema elements namespace context. This may be used for schema serialization, until a better mechanism was found.


setSchemaNamespacePrefix

public void setSchemaNamespacePrefix(String schemaNamespacePrefix)
Set the namespace prefix corresponding to the target namespace.

Parameters:
schemaNamespacePrefix -

setTargetNamespace

public void setTargetNamespace(String targetNamespace)
Set the target namespace for this schema.

Parameters:
targetNamespace - the new target namespace URI. A value of "" is ignored.

toString

public String toString()
Overrides:
toString in class XmlSchemaAnnotated

write

public void write(OutputStream out)
           throws UnsupportedEncodingException
Serialize the schema as XML to the specified stream using the encoding established with setInputEncoding(String).

Parameters:
out - - the output stream to write to
Throws:
UnsupportedEncodingException - for an invalid encoding.

write

public void write(OutputStream out,
                  Map<String,String> options)
           throws UnsupportedEncodingException
Serialize the schema as XML to the specified stream using the encoding established with setInputEncoding(String).

Parameters:
out - - the output stream to write to
options - - a map of options
Throws:
UnsupportedEncodingException

write

public void write(Writer writer)
Serialize the schema to a Writer.

Parameters:
writer - - the writer to write this

write

public void write(Writer writer,
                  Map<String,String> options)
Serialize the schema to a Writer.

Parameters:
writer - - the writer to write this

getAttributeByName

protected XmlSchemaAttribute getAttributeByName(QName name,
                                                boolean deep,
                                                Stack<XmlSchema> schemaStack)

getAttributeGroupByName

protected XmlSchemaAttributeGroup getAttributeGroupByName(QName name,
                                                          boolean deep,
                                                          Stack<XmlSchema> schemaStack)

getElementByName

protected XmlSchemaElement getElementByName(QName name,
                                            boolean deep,
                                            Stack<XmlSchema> schemaStack)

getGroupByName

protected XmlSchemaGroup getGroupByName(QName name,
                                        boolean deep,
                                        Stack<XmlSchema> schemaStack)

getNotationByName

protected XmlSchemaNotation getNotationByName(QName name,
                                              boolean deep,
                                              Stack<XmlSchema> schemaStack)

getTypeByName

protected XmlSchemaType getTypeByName(QName name,
                                      boolean deep,
                                      Stack<XmlSchema> schemaStack)
Protected method that allows safe (non-recursive schema loading). It looks for a type with constraints.

Parameters:
name -
deep -
schemaStack -
Returns:
the type.


Copyright © 2004-2015 The Apache Software Foundation. All Rights Reserved.