com.sun.msv.reader.xmlschema

Class XMLSchemaReader

public class XMLSchemaReader extends GrammarReader implements XSDatatypeResolver

parses XML representation of XML Schema and constructs AGM.

Author: Kohsuke KAWAGUCHI

Nested Class Summary
static interfaceXMLSchemaReader.RefResolver
static classXMLSchemaReader.StateFactory
creates various State object, which in turn parses grammar. parsing behavior can be customized by implementing custom StateFactory.
Field Summary
ComplexTypeExpcomplexUrType
expression that matches to "ur-type" when used as a complex type.
booleandoDuplicateDefinitionCheck
a flag that indicates State objects should check duplicate definitions.
static StringERR_BAD_XPATH
static StringERR_DUPLICATE_ATTRIBUTE_DEFINITION
static StringERR_DUPLICATE_ATTRIBUTE_GROUP_DEFINITION
static StringERR_DUPLICATE_COMPLEXTYPE_DEFINITION
static StringERR_DUPLICATE_ELEMENT_DEFINITION
static StringERR_DUPLICATE_GROUP_DEFINITION
static StringERR_DUPLICATE_IDENTITY_CONSTRAINT_DEFINITION
static StringERR_DUPLICATE_SCHEMA_DEFINITION
static StringERR_IMPORTING_SAME_NAMESPACE
static StringERR_INCONSISTENT_TARGETNAMESPACE
static StringERR_INVALID_BASETYPE_FOR_SIMPLECONTENT
static StringERR_KEYREF_REFERRING_NON_KEY
static StringERR_KEY_FIELD_NUMBER_MISMATCH
static StringERR_MAXOCCURS_IS_NECESSARY
static StringERR_RECURSIVE_SUBSTITUTION_GROUP
static StringERR_REDEFINE_UNDEFINED
static StringERR_UNDECLARED_PREFIX
static StringERR_UNDEFINED_ATTRIBUTE_DECL
static StringERR_UNDEFINED_ATTRIBUTE_GROUP
static StringERR_UNDEFINED_COMPLEX_OR_SIMPLE_TYPE
static StringERR_UNDEFINED_COMPLEX_TYPE
static StringERR_UNDEFINED_ELEMENTTYPE
static StringERR_UNDEFINED_ELEMENT_DECL
static StringERR_UNDEFINED_GROUP
static StringERR_UNDEFINED_KEY
static StringERR_UNDEFINED_OR_FORWARD_REFERENCED_TYPE
static StringERR_UNDEFINED_SCHEMA
static StringERR_UNDEFINED_SIMPLE_TYPE
static StringERR_UNIMPLEMENTED_FEATURE
static StringERR_UNRELATED_TYPES_IN_SUBSTITUTIONGROUP
MapparsedFiles
tables that store all SystemIds that we've read. map from target namespace URI to set of system ids.
XMLSchemaReader.StateFactorysfactory
static StringWRN_IMPLICIT_URTYPE_FOR_ELEMENT
static StringWRN_OBSOLETED_NAMESPACE
static StringWRN_UNSUPPORTED_ANYELEMENT
ReferenceExpxsiSchemaLocationExp
content model that matches to optional xsi:schemaLocation or xsi:noNamespaceSchemaLocation.
static StringXMLSchemaNamespace
namespace URI of XML Schema declarations.
static StringXMLSchemaNamespace_old
static StringXMLSchemaSchemaLocationAttributes
Constructor Summary
XMLSchemaReader(GrammarReaderController controller)
easy-to-use constructor.
XMLSchemaReader(GrammarReaderController controller, SAXParserFactory parserFactory)
XMLSchemaReader(GrammarReaderController controller, SAXParserFactory parserFactory, ExpressionPool pool)
XMLSchemaReader(GrammarReaderController controller, SAXParserFactory parserFactory, XMLSchemaReader.StateFactory stateFactory, ExpressionPool pool)
Method Summary
StatecreateAttributeState(State parent, StartTagInfo tag)
creates a state object that parses "attribute","attributeGroup ref", and "anyAttribute".
StatecreateExpressionChildState(State parent, StartTagInfo tag)
StatecreateFacetState(State parent, StartTagInfo tag)
StatecreateModelGroupState(State parent, StartTagInfo tag)
creates a state object that parses "all"/"group ref"/"choice" and "sequence".
XMLSchemaSchemagetOrCreateSchema(String namespaceURI)
gets a reference to XMLSchemaGrammar object whose target namespace is the specified one.
XMLSchemaGrammargetResult()
GrammargetResultAsGrammar()
static SchemagetXmlSchemaForXmlSchema()
booleanisSchemaDefined(XMLSchemaSchema schema)
booleanisSchemaNamespace(String ns)
voidmarkSchemaAsDefined(XMLSchemaSchema schema)
static XMLSchemaGrammarparse(String grammarURL, SAXParserFactory factory, GrammarReaderController controller)
loads XML Schema
static XMLSchemaGrammarparse(InputSource grammar, SAXParserFactory factory, GrammarReaderController controller)
loads XML Schema
ExpressionprocessOccurs(StartTagInfo startTag, Expression item)
Adds maxOccurs/minOccurs semantics to a given expression.
ExpressionprocessOccurs(Expression item, int minOccurs, int maxOccurs)
Adds maxOccurs/minOccurs semantics to a given expression.
XSDatatyperesolveBuiltinDataType(String typeLocalName)
resolves built-in datatypes (URI: http://www.w3.org/2001/XMLSchema)
SimpleTypeExpresolveBuiltinSimpleType(String typeLocalName)
Gets a built-in datatype as SimpleTypeExp.
ExpressionresolveQNameRef(StartTagInfo tag, String attName, XMLSchemaReader.RefResolver resolver)
XSDatatypeExpresolveXSDatatype(String typeQName)
Resolves a simple type name into the corresponding XSDatatypeExp object.
String[]splitQName(String qName)
Resolves a QName into a pair of (namespace URI,local name).

Field Detail

complexUrType

public final ComplexTypeExp complexUrType
expression that matches to "ur-type" when used as a complex type.

doDuplicateDefinitionCheck

public boolean doDuplicateDefinitionCheck
a flag that indicates State objects should check duplicate definitions. This flag is set to false when in <redefine>. Otherwise this flag is true.

ERR_BAD_XPATH

public static final String ERR_BAD_XPATH

ERR_DUPLICATE_ATTRIBUTE_DEFINITION

public static final String ERR_DUPLICATE_ATTRIBUTE_DEFINITION

ERR_DUPLICATE_ATTRIBUTE_GROUP_DEFINITION

public static final String ERR_DUPLICATE_ATTRIBUTE_GROUP_DEFINITION

ERR_DUPLICATE_COMPLEXTYPE_DEFINITION

public static final String ERR_DUPLICATE_COMPLEXTYPE_DEFINITION

ERR_DUPLICATE_ELEMENT_DEFINITION

public static final String ERR_DUPLICATE_ELEMENT_DEFINITION

ERR_DUPLICATE_GROUP_DEFINITION

public static final String ERR_DUPLICATE_GROUP_DEFINITION

ERR_DUPLICATE_IDENTITY_CONSTRAINT_DEFINITION

public static final String ERR_DUPLICATE_IDENTITY_CONSTRAINT_DEFINITION

ERR_DUPLICATE_SCHEMA_DEFINITION

public static final String ERR_DUPLICATE_SCHEMA_DEFINITION

ERR_IMPORTING_SAME_NAMESPACE

public static final String ERR_IMPORTING_SAME_NAMESPACE

ERR_INCONSISTENT_TARGETNAMESPACE

public static final String ERR_INCONSISTENT_TARGETNAMESPACE

ERR_INVALID_BASETYPE_FOR_SIMPLECONTENT

public static final String ERR_INVALID_BASETYPE_FOR_SIMPLECONTENT

ERR_KEYREF_REFERRING_NON_KEY

public static final String ERR_KEYREF_REFERRING_NON_KEY

ERR_KEY_FIELD_NUMBER_MISMATCH

public static final String ERR_KEY_FIELD_NUMBER_MISMATCH

ERR_MAXOCCURS_IS_NECESSARY

public static final String ERR_MAXOCCURS_IS_NECESSARY

ERR_RECURSIVE_SUBSTITUTION_GROUP

public static final String ERR_RECURSIVE_SUBSTITUTION_GROUP

ERR_REDEFINE_UNDEFINED

public static final String ERR_REDEFINE_UNDEFINED

ERR_UNDECLARED_PREFIX

public static final String ERR_UNDECLARED_PREFIX

ERR_UNDEFINED_ATTRIBUTE_DECL

public static final String ERR_UNDEFINED_ATTRIBUTE_DECL

ERR_UNDEFINED_ATTRIBUTE_GROUP

public static final String ERR_UNDEFINED_ATTRIBUTE_GROUP

ERR_UNDEFINED_COMPLEX_OR_SIMPLE_TYPE

public static final String ERR_UNDEFINED_COMPLEX_OR_SIMPLE_TYPE

ERR_UNDEFINED_COMPLEX_TYPE

public static final String ERR_UNDEFINED_COMPLEX_TYPE

ERR_UNDEFINED_ELEMENTTYPE

public static final String ERR_UNDEFINED_ELEMENTTYPE

ERR_UNDEFINED_ELEMENT_DECL

public static final String ERR_UNDEFINED_ELEMENT_DECL

ERR_UNDEFINED_GROUP

public static final String ERR_UNDEFINED_GROUP

ERR_UNDEFINED_KEY

public static final String ERR_UNDEFINED_KEY

ERR_UNDEFINED_OR_FORWARD_REFERENCED_TYPE

public static final String ERR_UNDEFINED_OR_FORWARD_REFERENCED_TYPE

ERR_UNDEFINED_SCHEMA

public static final String ERR_UNDEFINED_SCHEMA

ERR_UNDEFINED_SIMPLE_TYPE

public static final String ERR_UNDEFINED_SIMPLE_TYPE

ERR_UNIMPLEMENTED_FEATURE

public static final String ERR_UNIMPLEMENTED_FEATURE

ERR_UNRELATED_TYPES_IN_SUBSTITUTIONGROUP

public static final String ERR_UNRELATED_TYPES_IN_SUBSTITUTIONGROUP

parsedFiles

public final Map parsedFiles
tables that store all SystemIds that we've read. map from target namespace URI to set of system ids. This field is used to prevent double inclusion. Strictly speaking, comparision based on system id is not enough. The spec calls for "the necessity of establishing identity component by component" (section 4.2.1, last note).

sfactory

public final XMLSchemaReader.StateFactory sfactory

WRN_IMPLICIT_URTYPE_FOR_ELEMENT

public static final String WRN_IMPLICIT_URTYPE_FOR_ELEMENT

WRN_OBSOLETED_NAMESPACE

public static final String WRN_OBSOLETED_NAMESPACE

WRN_UNSUPPORTED_ANYELEMENT

public static final String WRN_UNSUPPORTED_ANYELEMENT

xsiSchemaLocationExp

public final ReferenceExp xsiSchemaLocationExp
content model that matches to optional xsi:schemaLocation or xsi:noNamespaceSchemaLocation.

XMLSchemaNamespace

public static final String XMLSchemaNamespace
namespace URI of XML Schema declarations.

XMLSchemaNamespace_old

public static final String XMLSchemaNamespace_old

XMLSchemaSchemaLocationAttributes

public static final String XMLSchemaSchemaLocationAttributes

Constructor Detail

XMLSchemaReader

public XMLSchemaReader(GrammarReaderController controller)
easy-to-use constructor.

XMLSchemaReader

public XMLSchemaReader(GrammarReaderController controller, SAXParserFactory parserFactory)

XMLSchemaReader

public XMLSchemaReader(GrammarReaderController controller, SAXParserFactory parserFactory, ExpressionPool pool)

XMLSchemaReader

public XMLSchemaReader(GrammarReaderController controller, SAXParserFactory parserFactory, XMLSchemaReader.StateFactory stateFactory, ExpressionPool pool)

Method Detail

createAttributeState

public State createAttributeState(State parent, StartTagInfo tag)
creates a state object that parses "attribute","attributeGroup ref", and "anyAttribute".

createExpressionChildState

public State createExpressionChildState(State parent, StartTagInfo tag)

createFacetState

public State createFacetState(State parent, StartTagInfo tag)

createModelGroupState

public State createModelGroupState(State parent, StartTagInfo tag)
creates a state object that parses "all"/"group ref"/"choice" and "sequence".

getOrCreateSchema

public XMLSchemaSchema getOrCreateSchema(String namespaceURI)
gets a reference to XMLSchemaGrammar object whose target namespace is the specified one. If there is no such object, this method creates a new instance and returns it.

getResult

public final XMLSchemaGrammar getResult()

getResultAsGrammar

public Grammar getResultAsGrammar()

getXmlSchemaForXmlSchema

public static Schema getXmlSchemaForXmlSchema()

isSchemaDefined

public final boolean isSchemaDefined(XMLSchemaSchema schema)

isSchemaNamespace

public boolean isSchemaNamespace(String ns)

markSchemaAsDefined

public final void markSchemaAsDefined(XMLSchemaSchema schema)

parse

public static XMLSchemaGrammar parse(String grammarURL, SAXParserFactory factory, GrammarReaderController controller)
loads XML Schema

parse

public static XMLSchemaGrammar parse(InputSource grammar, SAXParserFactory factory, GrammarReaderController controller)
loads XML Schema

processOccurs

public Expression processOccurs(StartTagInfo startTag, Expression item)
Adds maxOccurs/minOccurs semantics to a given expression. For example, if this method receives A, minOccurs=0, and maxOccurs=3, then this method should return something like (A,(A,A?)?)?

processOccurs

public Expression processOccurs(Expression item, int minOccurs, int maxOccurs)
Adds maxOccurs/minOccurs semantics to a given expression.

Parameters: maxOccurs -1 to represent "unbounded".

resolveBuiltinDataType

public XSDatatype resolveBuiltinDataType(String typeLocalName)
resolves built-in datatypes (URI: http://www.w3.org/2001/XMLSchema)

Returns: null if the type is not defined.

resolveBuiltinSimpleType

public SimpleTypeExp resolveBuiltinSimpleType(String typeLocalName)
Gets a built-in datatype as SimpleTypeExp.

Returns: null if the type is not defined.

resolveQNameRef

public Expression resolveQNameRef(StartTagInfo tag, String attName, XMLSchemaReader.RefResolver resolver)

resolveXSDatatype

public XSDatatypeExp resolveXSDatatype(String typeQName)
Resolves a simple type name into the corresponding XSDatatypeExp object.

splitQName

public String[] splitQName(String qName)
Resolves a QName into a pair of (namespace URI,local name).

When we are parsing a "chameleon schema", any reference to the default empty namespace("") has to be treated as a reference to the intended target namespace.