Top Description Fields Constructors Methods
com.sun.tools.xjc.reader.xmlschema.parser

public Class CustomizationContextChecker

extends XMLFilterImpl
Class Inheritance
Imports
java.util.HashSet, .Set, .Stack, javax.xml.XMLConstants, javax.xml.namespace.QName, com.sun.tools.xjc.reader.Const, org.xml.sax.Attributes, .ErrorHandler, .Locator, .SAXException, .SAXParseException, org.xml.sax.helpers.XMLFilterImpl

Checks if binding declarations are placed where they are allowed.

For example, if a <jaxb:property> customization is given under the <xs:simpleContent> element, this class raises an error.

our main checkpoint of misplaced customizations are in BGMBuilder. There, we mark a customization whenever we use it. At the end of the day, we look for unmarked customizations and raise errors for them.

Between this approach and the JAXB spec 1.0 is a problem that the spec allows/prohibits customizations at schema element level, while BGMBuilder and XSOM works on schema component levels.

For example, a property customization is allowed on a complex type schema component, but it's only allowed on the <complexType> element. The spec team informed us that they would consider resolving this discrepancy in favor of RI, but meanwhile we need to detect errors correctly.

This filter is implemented for this purpose.

Customization and allowed locations

- globalBinding/schemaBinding schema - class complexType(*), modelGroupDecl, modelGroup, element - property attribute, element, any, modelGroup, modelGroupRef, complexType(*) - javaType simpleType(*) - typesafeEnumClass simpleType(*) - typesafeEnumMember simpleType(*), enumeration Components marked with '*' needs a check by this component since more than one schema element corresponds to one schema component of that type.

For simple types, customizations are allowed only under the <xs:simpleType> element, and for complex types they are allowed only under the <xs:cimplexType> element.

So the bottom line is that it would be suffice if we just make sure that no customization will be attached under other elements of simple types and complex types. Those are: - simpleType/restriction - list - union - complexType/(simple or complex)Content - complexType/(simple or complex)Content/(restriction of extension)

Author
Kohsuke Kawaguchi ([email protected])

Field Summary

Modifier and TypeField and Description
private final Stack<QName>
elementNames

Keep names of all the ancestor elements.

private final ErrorHandler
private Locator
private static final Set<String>
prohibitedSchemaElementNames

Set of element names that cannot have JAXB customizations.

Constructor Summary

AccessConstructor and Description
public
CustomizationContextChecker(ErrorHandler
Detected errors will be sent to this object.
_errorHandler
)

Method Summary

Modifier and TypeMethod and Description
public void
endElement(String namespaceURI, String localName, String qName)

Overrides org.xml.sax.helpers.XMLFilterImpl.endElement.

Implements org.xml.sax.ContentHandler.endElement.

Filter an end element event.

public void
public void
startElement(String namespaceURI, String localName, String qName, Attributes atts)

Overrides org.xml.sax.helpers.XMLFilterImpl.startElement.

Implements org.xml.sax.ContentHandler.startElement.

Filter a start element event.

private QName
top()

Gets the stack top.

Inherited from org.xml.sax.helpers.XMLFilterImpl:
charactersendDocumentendPrefixMappingerrorfatalErrorgetContentHandlergetDTDHandlergetEntityResolvergetErrorHandlergetFeaturegetParentgetPropertyignorableWhitespacenotationDeclparseparseprocessingInstructionresolveEntitysetContentHandlersetDTDHandlersetEntityResolversetErrorHandlersetFeaturesetParentsetPropertyskippedEntitystartDocumentstartPrefixMappingunparsedEntityDeclwarning

Field Detail

elementNamesback to summary
private final Stack<QName> elementNames

Keep names of all the ancestor elements.

errorHandlerback to summary
private final ErrorHandler errorHandler

Hides org.xml.sax.helpers.XMLFilterImpl.errorHandler.

locatorback to summary
private Locator locator

Hides org.xml.sax.helpers.XMLFilterImpl.locator.

prohibitedSchemaElementNamesback to summary
private static final Set<String> prohibitedSchemaElementNames

Set of element names that cannot have JAXB customizations.

Constructor Detail

CustomizationContextCheckerback to summary
public CustomizationContextChecker(ErrorHandler _errorHandler)
Parameters
_errorHandler:ErrorHandler

Detected errors will be sent to this object.

Method Detail

endElementback to summary
public void endElement(String namespaceURI, String localName, String qName) throws SAXException

Overrides org.xml.sax.helpers.XMLFilterImpl.endElement.

Implements org.xml.sax.ContentHandler.endElement.

Doc from org.xml.sax.helpers.XMLFilterImpl.endElement.

Filter an end element event.

Annotations
@Override
Exceptions
SAXException:
The client may throw an exception during processing.
setDocumentLocatorback to summary
public void setDocumentLocator(Locator locator)

Overrides org.xml.sax.helpers.XMLFilterImpl.setDocumentLocator.

Implements org.xml.sax.ContentHandler.setDocumentLocator.

Doc from org.xml.sax.helpers.XMLFilterImpl.setDocumentLocator.

Filter a new document locator event.

Annotations
@Override
startElementback to summary
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException

Overrides org.xml.sax.helpers.XMLFilterImpl.startElement.

Implements org.xml.sax.ContentHandler.startElement.

Doc from org.xml.sax.helpers.XMLFilterImpl.startElement.

Filter a start element event.

Annotations
@Override
Exceptions
SAXException:
The client may throw an exception during processing.
topback to summary
private QName top()

Gets the stack top.