org.quattor.pan.dml.data
Class Resource

java.lang.Object
  extended by org.quattor.pan.dml.data.Element
      extended by org.quattor.pan.dml.data.PersistentElement
          extended by org.quattor.pan.dml.data.Resource
All Implemented Interfaces:
java.lang.Iterable<Resource.Entry>, Operation
Direct Known Subclasses:
HashResource, ListResource

public abstract class Resource
extends PersistentElement
implements java.lang.Iterable<Resource.Entry>

A Resource is a container of Properties and other Resources. All resources descend from PersistentElement which makes them eligible for inclusion in a final machine configuration.

Author:
loomis

Nested Class Summary
static interface Resource.Entry
          Interface is an alias to make the syntax for the Resource.Entry less cumbersome.
static interface Resource.Iterator
          Interface is simply an alias to make the syntax for the Resource.Iterator less cumbersome.
 
Constructor Summary
Resource()
           
 
Method Summary
abstract  Element get(Term term)
          Retrieve the Element associated with the given Term (either an index or string key).
abstract  Resource.Iterator iterator()
          Get an iterator which allows to run over the resources in the Resource.
abstract  Element put(Term term, Element newValue)
          Define the mapping between the given Term and given Element.
 Element rget(Term[] terms, int index, boolean protect, boolean lookupOnly)
          Dereference the Element to return the value of a child.
 ListResource rgetList(Term[] terms, int index)
          This is a special lookup function that will retrieve a list from the resource.
 void rput(Term[] terms, int index, Element value)
          Add the given child to this resource, creating intermediate resources as necessary.
abstract  int size()
          Get the number of elements in this Resource.
 
Methods inherited from class org.quattor.pan.dml.data.Element
checkInvalidSelfContext, checkRange, checkRestrictedContext, checkValidReplacement, defined, duplicate, equals, execute, exists, getTypeAsString, hashCode, isBoolean, isDouble, isList, isLong, isNlist, isPersistent, isProperty, isProtected, isResource, isString, isTransient, locateUndefinedElement, protect, toString, writableCopy
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Resource

public Resource()
Method Detail

get

public abstract Element get(Term term)
                     throws InvalidTermException
Retrieve the Element associated with the given Term (either an index or string key).

Parameters:
term - Term which acts as the key for the desired Element
Returns:
Element associated with the given Term
Throws:
InvalidTermException - thrown if the term is not of the appropriate type for the resource; the message should contain the string representation of the term

put

public abstract Element put(Term term,
                            Element newValue)
                     throws InvalidTermException
Define the mapping between the given Term and given Element. The method returns the previous value or null if there was none.

Parameters:
term - Term which acts as the key for the desired Element
newValue - Element to associate with the given Term
Returns:
previous value if it existed, null otherwise
Throws:
InvalidTermException - thrown if the term is not of the appropriate type for the resource; the message should contain the string representation of the term

size

public abstract int size()
Get the number of elements in this Resource.

Returns:
number of elements in this Resource

rget

public Element rget(Term[] terms,
                    int index,
                    boolean protect,
                    boolean lookupOnly)
             throws InvalidTermException
Description copied from class: Element
Dereference the Element to return the value of a child. Any resource should return the value of the given child. The default implementation of this method will throw an EvaluationException indicating that this Element cannot be dereferenced.

Overrides:
rget in class Element
Parameters:
terms - list of terms to use for dereference
index - the term to use in the given list of term
protect - flag to indicate that the return value should be a protected (if value is a resource)
lookupOnly - indicates that only a lookup is required, return null if the element doesn't exist
Throws:
InvalidTermException - thrown if an trying to dereference a list with a key or a hash with an index

rput

public void rput(Term[] terms,
                 int index,
                 Element value)
          throws InvalidTermException
Description copied from class: Element
Add the given child to this resource, creating intermediate resources as necessary. If this Element is not a resource, then this will throw an InvalidTermException. The default implementation of this method throws such an exception. This resource must be a writable resource, otherwise an exception will be thrown.

Overrides:
rput in class Element
Throws:
InvalidTermException - thrown if an trying to dereference a list with a key or a hash with an index

rgetList

public ListResource rgetList(Term[] terms,
                             int index)
                      throws InvalidTermException
Description copied from class: Element
This is a special lookup function that will retrieve a list from the resource. If the resource does not exist, an empty list will be created. All necessary parent resources are created. The returned list is guaranteed to be a writable resource.

Overrides:
rgetList in class Element
Parameters:
terms - list of terms to use for dereference
index - the term to use in the given list of term
Returns:
writable list
Throws:
InvalidTermException

iterator

public abstract Resource.Iterator iterator()
Get an iterator which allows to run over the resources in the Resource. Note that concurrent modification of the Resource is not permitted while actively using the iterator. The effects of doing so are undefined.

Specified by:
iterator in interface java.lang.Iterable<Resource.Entry>
Returns:
Iterator which will allow access to the key, value pairs of the Resource


Copyright © 2011 Quattor. All Rights Reserved.