de.ispsoft.jaxme
Interface ObservedHandler

All Superinterfaces:
org.xml.sax.ContentHandler
All Known Implementing Classes:
ObservedHandlerImpl

public interface ObservedHandler
extends org.xml.sax.ContentHandler

An extension of the org.xml.sax.ContentHandler that allows to retrieve a parsed result.

Author:
Jochen Wiedmann

Method Summary
 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.
 void setContext(java.lang.String pContext)
          Sets a context to use in error messages.
 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.
 
Methods inherited from interface org.xml.sax.ContentHandler
characters, endDocument, endElement, endPrefixMapping, ignorableWhitespace, processingInstruction, setDocumentLocator, skippedEntity, startDocument, startElement, startPrefixMapping
 

Method Detail

setObserver

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
     }
   }
 

Parameters:
pObserver - The observer being notified or null to disable notification.
See Also:
getObserver()

getObserver

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.

See Also:
setObserver(de.ispsoft.jaxme.Observer)

getResultNode

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


setResultCollection

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
     }
   }
 

See Also:
getResultCollection()

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.

See Also:
setResultCollection(java.util.Collection)

setContext

public void setContext(java.lang.String pContext)

Sets a context to use in error messages.

Parameters:
pContext - or null for top level elements.

getContext

public java.lang.String getContext()

Returns the context to use in error messages.

Returns:
Current context or null for top level elements.

getContext

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"