|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object de.ispsoft.jaxme.ObservedHandlerImpl
A default implementation for an ObservedHandler.
Field Summary | |
protected java.lang.String |
context
|
protected int |
level
|
protected org.xml.sax.Locator |
locator
|
protected Observer |
observer
|
protected java.util.Collection |
resultCollection
|
protected java.lang.Object |
resultNode
|
Constructor Summary | |
ObservedHandlerImpl()
Creates a new instance of ObservedHandlerImpl. |
Method Summary | |
protected void |
addResultNode(java.lang.Object o)
Sets a result node, the result of calling getResultNode() .
|
void |
endDocument()
Called to terminate the document. |
java.lang.String |
getContext()
Returns the context to use in error messages. |
java.lang.String |
getContext(java.lang.String pName)
Returns the context to use in error messages, extended by the given element or attribute name. |
Observer |
getObserver()
Returns a possible observer. |
java.util.Collection |
getResultCollection()
Returns a collection where to add successfully parsed elements, Strings or other JMNode instances. |
java.lang.Object |
getResultNode()
This method may be called after a startDocument() ,
..., endDocument() sequence. |
protected org.xml.sax.SAXException |
getSAXException(java.lang.String msg)
Depending on the presence of a locator, returns a SAXException or a SAXParseException. |
protected org.xml.sax.SAXException |
getSAXException(java.lang.String msg,
java.lang.Exception e)
Depending on the presence of a locator, returns a SAXException or a SAXParseException. |
void |
setContext(java.lang.String pContext)
Sets a context to use in error messages. |
void |
setDocumentLocator(org.xml.sax.Locator pLocator)
Sets a document locator. |
void |
setObserver(Observer pObserver)
Sets a possible observer. |
void |
setResultCollection(java.util.Collection pCollection)
Sets a collection where to add successfully parsed elements, Strings or other JMNode instances. |
void |
startDocument()
This method is for resetting the ObservedHandlerImpl. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.xml.sax.ContentHandler |
characters, endElement, endPrefixMapping, ignorableWhitespace, processingInstruction, skippedEntity, startElement, startPrefixMapping |
Field Detail |
protected java.lang.Object resultNode
protected java.util.Collection resultCollection
protected Observer observer
protected org.xml.sax.Locator locator
protected java.lang.String context
protected int level
Constructor Detail |
public ObservedHandlerImpl()
Method Detail |
public Observer getObserver()
Returns a possible observer. If the observer is non-null, then it will be notified for any element, String or JMNode that has been read successfully.
getObserver
in interface ObservedHandler
setObserver(de.ispsoft.jaxme.Observer)
public void setObserver(Observer pObserver)
Sets a possible observer. If the observer is non-null, then it will be notified for any element, String or JMNode that has been read successfully. The parsed element can be accessed as follows:
public void notify(Object o) { ObservedHandler handler = (ObservedHandler) o; Object o = handler.getResultNode(); if (o instanceof JMAnyElement) { JMAnyElement element = (JMAnyElement) o; ... // Do something here } else { ... // Other possibilities: String, JMPI, JMEntity } }
setObserver
in interface ObservedHandler
pObserver
- The observer being notified or null to disable
notification.getObserver()
public java.lang.Object getResultNode()
This method may be called after a startDocument()
,
..., endDocument()
sequence. It returns the result
object, which may be either of
getResultNode
in interface ObservedHandler
public void setResultCollection(java.util.Collection pCollection)
Sets a collection where to add successfully parsed elements, Strings or other JMNode instances. The collection can be processed if the parsing is done completely.
This collection is relevant only, if you expect to parse multiple documents in a sequence. For example, you might read a SOAP reply where the actual result consists of a single root node and a lot of childs.
If you expect a single result element only, you might
prefer using the getResultNode()
method.
The collection can be processed as follows:
for (java.util.Iterator iter = handler.getResultCollection(); iter.hasNext(); ) { Object o = iter.next(); if (o instanceof JMAnyElement) { JMAnyElement element = (JMAnyElement) o; ... // Do something here } else { ... // Other possibilities: String, JMPI or JMEntity } }
setResultCollection
in interface ObservedHandler
getResultCollection()
public java.util.Collection getResultCollection()
Returns a collection where to add successfully parsed elements, Strings or other JMNode instances. The collection can be processed if the parsing is done completely.
This collection is relevant only, if you expect to parse multiple documents in a sequence. For example, you might read a SOAP reply where the actual result consists of a single root node and a lot of childs.
If you expect a single result element only, you might
prefer using the getResultNode()
method.
getResultCollection
in interface ObservedHandler
setResultCollection(java.util.Collection)
protected void addResultNode(java.lang.Object o) throws org.xml.sax.SAXException
Sets a result node, the result of calling getResultNode()
.
If the result collection is non-null, then the result node will be added
to the collection. If the observer is non-null, then it will be notified.
org.xml.sax.SAXException
public void setDocumentLocator(org.xml.sax.Locator pLocator)
Sets a document locator.
setDocumentLocator
in interface org.xml.sax.ContentHandler
protected org.xml.sax.SAXException getSAXException(java.lang.String msg)
Depending on the presence of a locator, returns a SAXException or a SAXParseException.
protected org.xml.sax.SAXException getSAXException(java.lang.String msg, java.lang.Exception e)
Depending on the presence of a locator, returns a SAXException or a SAXParseException.
public void startDocument() throws org.xml.sax.SAXException
This method is for resetting the ObservedHandlerImpl.
Concrete subclasses should call this from within their
own startDocument()
methods.
startDocument
in interface org.xml.sax.ContentHandler
org.xml.sax.SAXException
public void endDocument() throws org.xml.sax.SAXException
Called to terminate the document. Does nothing.
endDocument
in interface org.xml.sax.ContentHandler
org.xml.sax.SAXException
public void setContext(java.lang.String pContext)
Sets a context to use in error messages.
setContext
in interface ObservedHandler
pContext
- or null for top level elements.public java.lang.String getContext()
Returns the context to use in error messages.
getContext
in interface ObservedHandler
public java.lang.String getContext(java.lang.String pName)
Returns the context to use in error messages, extended by the given element or attribute name.
Example:
String context = "/Address/Name"; setContext(context); getContext("FirstName"); // Returns "/Address/Name/FirstName"
getContext
in interface ObservedHandler
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |