com.caucho.util
Class RegistryNode

java.lang.Object
  |
  +--com.caucho.util.RegistryNode

public class RegistryNode
extends java.lang.Object

The Registry is a configuration tree based on a key, value pair structure, essentially like an AList.


Constructor Summary
RegistryNode()
          Zero-arg constructor.
 
Method Summary
 void addChild(RegistryNode child)
          Adds the node as a child of the current node
 void append(RegistryNode next)
          Appends the children of the next node as children of this node.
 java.lang.Object clone()
          Clones the current node.
 RegistryException error(java.lang.Exception e)
          Returns a configuration error for a given configuration line number.
 RegistryException error(java.lang.String msg)
          Returns a configuration error for a given configuration line number.
 boolean getBoolean()
          Returns a boolean value, returning true if no value is specified.
 boolean getBoolean(java.lang.String path, boolean deflt)
          Gets a boolean value from a subnode with a default.
 java.util.List getChildren()
           
 QDate getDate()
           
 QDate getDate(java.lang.String path, QDate deflt)
           
 double getDouble()
          Returns the node's value interpreted as a double.
 double getDouble(java.lang.String path, double deflt)
          Returns a subnode's value interpreted as a double
 java.lang.String getErrorMessage(java.lang.String message)
          Adds the filename and line to the error message.
 java.lang.String getFilename()
          Returns the source filename for the configuration node.
 RegistryNode getFirstChild()
          Returns the first child node or null if there are no children.
 int getInt()
          Returns the node's value interpreted as an integer
 int getInt(java.lang.String path, int deflt)
          Returns a subnode's value interpreted as an integer
 int getLine()
          Returns the source line number for the configuration node.
 java.lang.String getName()
          Returns the attribute's name.
 RegistryNode getParent()
          Returns the parent node.
 java.lang.String getPath()
          Returns the node's value interpreted as a path.
 java.lang.String getPath(java.lang.String path, java.lang.String deflt)
          Returns a subnode's value interpreted as a path.
 long getPeriod()
          Returns the value as a period.
 long getPeriod(java.lang.String path, long deflt)
          Returns the value as a period.
 Registry getRoot()
          Return the root node
 java.lang.String getString()
          Returns the node's value interpreted as a string.
 java.lang.String getString(java.lang.String path, java.lang.String deflt)
          Returns a subnode's value interpreted as a string.
 java.lang.String getValue()
          Returns the attribute's value.
 boolean isModified()
          Returns true if the underlying files have been modified.
 java.util.Iterator iterator()
          Returns an iterator over the node's children.
 RegistryNode lookup(java.lang.String path)
          Returns the node corresponding to the path.
static long periodEnd(long now, long period)
          Calculates the next period end.
 void print(WriteStream os)
          Prints the RegistryNode tree for debugging.
 java.util.Iterator select(java.lang.String key)
          Returns an iterator over the node's children which match the key.
 void setRoot(Registry root)
          Return the root node
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RegistryNode

public RegistryNode()
Zero-arg constructor.
Method Detail

isModified

public boolean isModified()
Returns true if the underlying files have been modified.

getName

public java.lang.String getName()
Returns the attribute's name.

getValue

public java.lang.String getValue()
Returns the attribute's value.

getFilename

public java.lang.String getFilename()
Returns the source filename for the configuration node.

getLine

public int getLine()
Returns the source line number for the configuration node.

getParent

public RegistryNode getParent()
Returns the parent node.

getFirstChild

public RegistryNode getFirstChild()
Returns the first child node or null if there are no children.

getRoot

public Registry getRoot()
Return the root node

setRoot

public void setRoot(Registry root)
Return the root node

append

public void append(RegistryNode next)
Appends the children of the next node as children of this node.
Parameters:
next - parent of the children to be added

addChild

public void addChild(RegistryNode child)
Adds the node as a child of the current node
Parameters:
child - new child to be added

getBoolean

public boolean getBoolean()
                   throws RegistryException
Returns a boolean value, returning true if no value is specified.
 <flag>
 <flag>true</flag>
 <flag>yes</flag>
 
Throws:
RegistryException - if the value isn't true or false.

getBoolean

public boolean getBoolean(java.lang.String path,
                          boolean deflt)
                   throws RegistryException
Gets a boolean value from a subnode with a default.
Parameters:
path - hierarchical path specifying a child node
deflt - default value if no node is found

lookup

public RegistryNode lookup(java.lang.String path)
Returns the node corresponding to the path.
 RegistryNode subnode = node.lookup("web-app/servlet");
 
Parameters:
path - slash-separated path selecting a descendent node.

getInt

public int getInt()
           throws RegistryException
Returns the node's value interpreted as an integer
Throws:
throws - RegistryException if the value isn't a valid integer

getInt

public int getInt(java.lang.String path,
                  int deflt)
           throws RegistryException
Returns a subnode's value interpreted as an integer
Parameters:
path - the path to the subnode
deflt - default value for the int
Returns:
the specified value or the default if none specified.
Throws:
throws - RegistryException if the value isn't a valid integer

getDouble

public double getDouble()
                 throws RegistryException
Returns the node's value interpreted as a double.
Throws:
throws - RegistryException if the value isn't a valid double

getDouble

public double getDouble(java.lang.String path,
                        double deflt)
                 throws RegistryException
Returns a subnode's value interpreted as a double
Parameters:
path - the path to the subnode
deflt - default value for the double
Returns:
the specified value or the default if none specified.
Throws:
throws - RegistryException if the value isn't a valid double

getString

public java.lang.String getString()
Returns the node's value interpreted as a string.

getString

public java.lang.String getString(java.lang.String path,
                                  java.lang.String deflt)
Returns a subnode's value interpreted as a string.
Parameters:
path - the path to the subnode
deflt - default value for the string
Returns:
the specified value or the default if none specified.

getPath

public java.lang.String getPath()
Returns the node's value interpreted as a path. getPath automatically looks up variables in the System.properties so $foo/bar.xml resolves to the value of $foo.

getPath

public java.lang.String getPath(java.lang.String path,
                                java.lang.String deflt)
Returns a subnode's value interpreted as a path.
Parameters:
path - the path to the subnode
deflt - default value for the string
Returns:
the specified value or the default if none specified.

getDate

public QDate getDate()
              throws RegistryException

getDate

public QDate getDate(java.lang.String path,
                     QDate deflt)
              throws RegistryException

getPeriod

public long getPeriod()
               throws RegistryException
Returns the value as a period.
sseconds
mminutes
hhours
Ddays
Wweeks
Mmonths
Yyears
Returns:
the period in milliseconds, 0 if no period.
Throws:
throws - RegistryException if the value isn't a valid period

getPeriod

public long getPeriod(java.lang.String path,
                      long deflt)
               throws RegistryException
Returns the value as a period.
sseconds
mminutes
hhours
Ddays
Wweeks
Mmonths
Yyears
Parameters:
path - the path to the configuration subnode
deflt - default period
Returns:
the period in milliseconds, 0 if no period.
Throws:
throws - RegistryException if the value isn't a valid period

periodEnd

public static long periodEnd(long now,
                             long period)
Calculates the next period end.

iterator

public java.util.Iterator iterator()
Returns an iterator over the node's children.

select

public java.util.Iterator select(java.lang.String key)
Returns an iterator over the node's children which match the key.
Parameters:
key - the key for the children to match

getChildren

public java.util.List getChildren()

error

public RegistryException error(java.lang.String msg)
Returns a configuration error for a given configuration line number.
Parameters:
msg - the error message.

error

public RegistryException error(java.lang.Exception e)
Returns a configuration error for a given configuration line number.
Parameters:
node - the configuration node throwing the error.
e - exception thrown for that node.

getErrorMessage

public java.lang.String getErrorMessage(java.lang.String message)
Adds the filename and line to the error message.
 resin.conf:14: unknown tag `foo'
 
Parameters:
message - the error message
Returns:
the error message with filename and line number.

print

public void print(WriteStream os)
           throws java.io.IOException
Prints the RegistryNode tree for debugging.
Parameters:
os - the write stream to print the tree to.

clone

public java.lang.Object clone()
Clones the current node. Children and parents are not copied, just assigned by reference.
Overrides:
clone in class java.lang.Object
Returns:
the cloned object.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object