cookxml.core
Class CookXml

java.lang.Object
  extended bycookxml.core.CookXml
Direct Known Subclasses:
CookJFace, CookSwing, CookSwt

public class CookXml
extends Object

This class is a general purpose XML configurator.

Since:
CookXml 1.0

Constructor Summary
CookXml(DocumentBuilder builder, TagLibrary tagLibrary, Object varObj)
          constructor.
CookXml(DocumentBuilder builder, TagLibrary tagLibrary, VarLookup varLookup)
          constructor.
 
Method Summary
static boolean debug(Exception ex)
          This function is supposed to work in conjunction with assert to generate a debug message but does not really throw an Exception
static boolean debug(String msg)
          This function is supposed to work in conjunction with assert to generate a debug message but does not really throw an Exception
static boolean debug(String msg, Exception ex)
          This function is supposed to work in conjunction with assert to generate a debug message but does not really throw an Exception
 ClassLoader getClassLoader()
          Obtain the ClassLoader that is used to locate resources.
static ClassLoader getDefaultClassLoader()
          Obtain the default ClassLoader that is used to locate resources.
static ExceptionHandler getDefaultExceptionHandler()
          Obtain the default ExceptionHandler for all instances of CookXml.
 DocumentBuilder getDocumentBuilder()
          Gets the DocumentBuilder used by this CookXml object.
 ExceptionHandler getExceptionHandler()
          returns the current ExceptionHandler.
 IdReference getId(String id)
          get the element associated with the id.
 ResourceBundle getResourceBundle()
          Gets the resource bundle used by this CookXml object.
 Object getRootObject()
          Gets the root object associated with the xml document root element.
 TagLibrary getTagLibrary()
          returns the tag library used by this CookXml object
 VarLookup getVarLookup()
          returns the current VarLookup object.
 boolean isAccessible()
          Returns if CookXml should attempt to access non-public variables.
static boolean isDefaultAccessible()
          Returns if CookXml by default should attempt to access non-public variables.
 void setAccessible(boolean accessible)
          Setting this flag to true to allow this CookXml object to read/write non-public variables (including package scope, protected, and private variables).
 void setClassLoader(ClassLoader classLoader)
          Set the ClassLaoder that is used to locate resouces.
static void setDefaultAccessible(boolean accessible)
          Setting this flag to true to allow CookXml to read/write non-public variables (including package scope, protected, and private variables) by default.
static void setDefaultClassLoader(ClassLoader defaultClassLoader)
          Set the default ClassLaoder that is used to locate resouces.
static void setDefaultExceptionHandler(ExceptionHandler defaultExceptionHandler)
          Sets the default ExceptionHandler for all instances of CookXml.
 void setDocumentBuilder(DocumentBuilder docBuilder)
          sets the DocumentBuilder used by this CookXml object.
 void setExceptionHandler(ExceptionHandler exceptionHandler)
          sets the current ExceptionHandler.
 void setId(String id, String ns, String tag, Object obj)
          Save an element with an id in a map such that this element can be referenced later.
 void setResourceBundle(ResourceBundle bundle)
          Sets the resource bundle to be used by this CookXml object.
 void setRootObject(Object rootObj)
          Sets the root object associated with the xml document root element.
 void setVarLookup(VarLookup varLookup)
          sets the current VarLookup object.
 Object xmlDecode(Object input)
          Call this function to start decoding the input.
 Object xmlDecode(Object input, String parentNS, String parentTag, Object parentObj)
          Call this function to start decoding the input.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CookXml

public CookXml(DocumentBuilder builder,
               TagLibrary tagLibrary,
               Object varObj)
constructor.

Parameters:
builder - the document builder use to parse the xml document.
tagLibrary - the tag library to be used.
varObj - inside where all the variables are contained.

CookXml

public CookXml(DocumentBuilder builder,
               TagLibrary tagLibrary,
               VarLookup varLookup)
constructor.

Parameters:
builder - the document builder use to parse the xml document.
tagLibrary - the tag library to be used.
varLookup - a handler for looking up variables
Method Detail

getDefaultExceptionHandler

public static ExceptionHandler getDefaultExceptionHandler()
Obtain the default ExceptionHandler for all instances of CookXml.

Returns:
the default ExceptionHandler for all instances of CookXml
Since:
CookXml 2.0
See Also:
ExceptionHandler

setDefaultExceptionHandler

public static void setDefaultExceptionHandler(ExceptionHandler defaultExceptionHandler)
Sets the default ExceptionHandler for all instances of CookXml.

Parameters:
defaultExceptionHandler - the default ExceptionHandler to be used
Since:
CookXml 2.0
See Also:
ExceptionHandler

setDefaultAccessible

public static void setDefaultAccessible(boolean accessible)
Setting this flag to true to allow CookXml to read/write non-public variables (including package scope, protected, and private variables) by default.

Note, reading/writing non-public variable should be avoided for Web Start applications or applications that run in a sandbox, as such action can generate a SecurityException.

Usually, it is rather rare to have frequent access to a single variable. So, performance-wise should be okay. If you read/write a particular variable more often, consider to cache the object.

Parameters:
accessible - if CookXml should attempt to access non-public variables
Since:
CookXml 2.3
See Also:
AccessException

isDefaultAccessible

public static boolean isDefaultAccessible()
Returns if CookXml by default should attempt to access non-public variables.

Returns:
if CookXml by default should attempt to access non-public variables
Since:
CookXml 2.3

getDefaultClassLoader

public static ClassLoader getDefaultClassLoader()
Obtain the default ClassLoader that is used to locate resources.

Returns:
the default ClassLoader
Since:
CookXml 2.3

setDefaultClassLoader

public static void setDefaultClassLoader(ClassLoader defaultClassLoader)
Set the default ClassLaoder that is used to locate resouces.

Parameters:
defaultClassLoader - the default ClassLoader to be used.
Since:
CookXml 2.3

debug

public static boolean debug(String msg)
This function is supposed to work in conjunction with assert to generate a debug message but does not really throw an Exception

Parameters:
msg - the message to be printed.
Returns:
true

debug

public static boolean debug(String msg,
                            Exception ex)
This function is supposed to work in conjunction with assert to generate a debug message but does not really throw an Exception

Parameters:
msg - the message to be printed.
ex - the exception message to be printed.
Returns:
true

debug

public static boolean debug(Exception ex)
This function is supposed to work in conjunction with assert to generate a debug message but does not really throw an Exception

Parameters:
ex - the exception message to be printed.
Returns:
true

getTagLibrary

public TagLibrary getTagLibrary()
returns the tag library used by this CookXml object

Returns:
the tag library used by this CookXml object

getId

public IdReference getId(String id)
get the element associated with the id.

Parameters:
id - the id to be retrieved.
Returns:
the information associated with the id.

setId

public void setId(String id,
                  String ns,
                  String tag,
                  Object obj)
Save an element with an id in a map such that this element can be referenced later.

Parameters:
id - the id to be saved.
tag - the tag name.
obj - the object associated with the tag.

xmlDecode

public Object xmlDecode(Object input)
                 throws CookXmlException
Call this function to start decoding the input. The input can be a string (which would be looked up using ClassLoader), a File, an InputStream, or an InputSource.

Parameters:
input - the input source
Returns:
the object constructed.
Throws:
CookXmlException

xmlDecode

public Object xmlDecode(Object input,
                        String parentNS,
                        String parentTag,
                        Object parentObj)
                 throws CookXmlException
Call this function to start decoding the input. The input can be a string (which would be looked up using ClassLoader), a File, an InputStream, or an InputSource.

Parameters:
parentTag - the assumed parent tag
parentObj - the assumed parentObj
input - the input source
Returns:
the object constructed.
Throws:
CookXmlException

getRootObject

public Object getRootObject()
Gets the root object associated with the xml document root element.

Returns:
the object to be associated with.

setRootObject

public void setRootObject(Object rootObj)
Sets the root object associated with the xml document root element.

Parameters:
rootObj - the object to be associated with.

getDocumentBuilder

public DocumentBuilder getDocumentBuilder()
Gets the DocumentBuilder used by this CookXml object.

Returns:
the DocumentBuilder used by this CookXml object.

setDocumentBuilder

public void setDocumentBuilder(DocumentBuilder docBuilder)
sets the DocumentBuilder used by this CookXml object.

Parameters:
docBuilder - the DocumentBuilder to be used by this CookXml object.

getResourceBundle

public ResourceBundle getResourceBundle()
Gets the resource bundle used by this CookXml object.

Returns:
the resource bundle used by the xml document.

setResourceBundle

public void setResourceBundle(ResourceBundle bundle)
Sets the resource bundle to be used by this CookXml object.

Parameters:
bundle - the resource bundle to be used by the xml document.

getVarLookup

public VarLookup getVarLookup()
returns the current VarLookup object.

Returns:
the current VarLookup object.
Since:
CookXml 2.0

setVarLookup

public void setVarLookup(VarLookup varLookup)
sets the current VarLookup object.

Parameters:
varLookup - the VarLookup object which is used for variable lookup.
Since:
CookXml 2.0

getExceptionHandler

public ExceptionHandler getExceptionHandler()
returns the current ExceptionHandler.

Returns:
the current ExceptionHandler.
Since:
CookXml 2.0

setExceptionHandler

public void setExceptionHandler(ExceptionHandler exceptionHandler)
sets the current ExceptionHandler.

Parameters:
exceptionHandler - the handler for exceptions.
Since:
CookXml 2.0

isAccessible

public boolean isAccessible()
Returns if CookXml should attempt to access non-public variables.

Returns:
if CookXml should attempt to access non-public variables
Since:
CookXml 2.3

setAccessible

public void setAccessible(boolean accessible)
Setting this flag to true to allow this CookXml object to read/write non-public variables (including package scope, protected, and private variables).

Note, reading/writing non-public variable should be avoided for Web Start applications or applications that run in a sandbox, as such action can generate a SecurityException.

Usually, it is rather rare to have frequent access to a single variable. So, performance-wise should be okay. If you read/write a particular variable more often, consider to cache the object.

Parameters:
accessible - if CookXml should attempt to access non-public variables
Since:
CookXml 2.3
See Also:
AccessException

getClassLoader

public ClassLoader getClassLoader()
Obtain the ClassLoader that is used to locate resources.

Returns:
the default ClassLoader
Since:
CookXml 2.4

setClassLoader

public void setClassLoader(ClassLoader classLoader)
Set the ClassLaoder that is used to locate resouces.

Parameters:
classLoader - the ClassLoader to be used.
Since:
CookXml 2.4