Top Description Inners Fields Constructors Methods
com.sun.xml.xsom.impl.parser

public Class NGCCRuntimeEx

extends NGCCRuntime
implements PatcherManager
Class Inheritance
All Implemented Interfaces
com.sun.xml.xsom.impl.parser.PatcherManager
Imports
com.sun.tools.rngdatatype.ValidationContext, com.sun.xml.xsom.XSDeclaration, .XSSimpleType, .XmlString, com.sun.xml.xsom.impl.Const, .ForeignAttributesImpl, .SchemaImpl, .UName, com.sun.xml.xsom.impl.parser.state.NGCCRuntime, .Schema, com.sun.xml.xsom.parser.AnnotationParser, org.xml.sax.Attributes, .EntityResolver, .ErrorHandler, .InputSource, .Locator, .SAXException, .SAXParseException, org.xml.sax.helpers.LocatorImpl, java.io.IOException, java.net.URI, .URL, java.text.MessageFormat, java.util.Stack, java.util.regex.Pattern

NGCCRuntime extended with various utility methods for parsing XML Schema.
Author
Kohsuke Kawaguchi ([email protected])

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
public boolean
attributeFormDefault

The @attributeFormDefault value of the current schema.

public int
blockDefault

The @blockDefault value of the current schema.

public boolean
chameleonMode

True if the current schema is in a chameleon mode.

private NGCCRuntimeEx.Context
public SchemaImpl
currentSchema

The schema currently being parsed.

public SchemaDocumentImpl
document

Points to the SchemaDocumentImpl that represents the schema document being parsed.

private String
documentSystemId

URI that identifies the schema document.

public boolean
elementFormDefault

The @elementFormDefault value of the current schema.

private final Stack<String>
elementNames

Keep the local name of elements encountered so far.

public int
finalDefault

The @finalDefault value of the current schema.

private static final Pattern
P

public final ParserContext
parser

coordinator.

private final NGCCRuntimeEx
referer

Points to the schema document (the parser of it) that included/imported this schema.

Constructor Summary

AccessConstructor and Description
pack-priv
private
NGCCRuntimeEx(ParserContext _parser, boolean chameleonMode, NGCCRuntimeEx referer)

Method Summary

Modifier and TypeMethod and Description
public void
public void
public void
public String

Returns:

String with whitespaces collapsed
collapse
(String
String where whitespaces should be collapsed
text
)

Utility function for collapsing the namespaces inside qname declarations and 'name' attribute values that should contain the qname values

private CharSequence
collapse(CharSequence text)

This is usually the biggest processing bottleneck.

public Locator

Returns:

Locator copy
copyLocator
()

Creates a copy of the current locator object.

public AnnotationParser

Returns:

Annotation parser
createAnnotationParser
()

Creates a new instance of annotation parser.

public ValidationContext

Returns:

Snapshot of current context
createValidationContext
()

Returns an immutable snapshot of the current context.

public XmlString
public void
public String

Returns:

Element name
getAnnotationContextElementName
()

Gets the element name that contains the annotation element.This method works correctly only when called by the annotation handler.

public ErrorHandler
public boolean

Returns:

true if the document has already been processed and thus needs to be skipped.
hasAlreadyBeenRead
()

Called when a new document is being parsed and checks if the document has already been parsed before.

public static boolean
public void
importSchema(String ns, String schemaLocation)

Imports the specified schema.

public void
includeSchema(String schemaLocation)

Includes the specified schema.

private static boolean
private boolean
isWhiteSpace(char ch)

returns true if the specified char is a white space character.

public void
onEnterElementConsumed(String uri, String localName, String qname, Attributes atts)

Overrides com.sun.xml.xsom.impl.parser.state.NGCCRuntime.onEnterElementConsumed.

Called by the generated handler code when an enter element event is consumed.

public void
public boolean
public void
parseEntity(InputSource source, boolean includeMode, String expectedNamespace, Locator
The source location of the import/include statement. Used for reporting errors.
importLocation
)

Parses the specified entity.

public ForeignAttributesImpl
public UName

Returns:

New UName instance based on attribute name.
parseUName
(final String
Attribute name.
qname
)

Parses UName under the given context.

public void
reportError(String msg, Locator loc)

Implements com.sun.xml.xsom.impl.parser.PatcherManager.reportError.

Reports an error during the parsing.

public void
private InputSource

Returns:

non-null if EntityResolver returned an InputSource, or if the relativeUri parameter seems to be pointing to something. Otherwise it returns null, in which case import/include should be abandoned.
resolveRelativeURL
(String
passed to the entity resolver.
namespaceURI
,
String
value of the schemaLocation attribute. Can be null.
relativeUri
)

Resolves relative URI found in the document.

public void
protected void
Inherited from com.sun.xml.xsom.impl.parser.state.NGCCRuntime:
charactersconsumeAttributeendDocumentendElementgetAttributeIndexgetCurrentAttributesgetLocatorignorableWhitespaceprocessingInstructionprocessListredirectSubtreereplaceresetresolveNamespacePrefixsendEnterAttributesendEnterElementsendLeaveAttributesendLeaveElementsendTextsetDocumentLocatorsetRootHandlerskippedEntitystartDocumentstartElementtracetraceln

Field Detail

attributeFormDefaultback to summary
public boolean attributeFormDefault

The @attributeFormDefault value of the current schema. True if local attributes are qualified by default.

blockDefaultback to summary
public int blockDefault

The @blockDefault value of the current schema.

chameleonModeback to summary
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.

currentContextback to summary
private NGCCRuntimeEx.Context currentContext
currentSchemaback to summary
public SchemaImpl currentSchema

The schema currently being parsed.

documentback to summary
public SchemaDocumentImpl document

Points to the SchemaDocumentImpl that represents the schema document being parsed.

documentSystemIdback to summary
private String documentSystemId

URI that identifies the schema document. Maybe null if the system ID is not available.

elementFormDefaultback to summary
public boolean elementFormDefault

The @elementFormDefault value of the current schema. True if local elements are qualified by default.

elementNamesback to summary
private final Stack<String> elementNames

Keep the local name of elements encountered so far. This information is passed to AnnotationParser as context information

finalDefaultback to summary
public int finalDefault

The @finalDefault value of the current schema.

Pback to summary
private static final Pattern P
parserback to summary
public final ParserContext parser

coordinator.

refererback to summary
private final NGCCRuntimeEx referer

Points to the schema document (the parser of it) that included/imported this schema.

Constructor Detail

NGCCRuntimeExback to summary
pack-priv NGCCRuntimeEx(ParserContext _parser)
NGCCRuntimeExback to summary
private NGCCRuntimeEx(ParserContext _parser, boolean chameleonMode, NGCCRuntimeEx referer)

Method Detail

addErrorCheckerback to summary
public void addErrorChecker(Patch patcher)

Implements com.sun.xml.xsom.impl.parser.PatcherManager.addErrorChecker.

Annotations
@Override
addPatcherback to summary
public void addPatcher(Patch patcher)

Implements com.sun.xml.xsom.impl.parser.PatcherManager.addPatcher.

Annotations
@Override
checkDoubleDefErrorback to summary
public void checkDoubleDefError(XSDeclaration c) throws SAXException
collapseback to summary
public String collapse(String text)

Utility function for collapsing the namespaces inside qname declarations and 'name' attribute values that should contain the qname values

Parameters
text:String

String where whitespaces should be collapsed

Returns:String

String with whitespaces collapsed

collapseback to summary
private CharSequence collapse(CharSequence text)

This is usually the biggest processing bottleneck.

copyLocatorback to summary
public Locator copyLocator()

Creates a copy of the current locator object.

Returns:Locator

Locator copy

createAnnotationParserback to summary
public AnnotationParser createAnnotationParser()

Creates a new instance of annotation parser.

Returns:AnnotationParser

Annotation parser

createValidationContextback to summary
public ValidationContext createValidationContext()

Returns an immutable snapshot of the current context.

Returns:ValidationContext

Snapshot of current context

createXmlStringback to summary
public XmlString createXmlString(String value)
endPrefixMappingback to summary
public void endPrefixMapping(String prefix) throws SAXException

Overrides com.sun.xml.xsom.impl.parser.state.NGCCRuntime.endPrefixMapping.

Implements org.xml.sax.ContentHandler.endPrefixMapping.

Doc from org.xml.sax.ContentHandler.endPrefixMapping.

End the scope of a prefix-URI mapping.

See startPrefixMapping for details. These events will always occur immediately after the corresponding endElement event, but the order of endPrefixMapping events is not otherwise guaranteed.

Annotations
@Override
Exceptions
SAXException:
the client may throw an exception during processing
getAnnotationContextElementNameback to summary
public String getAnnotationContextElementName()

Gets the element name that contains the annotation element.This method works correctly only when called by the annotation handler.

Returns:String

Element name

getErrorHandlerback to summary
public ErrorHandler getErrorHandler()
hasAlreadyBeenReadback to summary
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:boolean

true if the document has already been processed and thus needs to be skipped.

ignorableDuplicateComponentback to summary
public static boolean ignorableDuplicateComponent(XSDeclaration c)
importSchemaback to summary
public void importSchema(String ns, String schemaLocation) throws SAXException

Imports the specified schema.

includeSchemaback to summary
public void includeSchema(String schemaLocation) throws SAXException

Includes the specified schema.

isAbsoluteback to summary
private static boolean isAbsolute(String uri)
isWhiteSpaceback to summary
private boolean isWhiteSpace(char ch)

returns true if the specified char is a white space character.

onEnterElementConsumedback to summary
public void onEnterElementConsumed(String uri, String localName, String qname, Attributes atts) throws SAXException

Overrides com.sun.xml.xsom.impl.parser.state.NGCCRuntime.onEnterElementConsumed.

Doc from com.sun.xml.xsom.impl.parser.state.NGCCRuntime.onEnterElementConsumed.

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

Annotations
@Override
onLeaveElementConsumedback to summary
public void onLeaveElementConsumed(String uri, String localName, String qname) throws SAXException

Overrides com.sun.xml.xsom.impl.parser.state.NGCCRuntime.onLeaveElementConsumed.

Annotations
@Override
parseBooleanback to summary
public boolean parseBoolean(String v)
parseEntityback to summary
public void parseEntity(InputSource source, boolean includeMode, String expectedNamespace, Locator importLocation) throws SAXException

Parses the specified entity.

Parameters
importLocation:Locator

The source location of the import/include statement. Used for reporting errors.

parseForeignAttributesback to summary
public ForeignAttributesImpl parseForeignAttributes(ForeignAttributesImpl next)
parseUNameback to summary
public UName parseUName(final String qname) throws SAXException

Parses UName under the given context.

Parameters
qname:String

Attribute name.

Returns:UName

New UName instance based on attribute name.

reportErrorback to summary
public void reportError(String msg, Locator loc) throws SAXException

Implements com.sun.xml.xsom.impl.parser.PatcherManager.reportError.

Doc from com.sun.xml.xsom.impl.parser.PatcherManager.reportError.

Reports an error during the parsing.

Annotations
@Override
reportErrorback to summary
public void reportError(String msg) throws SAXException
resolveRelativeURLback to summary
private InputSource resolveRelativeURL(String namespaceURI, String relativeUri) throws SAXException

Resolves relative URI found in the document.

Parameters
namespaceURI:String

passed to the entity resolver.

relativeUri:String

value of the schemaLocation attribute. Can be null.

Returns:InputSource

non-null if EntityResolver returned an InputSource, or if the relativeUri parameter seems to be pointing to something. Otherwise it returns null, in which case import/include should be abandoned.

startPrefixMappingback to summary
public void startPrefixMapping(String prefix, String uri) throws SAXException

Overrides com.sun.xml.xsom.impl.parser.state.NGCCRuntime.startPrefixMapping.

Implements org.xml.sax.ContentHandler.startPrefixMapping.

Doc from org.xml.sax.ContentHandler.startPrefixMapping.

Begin the scope of a prefix-URI Namespace mapping.

The information from this event is not necessary for normal Namespace processing: the SAX XML reader will automatically replace prefixes for element and attribute names when the http://xml.org/sax/features/namespaces feature is true (the default).

There are cases, however, when applications need to use prefixes in character data or in attribute values, where they cannot safely be expanded automatically; the start/endPrefixMapping event supplies the information to the application to expand prefixes in those contexts itself, if necessary.

Note that start/endPrefixMapping events are not guaranteed to be properly nested relative to each other: all startPrefixMapping events will occur immediately before the corresponding startElement event, and all endPrefixMapping events will occur immediately after the corresponding endElement event, but their order is not otherwise guaranteed.

There should never be start/endPrefixMapping events for the "xml" prefix, since it is predeclared and immutable.

Annotations
@Override
Exceptions
SAXException:
the client may throw an exception during processing
unexpectedXback to summary
protected void unexpectedX(String token) throws SAXException

Overrides com.sun.xml.xsom.impl.parser.state.NGCCRuntime.unexpectedX.

Annotations
@Override
com.sun.xml.xsom.impl.parser back to summary

private Class NGCCRuntimeEx.Context

extends Object
implements ValidationContext
Class Inheritance
All Implemented Interfaces
com.sun.tools.rngdatatype.ValidationContext

Field Summary

Modifier and TypeField and Description
private final String
private final NGCCRuntimeEx.Context
private final String

Constructor Summary

AccessConstructor and Description
pack-priv
Context(String _prefix, String _uri, NGCCRuntimeEx.Context _context)

Method Summary

Modifier and TypeMethod and Description
public String
getBaseUri()

Implements com.sun.tools.rngdatatype.ValidationContext.getBaseUri.

Returns the base URI of the context.

public boolean
isNotation(String arg0)

Implements com.sun.tools.rngdatatype.ValidationContext.isNotation.

Checks if a notation is declared with the specified name.

public boolean
isUnparsedEntity(String arg0)

Implements com.sun.tools.rngdatatype.ValidationContext.isUnparsedEntity.

Checks if an unparsed entity is declared with the specified name.

public String
resolveNamespacePrefix(String p)

Implements com.sun.tools.rngdatatype.ValidationContext.resolveNamespacePrefix.

Resolves a namespace prefix to the corresponding namespace URI.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

prefixback to summary
private final String prefix
previousback to summary
private final NGCCRuntimeEx.Context previous
uriback to summary
private final String uri

Constructor Detail

Contextback to summary
pack-priv Context(String _prefix, String _uri, NGCCRuntimeEx.Context _context)

Method Detail

getBaseUriback to summary
public String getBaseUri()

Implements com.sun.tools.rngdatatype.ValidationContext.getBaseUri.

Doc from com.sun.tools.rngdatatype.ValidationContext.getBaseUri.

Returns the base URI of the context. The null string may be returned if no base URI is known.

Annotations
@Override
isNotationback to summary
public boolean isNotation(String arg0)

Implements com.sun.tools.rngdatatype.ValidationContext.isNotation.

Doc from com.sun.tools.rngdatatype.ValidationContext.isNotation.

Checks if a notation is declared with the specified name.

Annotations
@Override
isUnparsedEntityback to summary
public boolean isUnparsedEntity(String arg0)

Implements com.sun.tools.rngdatatype.ValidationContext.isUnparsedEntity.

Doc from com.sun.tools.rngdatatype.ValidationContext.isUnparsedEntity.

Checks if an unparsed entity is declared with the specified name.

Annotations
@Override
resolveNamespacePrefixback to summary
public String resolveNamespacePrefix(String p)

Implements com.sun.tools.rngdatatype.ValidationContext.resolveNamespacePrefix.

Doc from com.sun.tools.rngdatatype.ValidationContext.resolveNamespacePrefix.

Resolves a namespace prefix to the corresponding namespace URI. This method is used for validating the QName type, for example.

If the prefix is "" (empty string), it indicates an unprefixed value. The callee should resolve it as for an unprefixed element, rather than for an unprefixed attribute.

If the prefix is "xml", then the callee must resolve this prefix into "http://www.w3.org/XML/1998/namespace", as defined in the XML Namespaces Recommendation.

Annotations
@Override