com.google.clearsilver.jsilver.data
Class ChainedData

java.lang.Object
  extended by com.google.clearsilver.jsilver.data.DelegatedData
      extended by com.google.clearsilver.jsilver.data.ChainedData
All Implemented Interfaces:
Data
Direct Known Subclasses:
LocalAndGlobalData

public class ChainedData
extends DelegatedData

Implementation of Data that allows for multiple underlying Data objects and checks each one in order for a value before giving up. Behaves like local HDF and global HDF in the JNI implementation of Clearsilver. This is only meant to be a root Data object and hardcodes that fact.

Note: If you have elements foo.1, foo.2, foo.3 in first Data object and foo.4, foo.5, foo.6 in second Data object, then fetching children of foo will return only foo.1 foo.2 foo.3 from first Data object.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.google.clearsilver.jsilver.data.DelegatedData
DelegatedData.DelegatedIterator
 
Field Summary
static boolean DEBUG_MULTIPLE_ASSIGNMENTS
           
static Logger logger
           
 
Constructor Summary
ChainedData(Data... dataList)
           
ChainedData(Data data)
          Optmization for case of single item.
ChainedData(List<Data> dataList)
           
 
Method Summary
 Data createChild(String path)
          Retrieves the HDF object that is the root of the subtree at hdfpath, create the subtree if it doesn't exist
 boolean getBooleanValue(String path)
          Retrieves the value at the specified path in this HDF node's subtree.
 Data getChild(String path)
          Retrieves the object that is the root of the subtree at hdfpath, returning null if the subtree doesn't exist
 int getIntValue(String path)
          Retrieves the value at the specified path in this HDF node's subtree.
 int getIntValue(String path, int defaultValue)
          Retrieves the integer value at the specified path in this HDF node's subtree.
 String getValue(String path)
          Retrieves the value at the specified path in this HDF node's subtree.
 String getValue(String path, String defaultValue)
          Retrieves the value at the specified path in this HDF node's subtree.
protected  DelegatedData newInstance(Data newDelegate)
          Subclasses will want to override this method to return a Data object of their specific type.
 void optimize()
          Optimizes the Data structure for performance.
 void toString(StringBuilder out, int indent)
           
 void write(Appendable out, int indent)
          Write out the String representation of this HDF node.
 
Methods inherited from class com.google.clearsilver.jsilver.data.DelegatedData
copy, copy, getAttribute, getAttributeCount, getAttributes, getBooleanValue, getChildCount, getChildren, getDelegate, getEscapeMode, getFullPath, getIntValue, getName, getNextSibling, getParent, getRoot, getSymlink, getValue, hasAttribute, isFirstSibling, isLastSibling, newChildIterator, removeTree, setAttribute, setEscapeMode, setSymlink, setSymlink, setSymlink, setValue, setValue, toString, unwrap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

public static final Logger logger

DEBUG_MULTIPLE_ASSIGNMENTS

public static final boolean DEBUG_MULTIPLE_ASSIGNMENTS
See Also:
Constant Field Values
Constructor Detail

ChainedData

public ChainedData(Data data)
Optmization for case of single item.

Parameters:
data - a single data object to wrap.

ChainedData

public ChainedData(Data... dataList)

ChainedData

public ChainedData(List<Data> dataList)
Method Detail

newInstance

protected DelegatedData newInstance(Data newDelegate)
Description copied from class: DelegatedData
Subclasses will want to override this method to return a Data object of their specific type.

Overrides:
newInstance in class DelegatedData
Parameters:
newDelegate - the Data object to wrap with a new delegator
Returns:
a DelegateData type or subclass.

getChild

public Data getChild(String path)
Description copied from interface: Data
Retrieves the object that is the root of the subtree at hdfpath, returning null if the subtree doesn't exist

Specified by:
getChild in interface Data
Overrides:
getChild in class DelegatedData

createChild

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

Specified by:
createChild in interface Data
Overrides:
createChild in class DelegatedData

getValue

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

Specified by:
getValue in interface Data
Overrides:
getValue in class DelegatedData

getIntValue

public int getIntValue(String path,
                       int defaultValue)
Description copied from interface: Data
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 Data
Overrides:
getIntValue in class DelegatedData

getValue

public String getValue(String path)
Description copied from interface: Data
Retrieves the value at the specified path in this HDF node's subtree. If not found, returns null.

Specified by:
getValue in interface Data
Overrides:
getValue in class DelegatedData

getIntValue

public int getIntValue(String path)
Description copied from interface: Data
Retrieves the value at the specified path in this HDF node's subtree. If not found or invalid, returns 0.

Specified by:
getIntValue in interface Data
Overrides:
getIntValue in class DelegatedData

getBooleanValue

public boolean getBooleanValue(String path)
Description copied from interface: Data
Retrieves the value at the specified path in this HDF node's subtree. If not found or invalid, returns false.

Specified by:
getBooleanValue in interface Data
Overrides:
getBooleanValue in class DelegatedData

toString

public void toString(StringBuilder out,
                     int indent)
Specified by:
toString in interface Data
Overrides:
toString in class DelegatedData

write

public void write(Appendable out,
                  int indent)
           throws IOException
Description copied from interface: Data
Write out the String representation of this HDF node.

Specified by:
write in interface Data
Overrides:
write in class DelegatedData
Throws:
IOException

optimize

public void optimize()
Description copied from interface: Data
Optimizes the Data structure for performance. This is a somewhat expensive operation that should improve CPU and/or memory usage for long-lived Data objects. For example, it may internalize all Strings to reduce redundant copies.

Specified by:
optimize in interface Data
Overrides:
optimize in class DelegatedData


Copyright © 2010-2012 Google. All Rights Reserved.