Class NGCCRuntimeEx
- java.lang.Object
-
- com.sun.xml.xsom.impl.parser.state.NGCCRuntime
-
- com.sun.xml.xsom.impl.parser.NGCCRuntimeEx
-
- All Implemented Interfaces:
PatcherManager,NGCCEventSource,org.xml.sax.ContentHandler
public class NGCCRuntimeEx extends NGCCRuntime implements PatcherManager
NGCCRuntime extended with various utility methods for parsing XML Schema.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classNGCCRuntimeEx.Context-
Nested classes/interfaces inherited from interface com.sun.xml.xsom.impl.parser.PatcherManager
PatcherManager.Patcher
-
-
Field Summary
Fields Modifier and Type Field Description booleanattributeFormDefaultThe @attributeFormDefault value of the current schema.intblockDefaultThe @blockDefault value of the current schema.booleanchameleonModeTrue if the current schema is in a chameleon mode.private NGCCRuntimeEx.ContextcurrentContextSchemaImplcurrentSchemaThe schema currently being parsed.SchemaDocumentImpldocumentPoints to theSchemaDocumentImplthat represents the schema document being parsed.private java.lang.StringdocumentSystemIdURI that identifies the schema document.booleanelementFormDefaultThe @elementFormDefault value of the current schema.private java.util.Stack<java.lang.String>elementNamesKeep the local name of elements encountered so far.intfinalDefaultThe @finalDefault value of the current schema.ParserContextparsercoordinator.private NGCCRuntimeExrefererPoints to the schema document (the parser of it) that included/imported this schema.static java.lang.StringXMLSchemaNSURI
-
Constructor Summary
Constructors Modifier Constructor Description (package private)NGCCRuntimeEx(ParserContext _parser)privateNGCCRuntimeEx(ParserContext _parser, boolean chameleonMode, NGCCRuntimeEx referer)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddErrorChecker(Patch patcher)voidaddPatcher(Patch patcher)voidcheckDoubleDefError(XSDeclaration c)org.xml.sax.LocatorcopyLocator()Creates a copy of the current locator object.AnnotationParsercreateAnnotationParser()Creates a new instance of annotation parser.org.relaxng.datatype.ValidationContextcreateValidationContext()Returns an immutable snapshot of the current context.XmlStringcreateXmlString(java.lang.String value)voidendPrefixMapping(java.lang.String prefix)java.lang.StringgetAnnotationContextElementName()Gets the element name that contains the annotation element.org.xml.sax.ErrorHandlergetErrorHandler()booleanhasAlreadyBeenRead()Called when a new document is being parsed and checks if the document has already been parsed before.static booleanignorableDuplicateComponent(XSDeclaration c)voidimportSchema(java.lang.String ns, java.lang.String schemaLocation)Imports the specified schema.voidincludeSchema(java.lang.String schemaLocation)Includes the specified schema.voidonEnterElementConsumed(java.lang.String uri, java.lang.String localName, java.lang.String qname, org.xml.sax.Attributes atts)Called by the generated handler code when an enter element event is consumed.voidonLeaveElementConsumed(java.lang.String uri, java.lang.String localName, java.lang.String qname)booleanparseBoolean(java.lang.String v)voidparseEntity(org.xml.sax.InputSource source, boolean includeMode, java.lang.String expectedNamespace, org.xml.sax.Locator importLocation)Parses the specified entity.ForeignAttributesImplparseForeignAttributes(ForeignAttributesImpl next)UNameparseUName(java.lang.String qname)Parses UName under the given context.voidreportError(java.lang.String msg)voidreportError(java.lang.String msg, org.xml.sax.Locator loc)Reports an error during the parsing.private org.xml.sax.InputSourceresolveRelativeURL(java.lang.String namespaceURI, java.lang.String relativeUri)Resolves relative URI found in the document.voidstartPrefixMapping(java.lang.String prefix, java.lang.String uri)protected voidunexpectedX(java.lang.String token)-
Methods inherited from class com.sun.xml.xsom.impl.parser.state.NGCCRuntime
characters, consumeAttribute, endDocument, endElement, getAttributeIndex, getCurrentAttributes, getLocator, ignorableWhitespace, processingInstruction, processList, redirectSubtree, replace, reset, resolveNamespacePrefix, sendEnterAttribute, sendEnterElement, sendLeaveAttribute, sendLeaveElement, sendText, setDocumentLocator, setRootHandler, skippedEntity, startDocument, startElement, trace, traceln
-
-
-
-
Field Detail
-
parser
public final ParserContext parser
coordinator.
-
currentSchema
public SchemaImpl currentSchema
The schema currently being parsed.
-
finalDefault
public int finalDefault
The @finalDefault value of the current schema.
-
blockDefault
public int blockDefault
The @blockDefault value of the current schema.
-
elementFormDefault
public boolean elementFormDefault
The @elementFormDefault value of the current schema. True if local elements are qualified by default.
-
attributeFormDefault
public boolean attributeFormDefault
The @attributeFormDefault value of the current schema. True if local attributes are qualified by default.
-
chameleonMode
public boolean chameleonMode
True if the current schema is in a chameleon mode. This changes the way QNames are interpreted. Life is very miserable with XML Schema, as you see.
-
documentSystemId
private java.lang.String documentSystemId
URI that identifies the schema document. Maybe null if the system ID is not available.
-
elementNames
private final java.util.Stack<java.lang.String> elementNames
Keep the local name of elements encountered so far. This information is passed to AnnotationParser as context information
-
referer
private final NGCCRuntimeEx referer
Points to the schema document (the parser of it) that included/imported this schema.
-
document
public SchemaDocumentImpl document
Points to theSchemaDocumentImplthat represents the schema document being parsed.
-
currentContext
private NGCCRuntimeEx.Context currentContext
-
XMLSchemaNSURI
public static final java.lang.String XMLSchemaNSURI
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
NGCCRuntimeEx
NGCCRuntimeEx(ParserContext _parser)
-
NGCCRuntimeEx
private NGCCRuntimeEx(ParserContext _parser, boolean chameleonMode, NGCCRuntimeEx referer)
-
-
Method Detail
-
checkDoubleDefError
public void checkDoubleDefError(XSDeclaration c) throws org.xml.sax.SAXException
- Throws:
org.xml.sax.SAXException
-
ignorableDuplicateComponent
public static boolean ignorableDuplicateComponent(XSDeclaration c)
-
addPatcher
public void addPatcher(Patch patcher)
- Specified by:
addPatcherin interfacePatcherManager
-
addErrorChecker
public void addErrorChecker(Patch patcher)
- Specified by:
addErrorCheckerin interfacePatcherManager
-
reportError
public void reportError(java.lang.String msg, org.xml.sax.Locator loc) throws org.xml.sax.SAXExceptionDescription copied from interface:PatcherManagerReports an error during the parsing.- Specified by:
reportErrorin interfacePatcherManagerloc- location of the error in the source file, or null if it's unavailable.- Throws:
org.xml.sax.SAXException
-
reportError
public void reportError(java.lang.String msg) throws org.xml.sax.SAXException- Throws:
org.xml.sax.SAXException
-
resolveRelativeURL
private org.xml.sax.InputSource resolveRelativeURL(java.lang.String namespaceURI, java.lang.String relativeUri) throws org.xml.sax.SAXExceptionResolves relative URI found in the document.- Parameters:
namespaceURI- passed to the entity resolver.relativeUri- value of the schemaLocation attribute. Can be null.- Returns:
- non-null if
EntityResolverreturned anInputSource, or if the relativeUri parameter seems to be pointing to something. Otherwise it returns null, in which case import/include should be abandoned. - Throws:
org.xml.sax.SAXException
-
includeSchema
public void includeSchema(java.lang.String schemaLocation) throws org.xml.sax.SAXExceptionIncludes the specified schema.- Throws:
org.xml.sax.SAXException
-
importSchema
public void importSchema(java.lang.String ns, java.lang.String schemaLocation) throws org.xml.sax.SAXExceptionImports the specified schema.- Throws:
org.xml.sax.SAXException
-
hasAlreadyBeenRead
public boolean hasAlreadyBeenRead()
Called when a new document is being parsed and checks if the document has already been parsed before.Used to avoid recursive inclusion. Note that the same document will be parsed multiple times if they are for different target namespaces.
Document Graph Model
The challenge we are facing here is that you have a graph of documents that reference each other. Each document has an unique URI to identify themselves, and references are done by using those. The graph may contain cycles.
Our goal here is to parse all the documents in the graph, without parsing the same document twice. This method implements this check.
One complication is the chameleon schema; a document can be parsed multiple times if they are under different target namespaces.
Also, note that when you resolve relative URIs in the @schemaLocation, their base URI is *NOT* the URI of the document.
- Returns:
- true if the document has already been processed and thus needs to be skipped.
-
parseEntity
public void parseEntity(org.xml.sax.InputSource source, boolean includeMode, java.lang.String expectedNamespace, org.xml.sax.Locator importLocation) throws org.xml.sax.SAXExceptionParses the specified entity.- Parameters:
importLocation- The source location of the import/include statement. Used for reporting errors.- Throws:
org.xml.sax.SAXException
-
createAnnotationParser
public AnnotationParser createAnnotationParser()
Creates a new instance of annotation parser.
-
getAnnotationContextElementName
public java.lang.String getAnnotationContextElementName()
Gets the element name that contains the annotation element. This method works correctly only when called by the annotation handler.
-
copyLocator
public org.xml.sax.Locator copyLocator()
Creates a copy of the current locator object.
-
getErrorHandler
public org.xml.sax.ErrorHandler getErrorHandler()
-
onEnterElementConsumed
public void onEnterElementConsumed(java.lang.String uri, java.lang.String localName, java.lang.String qname, org.xml.sax.Attributes atts) throws org.xml.sax.SAXExceptionDescription copied from class:NGCCRuntimeCalled by the generated handler code when an enter element event is consumed.Pushes a new attribute set.
Note that attributes are NOT pushed at the startElement method, because the processing of the enterElement event can trigger other attribute events and etc.
This method will be called from one of handlers when it truely consumes the enterElement event.
- Overrides:
onEnterElementConsumedin classNGCCRuntime- Throws:
org.xml.sax.SAXException
-
onLeaveElementConsumed
public void onLeaveElementConsumed(java.lang.String uri, java.lang.String localName, java.lang.String qname) throws org.xml.sax.SAXException- Overrides:
onLeaveElementConsumedin classNGCCRuntime- Throws:
org.xml.sax.SAXException
-
createValidationContext
public org.relaxng.datatype.ValidationContext createValidationContext()
Returns an immutable snapshot of the current context.
-
createXmlString
public XmlString createXmlString(java.lang.String value)
-
startPrefixMapping
public void startPrefixMapping(java.lang.String prefix, java.lang.String uri) throws org.xml.sax.SAXException- Specified by:
startPrefixMappingin interfaceorg.xml.sax.ContentHandler- Overrides:
startPrefixMappingin classNGCCRuntime- Throws:
org.xml.sax.SAXException
-
endPrefixMapping
public void endPrefixMapping(java.lang.String prefix) throws org.xml.sax.SAXException- Specified by:
endPrefixMappingin interfaceorg.xml.sax.ContentHandler- Overrides:
endPrefixMappingin classNGCCRuntime- Throws:
org.xml.sax.SAXException
-
parseUName
public UName parseUName(java.lang.String qname) throws org.xml.sax.SAXException
Parses UName under the given context.- Throws:
org.xml.sax.SAXException
-
parseBoolean
public boolean parseBoolean(java.lang.String v)
-
unexpectedX
protected void unexpectedX(java.lang.String token) throws org.xml.sax.SAXException- Overrides:
unexpectedXin classNGCCRuntime- Throws:
org.xml.sax.SAXException
-
parseForeignAttributes
public ForeignAttributesImpl parseForeignAttributes(ForeignAttributesImpl next)
-
-