metagloss 0.0.2

net.sf.metagloss.xml
Class DOMFeeder

java.lang.Object
  extended by net.sf.metagloss.xml.DOMFeeder
All Implemented Interfaces:
Injector

public class DOMFeeder
extends java.lang.Object
implements Injector

The DOMFeeder is capable of injecting XMLBind-annotated objects from XML sources.

It is possible to call the inject(Object) method several times, should different objects only request a limited set of data from the current node and children.

Note:

It currently only works on a single level below the root element supplied upon initialization.


Field Summary
 boolean debug
           
 
Constructor Summary
DOMFeeder(org.w3c.dom.Element root)
          Creates the DOMFeeder with a single element.
DOMFeeder(java.util.List<org.w3c.dom.Element> elements)
          Creates the DOMFeeder with a list of elements.
 
Method Summary
 void inject(java.lang.Object obj)
          Sets up object via setter injection.
 boolean isStrictChecking()
          Returns whether strict checking is enabled or not.
 boolean next()
          Tries to move to the next element in the list.
 void setStrictChecking(boolean strictChecking)
          Sets whether an injection-related error will throw XMLBindException upon error.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debug

public boolean debug
Constructor Detail

DOMFeeder

public DOMFeeder(org.w3c.dom.Element root)
Creates the DOMFeeder with a single element. When injecting several objects of the same type, it is adviced to initialize the DOMFeeder with a list instead.

This constructor will cause next() cause next to throw an InjectorException.

Parameters:
root - Starting element.
See Also:
DOMUtils.getChildren(Element, String)

DOMFeeder

public DOMFeeder(java.util.List<org.w3c.dom.Element> elements)
Creates the DOMFeeder with a list of elements. The element index initializes before the first element in the list. Traverse forward through the list by calling next().

The elements should be of the same type, that is, operate on the same class of objects.

Parameters:
elements - Starting elements.
Method Detail

isStrictChecking

public boolean isStrictChecking()
Returns whether strict checking is enabled or not.

Returns:
True, if errors should throw an exception.
See Also:
setStrictChecking(boolean)

setStrictChecking

public void setStrictChecking(boolean strictChecking)
Sets whether an injection-related error will throw XMLBindException upon error. If set to false, will continue parsing, discarding the element with a logcat stacktrace.

Defaults to false.

Parameters:
strictChecking - If true, aborts injection upon error.

inject

public void inject(java.lang.Object obj)
Description copied from interface: Injector
Sets up object via setter injection.

Specified by:
inject in interface Injector
Parameters:
obj - Object to inject.

next

public boolean next()
Tries to move to the next element in the list.

Specified by:
next in interface Injector
Returns:
True if the move was within bounds.