com.sun.msv.reader.xmlschema
Class XMLSchemaReader

java.lang.Object
  |
  +--org.xml.sax.helpers.XMLFilterImpl
        |
        +--com.sun.msv.reader.GrammarReader
              |
              +--com.sun.msv.reader.xmlschema.XMLSchemaReader
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler, IDContextProvider, ValidationContext, XMLFilter, XMLReader

public class XMLSchemaReader
extends GrammarReader

parses XML representation of XML Schema and constructs AGM.

Author:
Kohsuke KAWAGUCHI

Inner Class Summary
static interface XMLSchemaReader.RefResolver
           
static class XMLSchemaReader.StateFactory
          creates various State object, which in turn parses grammar.
 
Inner classes inherited from class com.sun.msv.reader.GrammarReader
GrammarReader.BackPatch, GrammarReader.BackwardReferenceMap, GrammarReader.ChainPrefixResolver, GrammarReader.PrefixResolver
 
Field Summary
 ComplexTypeExp complexUrType
          expression that matches to "ur-type" when used as a complex type.
 boolean doDuplicateDefinitionCheck
          a flag that indicates State objects should check duplicate definitions.
static String ERR_BAD_XPATH
           
static String ERR_DUPLICATE_ATTRIBUTE_DEFINITION
           
static String ERR_DUPLICATE_ATTRIBUTE_GROUP_DEFINITION
           
static String ERR_DUPLICATE_COMPLEXTYPE_DEFINITION
           
static String ERR_DUPLICATE_ELEMENT_DEFINITION
           
static String ERR_DUPLICATE_GROUP_DEFINITION
           
static String ERR_DUPLICATE_IDENTITY_CONSTRAINT_DEFINITION
           
static String ERR_DUPLICATE_SCHEMA_DEFINITION
           
static String ERR_IMPORTING_SAME_NAMESPACE
           
static String ERR_INCONSISTENT_TARGETNAMESPACE
           
static String ERR_KEY_FIELD_NUMBER_MISMATCH
           
static String ERR_KEYREF_REFERRING_NON_KEY
           
static String ERR_MAXOCCURS_IS_NECESSARY
           
static String ERR_RECURSIVE_SUBSTITUTION_GROUP
           
static String ERR_REDEFINE_UNDEFINED
           
static String ERR_UNDECLARED_PREFIX
           
static String ERR_UNDEFINED_ATTRIBUTE_DECL
           
static String ERR_UNDEFINED_ATTRIBUTE_GROUP
           
static String ERR_UNDEFINED_COMPLEX_TYPE
           
static String ERR_UNDEFINED_ELEMENT_DECL
           
static String ERR_UNDEFINED_ELEMENTTYPE
           
static String ERR_UNDEFINED_GROUP
           
static String ERR_UNDEFINED_KEY
           
static String ERR_UNDEFINED_OR_FORWARD_REFERENCED_TYPE
           
static String ERR_UNDEFINED_SCHEMA
           
static String ERR_UNDEFINED_SIMPLE_TYPE
           
static String ERR_UNIMPLEMENTED_FEATURE
           
static String ERR_UNRELATED_TYPES_IN_SUBSTITUTIONGROUP
           
 Expression nilExpression
          content model that matches to the use of "nil".
 Map parsedFiles
          tables that store all SystemIds that we've read.
 XMLSchemaReader.StateFactory sfactory
           
static String WRN_IMPLICIT_URTYPE_FOR_COMPLEXTYPE
           
static String WRN_IMPLICIT_URTYPE_FOR_ELEMENT
           
static String WRN_OBSOLETED_NAMESPACE
           
static String WRN_UNSUPPORTED_ANYELEMENT
           
static String XMLSchemaNamespace
          namespace URI of XML Schema declarations.
static String XMLSchemaNamespace_old
           
static String XMLSchemaSchemaLocationAttributes
           
 ReferenceExp xsiSchemaLocationExp
          content model that matches to optional xsi:schemaLocation or xsi:noNamespaceSchemaLocation.
 
Fields inherited from class com.sun.msv.reader.GrammarReader
backwardReference, basePrefixResolver, controller, ERR_BAD_ATTRIBUTE_VALUE, ERR_BAD_TYPE, ERR_CHARACTERS, ERR_CONFLICTING_ATTRIBUTES, ERR_DATATYPE_ALREADY_DEFINED, ERR_DISALLOWED_ATTRIBUTE, ERR_ILLEGAL_FINAL_VALUE, ERR_IO_EXCEPTION, ERR_MALPLACED_ELEMENT, ERR_MISSING_ATTRIBUTE, ERR_MISSING_ATTRIBUTE_2, ERR_MISSING_CHILD_EXPRESSION, ERR_MISSING_CHILD_TYPE, ERR_MISSING_TOPLEVEL, ERR_MORE_THAN_ONE_CHILD_EXPRESSION, ERR_MORE_THAN_ONE_CHILD_TYPE, ERR_RECURSIVE_DATATYPE, ERR_RECURSIVE_INCLUDE, ERR_RUNAWAY_EXPRESSION, ERR_SAX_EXCEPTION, ERR_UNDEFINED_DATATYPE, ERR_XMLPARSERFACTORY_EXCEPTION, hadError, locator, parserFactory, pool, prefixResolver, WRN_DEPRECATED_TYPENAME, WRN_MAYBE_WRONG_NAMESPACE
 
Constructor Summary
XMLSchemaReader(GrammarReaderController controller, javax.xml.parsers.SAXParserFactory parserFactory)
           
XMLSchemaReader(GrammarReaderController controller, javax.xml.parsers.SAXParserFactory parserFactory, XMLSchemaReader.StateFactory stateFactory, ExpressionPool pool)
           
 
Method Summary
 State createAttributeState(State parent, StartTagInfo tag)
          creates a state object that parses "attribute","attributeGroup ref", and "anyAttribute".
 State createExpressionChildState(State parent, StartTagInfo tag)
          this method must be implemented by the derived class to create language-default expresion state.
 State createFacetState(State parent, StartTagInfo tag)
           
 State createModelGroupState(State parent, StartTagInfo tag)
          creates a state object that parses "all"/"group ref"/"choice" and "sequence".
 XMLSchemaSchema getOrCreateSchema(String namespaceURI)
          gets a reference to XMLSchemaGrammar object whose target namespace is the specified one.
 XMLSchemaGrammar getResult()
           
 Grammar getResultAsGrammar()
          gets the parsed AGM.
 boolean isSchemaDefined(XMLSchemaSchema schema)
           
 boolean isSchemaNamespace(String ns)
           
 void markSchemaAsDefined(XMLSchemaSchema schema)
           
static XMLSchemaGrammar parse(InputSource grammar, javax.xml.parsers.SAXParserFactory factory, GrammarReaderController controller)
          loads XML Schema
static XMLSchemaGrammar parse(String grammarURL, javax.xml.parsers.SAXParserFactory factory, GrammarReaderController controller)
          loads XML Schema
 Expression processOccurs(StartTagInfo startTag, Expression item)
           
 Datatype resolveBuiltinDataType(String typeLocalName)
          resolves built-in datatypes (URI: http://www.w3.org/2001/XMLSchema)
 Datatype resolveDataType(String typeQName)
          gets DataType object from type name.
 Expression resolveDelayedDataType(String qName)
          gets a TypedString expression for the specified datatype.
 Expression resolveQNameRef(StartTagInfo tag, String attName, XMLSchemaReader.RefResolver resolver)
           
 
Methods inherited from class com.sun.msv.reader.GrammarReader
addBackPatchJob, combineURL, detectUndefinedOnes, endPrefixMapping, getBackwardCompatibleType, getCurrentState, getDeclaredLocationOf, isNotation, isUnparsedEntity, onID, onIDREF, parse, parse, popState, pushState, reportError, reportError, reportError, reportError, reportError, reportError, reportError, reportError, reportWarning, reportWarning, reportWarning, resolveLocation, resolveNamespacePrefix, setDeclaredLocationOf, setDocumentLocator, splitQName, startPrefixMapping, switchSource
 
Methods inherited from class org.xml.sax.helpers.XMLFilterImpl
characters, endDocument, endElement, error, fatalError, getContentHandler, getDTDHandler, getEntityResolver, getErrorHandler, getFeature, getParent, getProperty, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setContentHandler, setDTDHandler, setEntityResolver, setErrorHandler, setFeature, setParent, setProperty, skippedEntity, startDocument, startElement, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nilExpression

public final Expression nilExpression
content model that matches to the use of "nil".

xsiSchemaLocationExp

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

XMLSchemaSchemaLocationAttributes

public static final String XMLSchemaSchemaLocationAttributes

complexUrType

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

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

XMLSchemaNamespace

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

XMLSchemaNamespace_old

public static final String XMLSchemaNamespace_old

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_MAXOCCURS_IS_NECESSARY

public static final String ERR_MAXOCCURS_IS_NECESSARY

ERR_UNIMPLEMENTED_FEATURE

public static final String ERR_UNIMPLEMENTED_FEATURE

ERR_UNDECLARED_PREFIX

public static final String ERR_UNDECLARED_PREFIX

ERR_INCONSISTENT_TARGETNAMESPACE

public static final String ERR_INCONSISTENT_TARGETNAMESPACE

ERR_IMPORTING_SAME_NAMESPACE

public static final String ERR_IMPORTING_SAME_NAMESPACE

ERR_DUPLICATE_SCHEMA_DEFINITION

public static final String ERR_DUPLICATE_SCHEMA_DEFINITION

ERR_UNDEFINED_ELEMENTTYPE

public static final String ERR_UNDEFINED_ELEMENTTYPE

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_TYPE

public static final String ERR_UNDEFINED_COMPLEX_TYPE

ERR_UNDEFINED_SIMPLE_TYPE

public static final String ERR_UNDEFINED_SIMPLE_TYPE

ERR_UNDEFINED_ELEMENT_DECL

public static final String ERR_UNDEFINED_ELEMENT_DECL

ERR_UNDEFINED_GROUP

public static final String ERR_UNDEFINED_GROUP

ERR_UNDEFINED_SCHEMA

public static final String ERR_UNDEFINED_SCHEMA

WRN_UNSUPPORTED_ANYELEMENT

public static final String WRN_UNSUPPORTED_ANYELEMENT

WRN_OBSOLETED_NAMESPACE

public static final String WRN_OBSOLETED_NAMESPACE

ERR_UNDEFINED_OR_FORWARD_REFERENCED_TYPE

public static final String ERR_UNDEFINED_OR_FORWARD_REFERENCED_TYPE

ERR_REDEFINE_UNDEFINED

public static final String ERR_REDEFINE_UNDEFINED

ERR_DUPLICATE_ATTRIBUTE_DEFINITION

public static final String ERR_DUPLICATE_ATTRIBUTE_DEFINITION

ERR_DUPLICATE_COMPLEXTYPE_DEFINITION

public static final String ERR_DUPLICATE_COMPLEXTYPE_DEFINITION

ERR_DUPLICATE_ATTRIBUTE_GROUP_DEFINITION

public static final String ERR_DUPLICATE_ATTRIBUTE_GROUP_DEFINITION

ERR_DUPLICATE_GROUP_DEFINITION

public static final String ERR_DUPLICATE_GROUP_DEFINITION

ERR_DUPLICATE_ELEMENT_DEFINITION

public static final String ERR_DUPLICATE_ELEMENT_DEFINITION

ERR_DUPLICATE_IDENTITY_CONSTRAINT_DEFINITION

public static final String ERR_DUPLICATE_IDENTITY_CONSTRAINT_DEFINITION

ERR_BAD_XPATH

public static final String ERR_BAD_XPATH

ERR_UNDEFINED_KEY

public static final String ERR_UNDEFINED_KEY

ERR_KEY_FIELD_NUMBER_MISMATCH

public static final String ERR_KEY_FIELD_NUMBER_MISMATCH

ERR_KEYREF_REFERRING_NON_KEY

public static final String ERR_KEYREF_REFERRING_NON_KEY

ERR_UNRELATED_TYPES_IN_SUBSTITUTIONGROUP

public static final String ERR_UNRELATED_TYPES_IN_SUBSTITUTIONGROUP

ERR_RECURSIVE_SUBSTITUTION_GROUP

public static final String ERR_RECURSIVE_SUBSTITUTION_GROUP

WRN_IMPLICIT_URTYPE_FOR_ELEMENT

public static final String WRN_IMPLICIT_URTYPE_FOR_ELEMENT

WRN_IMPLICIT_URTYPE_FOR_COMPLEXTYPE

public static final String WRN_IMPLICIT_URTYPE_FOR_COMPLEXTYPE
Constructor Detail

XMLSchemaReader

public XMLSchemaReader(GrammarReaderController controller,
                       javax.xml.parsers.SAXParserFactory parserFactory)

XMLSchemaReader

public XMLSchemaReader(GrammarReaderController controller,
                       javax.xml.parsers.SAXParserFactory parserFactory,
                       XMLSchemaReader.StateFactory stateFactory,
                       ExpressionPool pool)
Method Detail

parse

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

parse

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

getResult

public final XMLSchemaGrammar getResult()

getResultAsGrammar

public Grammar getResultAsGrammar()
Description copied from class: GrammarReader
gets the parsed AGM. Should any error happens, this method returns null. derived classes should implement type-safe getGrammar method, along with this method.
Overrides:
getResultAsGrammar in class GrammarReader

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.

createExpressionChildState

public State createExpressionChildState(State parent,
                                        StartTagInfo tag)
Description copied from class: GrammarReader
this method must be implemented by the derived class to create language-default expresion state.
Overrides:
createExpressionChildState in class GrammarReader
Following copied from class: com.sun.msv.reader.GrammarReader
Returns:
null if the start tag is an error.

createModelGroupState

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

createAttributeState

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

createFacetState

public State createFacetState(State parent,
                              StartTagInfo tag)

markSchemaAsDefined

public final void markSchemaAsDefined(XMLSchemaSchema schema)

isSchemaDefined

public final boolean isSchemaDefined(XMLSchemaSchema schema)

resolveBuiltinDataType

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

isSchemaNamespace

public boolean isSchemaNamespace(String ns)

resolveDataType

public Datatype resolveDataType(String typeQName)
Description copied from class: GrammarReader
gets DataType object from type name. If undefined type name is specified, this method is responsible to report an error, and recover.
Overrides:
resolveDataType in class GrammarReader
Following copied from class: com.sun.msv.reader.GrammarReader
Parameters:
typeName - For RELAX, this is unqualified type name. For TREX, this is a QName.

resolveDelayedDataType

public Expression resolveDelayedDataType(String qName)
gets a TypedString expression for the specified datatype. this method may return a ReferenceExp whose content will be supplied later (to make forward-reference possible).

resolveQNameRef

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

processOccurs

public Expression processOccurs(StartTagInfo startTag,
                                Expression item)