org.quattor.pan.dml.data
Class ProtectedListResource

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
              extended by org.quattor.pan.dml.data.ListResource
                  extended by org.quattor.pan.dml.data.ProtectedListResource
All Implemented Interfaces:
java.lang.Iterable<Resource.Entry>, Operation

public class ProtectedListResource
extends ListResource


Nested Class Summary
 
Nested classes/interfaces inherited from class org.quattor.pan.dml.data.Resource
Resource.Entry, Resource.Iterator
 
Constructor Summary
ProtectedListResource(ListResource baseList)
           
 
Method Summary
 void checkRange(Range range)
          Determine if the element satisfies the given range constraint.
 Element duplicate()
          This method does a "clone" of the given Element.
 boolean equals(java.lang.Object o)
          Require that all Elements implement an equals method.
 Element get(Term key)
          Retrieve the Element associated with the given Term (either an index or string key).
protected  java.util.List<Element> getBackingList()
          Override this method to return the list from the base list.
 int hashCode()
          Require that all Elements implement the hashCode method.
 boolean isProtected()
          This method indicates if the given Element is protected.
 Resource.Iterator iterator()
          Get an iterator which allows to run over the resources in the Resource.
 java.lang.String locateUndefinedElement()
          Determine if the element contains any undefined (transient) elements.
 Element protect()
          Return a protected version of this Element.
 Element put(int index, Element newValue)
          This is an optimized version of the put method which doesn't require creating a Term object.
 Element put(Term key, Element newValue)
          Define the mapping between the given Term and given Element.
 void rput(Term[] terms, int index, Element value)
          Add the given child to this resource, creating intermediate resources as necessary.
 int size()
          Get the number of elements in this Resource.
 java.lang.String toString()
          Require that all Elements implement a reasonable toString method.
 Element writableCopy()
          This method returns a writable copy of this Element.
 
Methods inherited from class org.quattor.pan.dml.data.ListResource
append, checkValidReplacement, getTypeAsString, prepend
 
Methods inherited from class org.quattor.pan.dml.data.Resource
rget, rgetList
 
Methods inherited from class org.quattor.pan.dml.data.Element
checkInvalidSelfContext, checkRestrictedContext, defined, execute, exists, isBoolean, isDouble, isList, isLong, isNlist, isPersistent, isProperty, isResource, isString, isTransient
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ProtectedListResource

public ProtectedListResource(ListResource baseList)
Method Detail

duplicate

public Element duplicate()
Description copied from class: Element
This method does a "clone" of the given Element. Immutable Elements may return a reference to the same object. Mutable Elements (i.e. Resources) must provide an actual deep-copy of the Element. This method simply returns a reference to the same object and is suitable only for immutable subclasses. Mutable subclasses (i.e. Resources) must override this method to provide an appropriate deep copy. This is not actually named "clone" because it violates the conditions of that method for creating a duplicate of the instance in all cases.

Overrides:
duplicate in class ListResource
Returns:
deep-copy of Element for mutable elements, self-reference for immutable objects

get

public Element get(Term key)
            throws InvalidTermException
Description copied from class: Resource
Retrieve the Element associated with the given Term (either an index or string key).

Overrides:
get in class ListResource
Parameters:
key - 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 Element put(Term key,
                   Element newValue)
            throws InvalidTermException
Description copied from class: Resource
Define the mapping between the given Term and given Element. The method returns the previous value or null if there was none.

Overrides:
put in class ListResource
Parameters:
key - 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

put

public Element put(int index,
                   Element newValue)
Description copied from class: ListResource
This is an optimized version of the put method which doesn't require creating a Term object.

Overrides:
put in class ListResource
Parameters:
index - index of the element to insert
newValue - value to insert into the list
Returns:
old value if it existed

size

public int size()
Description copied from class: Resource
Get the number of elements in this Resource.

Overrides:
size in class ListResource
Returns:
number of elements in this Resource

iterator

public Resource.Iterator iterator()
Description copied from class: Resource
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>
Overrides:
iterator in class ListResource
Returns:
Iterator which will allow access to the key, value pairs of the Resource

locateUndefinedElement

public java.lang.String locateUndefinedElement()
Description copied from class: Element
Determine if the element contains any undefined (transient) elements. The call will return null if no undefined elements are found; it will return a string indicating the relative path if an undefined element is found. Subclasses MUST override this method appropriately. This default method will work only for elements which are not containers and not a transient element.

Overrides:
locateUndefinedElement in class ListResource
Returns:
String representation of the path of the undefined element, null otherwise

checkRange

public void checkRange(Range range)
                throws ValidationException
Description copied from class: Element
Determine if the element satisfies the given range constraint. This is used in the validation of the element. By default, this method with throw a ValidationException indicating that range checking of this element is not appropriate.

Overrides:
checkRange in class ListResource
Parameters:
range - Range to check Element against
Throws:
ValidationException - if the element cannot be compared to a range or if the element doesn't meet the range requirement

protect

public Element protect()
Description copied from class: Element
Return a protected version of this Element. The default implementation just returns to "this". Only unprotected resources will have to override this implementation.

Overrides:
protect in class ListResource
Returns:
protected version of the resource

hashCode

public int hashCode()
Description copied from class: Element
Require that all Elements implement the hashCode method.

Overrides:
hashCode in class ListResource

equals

public boolean equals(java.lang.Object o)
Description copied from class: Element
Require that all Elements implement an equals method.

Overrides:
equals in class ListResource

getBackingList

protected java.util.List<Element> getBackingList()
Override this method to return the list from the base list. This allows use of the superclass' equals method.

Overrides:
getBackingList in class ListResource
Returns:
backing list for list resource

toString

public java.lang.String toString()
Description copied from class: Element
Require that all Elements implement a reasonable toString method.

Overrides:
toString in class ListResource

isProtected

public boolean isProtected()
Description copied from class: Element
This method indicates if the given Element is protected. A protected element may not be written to and concerns just resources. The default implementation just returns false. This should be sufficient except for protected resources.

Overrides:
isProtected in class Element

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 Resource
Throws:
InvalidTermException - thrown if an trying to dereference a list with a key or a hash with an index

writableCopy

public Element writableCopy()
Description copied from class: Element
This method returns a writable copy of this Element. The default implementation just returns a reference to the same Element. This is the correct behavior for any object that returns false for the isProtected method. Objects that return true for isProtected, must override this method.

Overrides:
writableCopy in class Element
Returns:
returns a writable copy of this element; if the current element is not protected, then a reference to this object is returned


Copyright © 2011 Quattor. All Rights Reserved.