Top Description Methods
org.codehaus.stax2.validation

public Interface ValidationContext

Imports
javax.xml.namespace.QName, javax.xml.stream.Location, .XMLStreamException

Interface that defines functionality exposed by the "owner" of the content to validate (usually a stream reader or stream writer) to validators, needed in addition to actually validatable content, for succesful validation. It also defines methods needed for infoset augmentation some validators do, such as adding default values to attributes. Some of functionality is optional (for example, writer may not have any useful location information).

The functionality included is close to the minimal subset of functionality needed to support 3 main streamable schema languages (DTD, W3C Schema, Relax NG).

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

Index of the newly added attribute, if operation was succesful; -1 if not.
addDefaultAttribute
(String localName, String uri, String prefix, String value)

An optional method that can be used to add a new attribute value for an attribute that was not yet contained by the container, as part of using attribute default value mechanism.

public int

Returns:

Index of the specified attribute, if one present; -1 otherwise.
findAttributeIndex
(String nsURI, String localName)

public int

Returns:

Number of attributes accessible for the currently active start element.
getAttributeCount
()

This method returns number of attributes accessible from within currently active start element.

public String
public String
public String
getAttributePrefix(int index)

public String
getAttributeType(int index)

public String
getAttributeValue(int index)

public String
getAttributeValue(String nsURI, String localName)

public String

Returns:

Base URI active in the current location of the document being validated, if known; null to indicate no base URI known.
getBaseUri
()

public QName

Returns:

Name of the element at the top of the current element stack, if any. During validation calls it refers to the element being processed (start or end tag), or its parent (when processing text nodes), or null (in document prolog and epilog).
getCurrentElementName
()

Method that can be used to access name information of the innermost (top) element in the element stack.

public String
getNamespaceURI(String prefix)

Method that can be called by the validator to resolve a namespace prefix of the currently active top-level element.

public Location
getValidationLocation()

Method that will return the location that best represents current location within document to be validated, if such information is available.

public String

Returns:

Xml version of the document: currently has to be either "1.0" or "1.1".
getXmlVersion
()

Method that validator can call to figure out which xml version document being validated declared (if none, "1.0" is assumed as per xml specifications 1.0 and 1.1).

public boolean

Returns:

True, if a notation with specified name has been declared in the document being validated; false if not.
isNotationDeclared
(String name)

public boolean

Returns:

True, if an unparsed entity with specified name has been declared in the document being validated; false if not.
isUnparsedEntityDeclared
(String name)

public void
reportProblem(XMLValidationProblem problem)

Method called by the validator, upon encountering a validation problem.

Method Detail

addDefaultAttributeback to summary
public int addDefaultAttribute(String localName, String uri, String prefix, String value) throws XMLStreamException

An optional method that can be used to add a new attribute value for an attribute that was not yet contained by the container, as part of using attribute default value mechanism. Optional here means that it is possible that no operation is actually done by the context object. This would be the case, for example, when validation is done on the writer side: since default attributes are implied by a DTD, they should not be added to the output.

Note

caller has to ensure that the addition would not introduce a duplicate; attribute container implementation is not required to do any validation on attribute name (local name, prefix, uri) or value.

Returns:int

Index of the newly added attribute, if operation was succesful; -1 if not.

findAttributeIndexback to summary
public int findAttributeIndex(String nsURI, String localName)
Returns:int

Index of the specified attribute, if one present; -1 otherwise.

getAttributeCountback to summary
public int getAttributeCount()

This method returns number of attributes accessible from within currently active start element.

Note

this method is only guaranteed to be callable during execution of XMLValidator methods XMLValidator#validateElementStart, XMLValidator#validateAttribute and XMLValidator#validateElementAndAttributes. At other times implementations may choose to allow it to be called (for example, with information regarding last start element processed), to throw a IllegalArgumentException, or to return 0 to indicate no attribute information is available.

Also note that whether defaulted attributes (attributes for which values are only available via attribute defaulting) are accessible depends on exact time when this method is called, and in general can not be assumed to function reliably.

Returns:int

Number of attributes accessible for the currently active start element.

getAttributeLocalNameback to summary
public String getAttributeLocalName(int index)
getAttributeNamespaceback to summary
public String getAttributeNamespace(int index)
getAttributePrefixback to summary
public String getAttributePrefix(int index)
getAttributeTypeback to summary
public String getAttributeType(int index)
getAttributeValueback to summary
public String getAttributeValue(int index)
getAttributeValueback to summary
public String getAttributeValue(String nsURI, String localName)
getBaseUriback to summary
public String getBaseUri()
Returns:String

Base URI active in the current location of the document being validated, if known; null to indicate no base URI known.

getCurrentElementNameback to summary
public QName getCurrentElementName()

Method that can be used to access name information of the innermost (top) element in the element stack.

Returns:QName

Name of the element at the top of the current element stack, if any. During validation calls it refers to the element being processed (start or end tag), or its parent (when processing text nodes), or null (in document prolog and epilog).

getNamespaceURIback to summary
public String getNamespaceURI(String prefix)

Method that can be called by the validator to resolve a namespace prefix of the currently active top-level element. This may be necessary for things like DTD validators (which may need to heuristically guess proper namespace URI of attributes, esp. ones with default values).

getValidationLocationback to summary
public Location getValidationLocation()

Method that will return the location that best represents current location within document to be validated, if such information is available.

Note

it is likely that even when a location is known, it may not be very accurate; for example, when attributes are validated, it is possible that they all would point to a single location that may point to the start of the element that contains attributes.

getXmlVersionback to summary
public String getXmlVersion()

Method that validator can call to figure out which xml version document being validated declared (if none, "1.0" is assumed as per xml specifications 1.0 and 1.1).

Returns:String

Xml version of the document: currently has to be either "1.0" or "1.1".

isNotationDeclaredback to summary
public boolean isNotationDeclared(String name)
Returns:boolean

True, if a notation with specified name has been declared in the document being validated; false if not.

isUnparsedEntityDeclaredback to summary
public boolean isUnparsedEntityDeclared(String name)
Returns:boolean

True, if an unparsed entity with specified name has been declared in the document being validated; false if not.

reportProblemback to summary
public void reportProblem(XMLValidationProblem problem) throws XMLStreamException

Method called by the validator, upon encountering a validation problem. Implementations are encouraged to allow an optional ValidationProblemHandler be set by the application, to define handling.

Note

Stax2 version 2 only allowed throwing instances of XMLValidationProblem; version 3 allows generic base class to be thrown, to support other interfaces such as basic Stax interface javax.xml.stream.XMLReporter.