org.clearsilver
Class DelegatedHdf

java.lang.Object
  extended by org.clearsilver.DelegatedHdf
All Implemented Interfaces:
Closeable, HDF

public abstract class DelegatedHdf
extends Object
implements HDF

Utility class that delegates all methods of an HDF object. Made to facilitate the transition to HDF being an interface and thus not extensible in the same way as it was.

This class, and its subclasses must take care to wrap or unwrap HDF and CS objects as they are passed through from the callers to the delegate object.


Constructor Summary
DelegatedHdf(HDF hdf)
           
 
Method Summary
 boolean belongsToSameRoot(HDF hdf)
          Checks if the given hdf object belongs to the same root HDF object as this one.
 void close()
          Clean up CS object state.
 void copy(String hdfpath, HDF src)
          Deep copy of the contents of the source HDF structure to this HDF starting at the specified HDF path node.
 String dump()
          Generates a string representing the content of the HDF tree rooted at this node.
 void exportDate(String hdfname, String tz, int tt)
          Export a date to a clearsilver tree using a specified timezone
 void exportDate(String hdfname, TimeZone timeZone, Date date)
          Export a date to a clearsilver tree using a specified timezone
 DelegatedHdf getChild(String hdfpath)
          Retrieves the HDF for the first child of the root of the subtree at hdfpath, or null if no child exists of that path or if the path doesn't exist.
 CSFileLoader getFileLoader()
          Get the file loader in use, if any.
static HDF getFullyUnwrappedHdf(HDF hdf)
          Utility function for concrete ClearsilverFactories to unwrap DelegatedHdfs and get down to a concrete (or unknown) HDF object.
 HDF getHdf()
           
 int getIntValue(String hdfname, int default_value)
          Retrieves the integer value at the specified path in this HDF node's subtree.
 DelegatedHdf getObj(String hdfpath)
          Retrieves the HDF object that is the root of the subtree at hdfpath, or null if no object exists at that path.
 DelegatedHdf getOrCreateObj(String hdfpath)
          Retrieves the HDF object that is the root of the subtree at hdfpath, create the subtree if it doesn't exist
 DelegatedHdf getRootObj()
          Return the root of the tree where the current node lies.
 String getValue(String hdfname, String default_value)
          Retrieves the value at the specified path in this HDF node's subtree.
protected abstract  DelegatedHdf newDelegatedHdf(HDF hdf)
          Method subclasses are required to override with a method that returns a new DelegatedHdf object that wraps the specified HDF object.
 DelegatedHdf objChild()
          Returns the child of this HDF node, or null if there is no child.
 String objName()
          Returns the name of this HDF node.
 DelegatedHdf objNext()
          Returns the child of this HDF node, or null if there is no child.
 String objValue()
          Returns the value of this HDF node, or null if this node has no value.
 boolean readFile(String filename)
          Loads the contents of the specified HDF file from disk into the current HDF object.
 boolean readString(String data)
          Parses/loads the contents of the given string as HDF into the current HDF object.
 void removeTree(String hdfname)
          Remove the specified subtree.
 void setFileLoader(CSFileLoader fileLoader)
          Set the CS file loader to use
 void setSymLink(String hdf_name_src, String hdf_name_dest)
          Links the src hdf name to the dest.
 void setValue(String hdfname, String value)
          Sets the value at the specified path in this HDF node's subtree.
 boolean writeFile(String filename)
          Serializes HDF contents to a file (readable by readFile)
 String writeString()
          Serializes HDF contents to a string (readable by readString)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DelegatedHdf

public DelegatedHdf(HDF hdf)
Method Detail

getFullyUnwrappedHdf

public static HDF getFullyUnwrappedHdf(HDF hdf)
Utility function for concrete ClearsilverFactories to unwrap DelegatedHdfs and get down to a concrete (or unknown) HDF object.

Parameters:
hdf - the possibly DelegatedHdf to unwrap
Returns:
the innermost non-DelegatedHdf HDF object.

getHdf

public HDF getHdf()

newDelegatedHdf

protected abstract DelegatedHdf newDelegatedHdf(HDF hdf)
Method subclasses are required to override with a method that returns a new DelegatedHdf object that wraps the specified HDF object.

Parameters:
hdf - an HDF object that should be wrapped in a new DelegatedHdf object of the same type as this current object.
Returns:
an object that is a subclass of DelegatedHdf and which wraps the given HDF object.

close

public void close()
Description copied from interface: HDF
Clean up CS object state.

Specified by:
close in interface Closeable
Specified by:
close in interface HDF

readFile

public boolean readFile(String filename)
                 throws IOException,
                        FileNotFoundException
Description copied from interface: HDF
Loads the contents of the specified HDF file from disk into the current HDF object. The loaded contents are merged with the existing contents.

Specified by:
readFile in interface HDF
Throws:
IOException
FileNotFoundException

getFileLoader

public CSFileLoader getFileLoader()
Description copied from interface: HDF
Get the file loader in use, if any.

Specified by:
getFileLoader in interface HDF
Returns:
the file loader in use.

setFileLoader

public void setFileLoader(CSFileLoader fileLoader)
Description copied from interface: HDF
Set the CS file loader to use

Specified by:
setFileLoader in interface HDF
Parameters:
fileLoader - the file loader that should be used.

writeFile

public boolean writeFile(String filename)
                  throws IOException
Description copied from interface: HDF
Serializes HDF contents to a file (readable by readFile)

Specified by:
writeFile in interface HDF
Throws:
IOException

readString

public boolean readString(String data)
Description copied from interface: HDF
Parses/loads the contents of the given string as HDF into the current HDF object. The loaded contents are merged with the existing contents.

Specified by:
readString in interface HDF

writeString

public String writeString()
Description copied from interface: HDF
Serializes HDF contents to a string (readable by readString)

Specified by:
writeString in interface HDF

getIntValue

public int getIntValue(String hdfname,
                       int default_value)
Description copied from interface: HDF
Retrieves the integer value at the specified path in this HDF node's subtree. If the value does not exist, or cannot be converted to an integer, default_value will be returned.

Specified by:
getIntValue in interface HDF

getValue

public String getValue(String hdfname,
                       String default_value)
Description copied from interface: HDF
Retrieves the value at the specified path in this HDF node's subtree.

Specified by:
getValue in interface HDF

setValue

public void setValue(String hdfname,
                     String value)
Description copied from interface: HDF
Sets the value at the specified path in this HDF node's subtree.

Specified by:
setValue in interface HDF

removeTree

public void removeTree(String hdfname)
Description copied from interface: HDF
Remove the specified subtree.

Specified by:
removeTree in interface HDF

setSymLink

public void setSymLink(String hdf_name_src,
                       String hdf_name_dest)
Description copied from interface: HDF
Links the src hdf name to the dest.

Specified by:
setSymLink in interface HDF

exportDate

public void exportDate(String hdfname,
                       TimeZone timeZone,
                       Date date)
Description copied from interface: HDF
Export a date to a clearsilver tree using a specified timezone

Specified by:
exportDate in interface HDF

exportDate

public void exportDate(String hdfname,
                       String tz,
                       int tt)
Description copied from interface: HDF
Export a date to a clearsilver tree using a specified timezone

Specified by:
exportDate in interface HDF

getObj

public DelegatedHdf getObj(String hdfpath)
Description copied from interface: HDF
Retrieves the HDF object that is the root of the subtree at hdfpath, or null if no object exists at that path.

Specified by:
getObj in interface HDF

getChild

public DelegatedHdf getChild(String hdfpath)
Description copied from interface: HDF
Retrieves the HDF for the first child of the root of the subtree at hdfpath, or null if no child exists of that path or if the path doesn't exist.

Specified by:
getChild in interface HDF

getRootObj

public DelegatedHdf getRootObj()
Description copied from interface: HDF
Return the root of the tree where the current node lies. If the current node is the root, return this. Implementations may not necessarily return the same instance of HDF every time. Use HDF.belongsToSameRoot(HDF) to check if two HDFs belong to the same root.

Specified by:
getRootObj in interface HDF

belongsToSameRoot

public boolean belongsToSameRoot(HDF hdf)
Description copied from interface: HDF
Checks if the given hdf object belongs to the same root HDF object as this one.

Specified by:
belongsToSameRoot in interface HDF
Parameters:
hdf - The hdf object to compare to.

getOrCreateObj

public DelegatedHdf getOrCreateObj(String hdfpath)
Description copied from interface: HDF
Retrieves the HDF object that is the root of the subtree at hdfpath, create the subtree if it doesn't exist

Specified by:
getOrCreateObj in interface HDF

objName

public String objName()
Description copied from interface: HDF
Returns the name of this HDF node. The root node has no name, so calling this on the root node will return null.

Specified by:
objName in interface HDF

objValue

public String objValue()
Description copied from interface: HDF
Returns the value of this HDF node, or null if this node has no value. Every node in the tree can have a value, a child, and a next peer.

Specified by:
objValue in interface HDF

objChild

public DelegatedHdf objChild()
Description copied from interface: HDF
Returns the child of this HDF node, or null if there is no child. Use this in conjunction with objNext to walk the HDF tree. Every node in the tree can have a value, a child, and a next peer.

Specified by:
objChild in interface HDF

objNext

public DelegatedHdf objNext()
Description copied from interface: HDF
Returns the child of this HDF node, or null if there is no child. Use this in conjunction with objNext to walk the HDF tree. Every node in the tree can have a value, a child, and a next peer.

Specified by:
objNext in interface HDF

copy

public void copy(String hdfpath,
                 HDF src)
Description copied from interface: HDF
Deep copy of the contents of the source HDF structure to this HDF starting at the specified HDF path node.

This method copies over the attributes and value of the node and recurses through all the children of the source node. Any symlink in the source node becomes a symlink in the copy.

Specified by:
copy in interface HDF
Parameters:
hdfpath - the node within this HDF where the source structure should be copied to.
src - the source HDF to copy over.

dump

public String dump()
Description copied from interface: HDF
Generates a string representing the content of the HDF tree rooted at this node.

Specified by:
dump in interface HDF


Copyright © 2010-2012 Google. All Rights Reserved.