cookxml.core
Class DecodeEngine

java.lang.Object
  extended bycookxml.core.DecodeEngine
All Implemented Interfaces:
ExceptionHandler

public class DecodeEngine
extends Object
implements ExceptionHandler

This class does the actual internal decoding.

Since:
CookXml 1.0

Field Summary
static String XML_NS
          the XML namespace for xmlns:... attributes.
 
Method Summary
 void addChild(String parentNS, String parentTag, Element elm, Object parentObj, Object childObj)
          This function calls addChildUnchecked and calls ExceptionHandler to handle any exceptions generated.
 void addCleanupHook(CleanupHook hook)
          Add a CleanupHook for cleaning up work after DecodeEngine finishes, if the hook was not yet in the hook list.
 void addCurrentSkipList(Attr attr)
           
 void callSetter(String ns, String tag, String attrNS, String attr, Object obj, Object value)
           
 void cleanup()
          This function is to be called by CookXml after DecodeEngine finishes decoding XML.
static DecodeEngine createDecodeEngine(CookXml cookXml, VarLookup varLookup, StringHook stringHook)
           
static Object decode(Document document, CookXml cookXml, VarLookup varLookup, StringHook stringHook)
           
static Object decode(Element elm, CookXml cookXml, VarLookup varLookup, StringHook stringHook)
           
static Object decode(String parentNS, String parentTag, Document document, Object parentObj, CookXml cookXml, VarLookup varLookup, StringHook stringHook)
           
static Object decode(String parentNS, String parentTag, Element elm, Object parentObj, CookXml cookXml, VarLookup varLookup, StringHook stringHook)
           
 Object decodeElement(Element elm)
           
 Object decodeElement(String parentNS, String parentTag, Element elm, Object parentObj)
           
 CookXml getCookXml()
           
 Element getCurrentElement()
          returns the current DOM element being decoded.
 String getCurrentTag()
           
 Document getDocument()
           
 Handler getHandler(String ns, String tag, String attr)
          retrieve a handler from cache using the key pair.
 Object getParent(Object child)
           
 String getPrefixNameSpace(String prefix)
          Get the namespace associated with the namespace.
 Object getProperty(String key)
          Get data for a given key.
 StringHook getStringHook()
           
 Object getVariable(String name)
           
 VarLookup getVarLookup()
          returns the variable lookup handler.
 void handleException(String msg, Exception ex)
          A short hand for calling CookXml.getExceptionHandler and then call it to handle the exception.
 DecodeEngine newInstance()
           
 Object peekData()
          Peek the data on stack.
 Object popData()
          Pop the data off stack.
 void pushData(Object data)
          Push data onto stack.
 void removeCleanupHook(CleanupHook hook)
          Removes a CleanupHook for cleaning up work after DecodeEngine finishes.
 void setAddAction(AddAction addAction)
          This function set the current AddAction for addChild call.
 void setCurrentId(String id)
           
 void setCurrentTag(String tag)
           
 void setCurrentTag(String ns, String tag)
           
 void setCurrentVar(String var)
           
 void setDoAdd(boolean b)
          this function is mainly for the creators to tell the DecodeEngine not to add the object to the parent while it is being created.
 void setDocument(Document document)
           
 void setDoProcessChildren(boolean b)
          this function is mainly for the creators to tell the DecodeEngine not to process child nodes of the current one.
 void setHandler(String ns, String tag, String attr, Handler handler)
          save a handler into cache using the key pair.
 void setParent(Object parentObj, Object childObj)
          Set the parentObj childObj relationship by using childObj as the key for lookup its parentObj.
 Object setProperty(String key, Object value)
          Set data for a given key.
 void setStringHook(StringHook stringHook)
           
 void setVariable(String name, Object value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

XML_NS

public static final String XML_NS
the XML namespace for xmlns:... attributes. We need to ignore these since these are automatically processed.

See Also:
Constant Field Values
Method Detail

createDecodeEngine

public static DecodeEngine createDecodeEngine(CookXml cookXml,
                                              VarLookup varLookup,
                                              StringHook stringHook)

decode

public static Object decode(Document document,
                            CookXml cookXml,
                            VarLookup varLookup,
                            StringHook stringHook)
                     throws CookXmlException
Throws:
CookXmlException

decode

public static Object decode(String parentNS,
                            String parentTag,
                            Document document,
                            Object parentObj,
                            CookXml cookXml,
                            VarLookup varLookup,
                            StringHook stringHook)
                     throws CookXmlException
Throws:
CookXmlException

decode

public static Object decode(Element elm,
                            CookXml cookXml,
                            VarLookup varLookup,
                            StringHook stringHook)
                     throws CookXmlException
Throws:
CookXmlException

decode

public static Object decode(String parentNS,
                            String parentTag,
                            Element elm,
                            Object parentObj,
                            CookXml cookXml,
                            VarLookup varLookup,
                            StringHook stringHook)
                     throws CookXmlException
Throws:
CookXmlException

newInstance

public DecodeEngine newInstance()

decodeElement

public Object decodeElement(Element elm)
                     throws CookXmlException
Throws:
CookXmlException

decodeElement

public Object decodeElement(String parentNS,
                            String parentTag,
                            Element elm,
                            Object parentObj)
                     throws CookXmlException
Throws:
CookXmlException

callSetter

public void callSetter(String ns,
                       String tag,
                       String attrNS,
                       String attr,
                       Object obj,
                       Object value)
                throws SetterException
Throws:
SetterException

addChild

public void addChild(String parentNS,
                     String parentTag,
                     Element elm,
                     Object parentObj,
                     Object childObj)
              throws CookXmlException
This function calls addChildUnchecked and calls ExceptionHandler to handle any exceptions generated.

Parameters:
parentNS - the name space of the parentTag.
parentTag - parentTag of the parent element.
elm - the current element.
parentObj - the parent object.
childObj - the current object to be added to the parent.
Throws:
CookXmlException - the exception is thrown when errors occur.

getCookXml

public CookXml getCookXml()

getParent

public Object getParent(Object child)

getCurrentElement

public Element getCurrentElement()
returns the current DOM element being decoded.

Returns:
the current DOM element being decoded.

setParent

public void setParent(Object parentObj,
                      Object childObj)
Set the parentObj childObj relationship by using childObj as the key for lookup its parentObj.

Parameters:
parentObj - the parentObj object.
childObj - the childObj object.

getVarLookup

public VarLookup getVarLookup()
returns the variable lookup handler.

Returns:
the variable lookup handler

getVariable

public Object getVariable(String name)
                   throws VarLookupException
Throws:
VarLookupException

setVariable

public void setVariable(String name,
                        Object value)
                 throws VarLookupException
Throws:
VarLookupException

getHandler

public Handler getHandler(String ns,
                          String tag,
                          String attr)
retrieve a handler from cache using the key pair. It is usually the case where the handler for the same name and attribute use the same handler function.

Parameters:
ns - the namespace of the tag.
tag - the tag name of the key.
attr - the attribute name of the key.
Returns:
a handler from cache.

setHandler

public void setHandler(String ns,
                       String tag,
                       String attr,
                       Handler handler)
save a handler into cache using the key pair.

Parameters:
ns - the namespace of the tag.
tag - the tag name of the key.
attr - the attribute name of the key.
handler - the handler to be put in the cache.

getCurrentTag

public String getCurrentTag()

setCurrentTag

public void setCurrentTag(String tag)

setCurrentTag

public void setCurrentTag(String ns,
                          String tag)

setCurrentId

public void setCurrentId(String id)

setCurrentVar

public void setCurrentVar(String var)

addCurrentSkipList

public void addCurrentSkipList(Attr attr)

getStringHook

public StringHook getStringHook()

setStringHook

public void setStringHook(StringHook stringHook)

getDocument

public Document getDocument()

setDocument

public void setDocument(Document document)

pushData

public void pushData(Object data)
Push data onto stack.

Parameters:
data - data to be pushed onto stack.
Since:
CookXml 2.0

popData

public Object popData()
Pop the data off stack.

Returns:
data popped.
Since:
CookXml 2.0

peekData

public Object peekData()
Peek the data on stack.

Returns:
data peeked.
Since:
CookXml 2.0

setDoAdd

public void setDoAdd(boolean b)
this function is mainly for the creators to tell the DecodeEngine not to add the object to the parent while it is being created.

Parameters:
b - whether or not the add the object to the parent.
Since:
CookXml 2.0

setAddAction

public void setAddAction(AddAction addAction)
This function set the current AddAction for addChild call.

Parameters:
addAction - the current AddAction should be.
Since:
CookXml 3.0

setDoProcessChildren

public void setDoProcessChildren(boolean b)
this function is mainly for the creators to tell the DecodeEngine not to process child nodes of the current one.

Parameters:
b - whether or not the process further down the DOM hierachy.
Since:
CookXml 2.0

handleException

public void handleException(String msg,
                            Exception ex)
                     throws CookXmlException
A short hand for calling CookXml.getExceptionHandler and then call it to handle the exception.

Specified by:
handleException in interface ExceptionHandler
Parameters:
msg - the message for the exception
ex - the exception to be handled
Throws:
CookXmlException - if an error cannot be handled
Since:
CookXml 2.0

setProperty

public Object setProperty(String key,
                          Object value)
Set data for a given key. This feature is to allow creators to cache certain data.

Parameters:
key - key of the property entry
value - value of the property entry
Returns:
old value for the given key
Since:
CookXml 2.1

getProperty

public Object getProperty(String key)
Get data for a given key.

Parameters:
key - key of the property entry
Returns:
the value for the given key
Since:
CookXml 2.1

addCleanupHook

public void addCleanupHook(CleanupHook hook)
Add a CleanupHook for cleaning up work after DecodeEngine finishes, if the hook was not yet in the hook list.

Parameters:
hook - the CleanupHook to be added.
Since:
CookXml 2.5

removeCleanupHook

public void removeCleanupHook(CleanupHook hook)
Removes a CleanupHook for cleaning up work after DecodeEngine finishes.

Parameters:
hook - the CleanupHook to be remove.
Since:
CookXml 2.5

cleanup

public void cleanup()
             throws CleanupException
This function is to be called by CookXml after DecodeEngine finishes decoding XML.

Throws:
CleanupException - This exception is thrown when one of the CleanupHook encountered an error.
Since:
CookXml 2.5

getPrefixNameSpace

public String getPrefixNameSpace(String prefix)
Get the namespace associated with the namespace.

Parameters:
prefix - the namespace prefix.
Returns:
the namespace associated with the prefix. null if not found.
Since:
CookXml 3.0.1