|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.xolite.impl.BaseXMLEventParser
public abstract class BaseXMLEventParser
A base XMLEventParser
implementation common to many parsers.
Constructor Summary | |
---|---|
BaseXMLEventParser()
|
Method Summary | |
---|---|
protected abstract void |
addLocationInfo(XMLParseException xpe)
|
void |
delegateParsingTo(XMLSerializable handlerOfSubElements)
Delegates the parsing of a XML fragment to an other SaxHandler . |
protected void |
endElementImpl(String uri,
String localName)
|
NamespaceContext |
getCurrentDefinedNamespaces()
Get NamespacePrefixResolver mapping the prefix to the namespace URI. |
NamespacedName |
getCurrentElementName()
Get the namespace URI and local name of the current element. |
Object |
getCustomObject(Object key)
Get back any custom object that was put in with the putCustomObject(key, value) method. |
XMLObjectFactory |
getFactory()
Get a factory able to instantiate objects corresponding to XML elements. |
XMLSerializable |
getLastParsedObject()
Get the last object that called endParsing(..) method on the parser. |
String |
getNamespaceURI(String prefix)
Get namespace URI corresponding to the given prefix. |
String |
getPrefix(String namespaceURI)
Get the first prefix mapped to the given namespace. |
Iterator<String> |
getPrefixes(String namespaceURI)
Get all the prefixes mapped to the given namespace. |
NamespacedName |
getQualifiedName(String qName)
Resolve a qualified name to it's namespace URI + local name. |
boolean |
isFirstEvent()
'true' iff the startElement call is the first one called to the XMLSerializable currently receiving it. |
boolean |
isLastEvent()
'true' iff the endElement call is the last one called to the XMLSerializable currently receiving it. |
XMLSerializable |
parseElement(String uri,
String localName)
Create the XMLSerializable object corresponding to the given XML element, delegates the parsing to it and return the created object. |
protected void |
pushPrefixMappingInNextLevel(String prefix,
String namespaceURI)
|
void |
putCustomObject(Object key,
Object value)
Put a custom object in an internal Map. |
void |
setFactory(XMLObjectFactory newFactory)
Set the factory to be used by this parser. |
protected void |
setup(XMLSerializable rootHandler)
|
protected void |
startElementImpl(String uri,
String localName)
|
protected void |
tearDown()
|
void |
throwParseException(String message,
Throwable cause)
Throw an exception with given message and cause. |
void |
throwUnexpectedElementException(String expectedTags)
Throw an exception telling that the current element (the one that was just passed to a startElement(..) or
endElement(..) method) is unexpected. |
void |
throwUnexpectedNamespaceException(String expected)
Throw an exception telling that the namespace of the current element (the one that was just passed to a startElement(..) or endElement(..) method) is unexpected. |
protected void |
transformAndThrowException(Exception source)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface net.sf.xolite.XMLEventParser |
---|
getAttributeNameIterator, getAttributeNamespaceIterator, getAttributeValue, getAttributeValueNS, getElementText |
Constructor Detail |
---|
public BaseXMLEventParser()
Method Detail |
---|
public void setFactory(XMLObjectFactory newFactory)
newFactory
- a factory able to instantiate objects corresponding to XML elements.public String getNamespaceURI(String prefix)
getNamespaceURI
in interface NamespaceContext
NamespaceContext.getPrefix(java.lang.String)
public String getPrefix(String namespaceURI)
getPrefix
in interface NamespaceContext
NamespaceContext.getPrefix(java.lang.String)
public Iterator<String> getPrefixes(String namespaceURI)
getPrefixes
in interface NamespaceContext
NamespaceContext.getPrefixes(java.lang.String)
public NamespacedName getCurrentElementName()
XMLEventParser
getCurrentElementName
in interface XMLEventParser
public NamespaceContext getCurrentDefinedNamespaces()
XMLEventParser
NamespacePrefixResolver
mapping the prefix to the namespace URI. A copy of the current mapping object of
this parser at the moment of the call is returned.
getCurrentDefinedNamespaces
in interface XMLEventParser
public void delegateParsingTo(XMLSerializable handlerOfSubElements) throws XMLParseException
XMLEventParser
SaxHandler
. When this handler have finished to parse the
data belonging to it, it will call the endParsing(..)
method and the current parser will receive again the XML
parsing events. startElement(..)
method, the same startElement method (with same
parameters) is called against the delegated (handlerOfSubElements) object by the parser.
delegateParsingTo
in interface XMLEventParser
handlerOfSubElements
- the XMLSerializable that will receive the next 'simplified SAX' events from the XMLEventParser.
XMLParseException
public XMLSerializable parseElement(String uri, String localName) throws XMLParseException
XMLEventParser
XMLSerializable child = parser.getFactory().createObject(uri, localName, parser); parser.delegateParsingTo(child, uri, localName); return child;
parseElement
in interface XMLEventParser
XMLParseException
public boolean isFirstEvent()
XMLEventParser
startElement
call is the first one called to the XMLSerializable currently receiving it. startElement
is called the parsed object can use this method to know if the notified event is the start of itself or the start of a direct
sub-object. startElement
method implementation.
isFirstEvent
in interface XMLEventParser
startElement
is called against the XMLSerializable.public boolean isLastEvent()
XMLEventParser
endElement
call is the last one called to the XMLSerializable currently receiving it. endElement
is
called, the parsed object can use this method to know if the notified event is the end of itself or the end of a direct
sub-object. endElement
method implementation.
isLastEvent
in interface XMLEventParser
startElement
is called against the XMLSerializable.public XMLSerializable getLastParsedObject() throws XMLParseException
XMLEventParser
endParsing(..)
method on the parser.
getLastParsedObject
in interface XMLEventParser
endParsing(..)
method on the parser.
XMLParseException
public NamespacedName getQualifiedName(String qName) throws XMLParseException
XMLEventParser
To map the prefix, this method will use the prefix mappings of the parsed document. If no prefix mapping is defined for a
given prefix, an exception is thrown. When no prefix is defined, this method will try to find the default prefix mapping, but
if no default mapping is defined, no exception is thrown (in this case, the URI of the returned NamespacedName
is null).
getQualifiedName
in interface XMLEventParser
qName
- a qualified name (like: "xs:element").
XMLParseException
- If the qualified name contains a prefix not mapped to a namespace.public XMLObjectFactory getFactory() throws XMLParseException
XMLEventParser
getFactory
in interface XMLEventParser
XMLParseException
- if the factory is not defined.public Object getCustomObject(Object key)
XMLEventParser
putCustomObject(key, value)
method.
getCustomObject
in interface XMLEventParser
key
- key of the custom object.
public void putCustomObject(Object key, Object value)
XMLEventParser
getCustomObject(key)
method.
putCustomObject
in interface XMLEventParser
key
- key of the custom object.value
- custom object.public void throwUnexpectedNamespaceException(String expected) throws XMLParseException
XMLEventParser
startElement(..)
or endElement(..)
method) is unexpected. If the expected namespace URI is passed
as parameter, it is added in the message.
throwUnexpectedNamespaceException
in interface XMLEventParser
expected
- the expected namespace URI. If null, no expected namespace URI is mentioned in the exception message.
XMLParseException
public void throwUnexpectedElementException(String expectedTags) throws XMLParseException
XMLEventParser
startElement(..)
or
endElement(..)
method) is unexpected. If the expected tags are passed as parameter, they are added in the
message.
throwUnexpectedElementException
in interface XMLEventParser
expectedTags
- the expected element tag(s). If you expect several different tags, you can enumerate them in this parameter (for
example by separating them with commas). It is simply added in the exception message. If null, no expected tags
are mentioned in the exception message.
XMLParseException
public void throwParseException(String message, Throwable cause) throws XMLParseException
XMLEventParser
throwParseException
in interface XMLEventParser
message
- the exception message (rem: parser location is added).cause
- the exception cause
XMLParseException
protected void transformAndThrowException(Exception source) throws XMLParseException
XMLParseException
protected abstract void addLocationInfo(XMLParseException xpe)
protected void setup(XMLSerializable rootHandler)
protected void tearDown()
protected void pushPrefixMappingInNextLevel(String prefix, String namespaceURI)
protected void startElementImpl(String uri, String localName) throws Exception
Exception
protected void endElementImpl(String uri, String localName) throws Exception
Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |