SmartFrog 3.10.000

org.smartfrog.sfcore.reference
Class Reference

java.lang.Object
  extended by org.smartfrog.sfcore.reference.Reference
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Copying
Direct Known Subclasses:
ApplyReference, SFReference

public class Reference
extends java.lang.Object
implements Copying, java.lang.Cloneable, java.io.Serializable

A reference is a list of ReferencePart objects. An example of a reference is: ATTRIB a-b, which would resolve to an attribute in one of the containing contexts called a, which has to be a component that contains an attribute named b. <br > WARNING: References are not safe for use in hashtables (and therefor as attribute keys) if they are modified, since the hashCode is based on the first element.

See Also:
Serialized Form

Field Summary
protected  boolean data
          Indicator whether reference is data or link.
protected  boolean eager
          Indicator whether reference is eager or lazy.
static int inc
          Capacity increment for references.
static int initCap
          Initial capacity for references.
protected  java.util.Vector ref
          Actual reference.
 
Constructor Summary
Reference()
          Constructs an empty reference.
Reference(java.lang.Object referencePart)
          Constructs a reference with a single reference part from a String.
Reference(ReferencePart referencePart)
          Constructs a reference with a single reference part.
Reference(java.lang.String refString, boolean parse)
          Constructs a reference with a single reference part from a String or from a string in cannonical form using the parser.
 
Method Summary
 ReferencePart addElement(ReferencePart o)
          Adds element to the end of the reference.
 Reference addElements(Reference ref)
          Adds a reference to the end of the reference.
 java.lang.Object clone()
          Makes a clone of the reference.
 Reference clone(int start, int len)
          Clone this reference from start with length elements.
 java.lang.Object copy()
          Returns a copy of the reference, by cloning itself and then copying all the reference parts.
 ReferencePart elementAt(int index)
          Returns element at index.
 java.util.Enumeration elements()
          Returns an enumeration over the elements of the reference.
 boolean equals(java.lang.Object ref)
          Checks if this and given reference are equal.
 ReferencePart firstElement()
          Returns first element of reference.
static Reference fromString(java.lang.String refString)
          Utility method to create a reference from a string.
 boolean getData()
          Gets the data flag for the reference.
 boolean getEager()
          Gets the eager flag for the reference.
 int hashCode()
          Returns the hashcode for this reference.
 ReferencePart lastElement()
          Returns last element in reference.
 boolean removeElement(ReferencePart o)
          Remove element from reference.
 java.lang.Object resolve(ReferenceResolver rr, int index)
          Resolves this reference using the given reference resolver, and starting at index of this reference.
 java.lang.Object resolve(RemoteReferenceResolver rr, int index)
          Resolves this reference using the given remote reference resolver, and starting at index of this reference.
 boolean setData(boolean data)
          Sets the data flag for the reference.
 boolean setEager(boolean eager)
          Sets the eager flag for the reference.
 ReferencePart setElementAt(ReferencePart elem, int index)
          Sets the element at given index to a new element.
 int size()
          Returns the size of the reference.
 java.lang.String toString()
          Returns string representation of the reference.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

initCap

public static int initCap
Initial capacity for references. Looks up Reference.initCap (offset by propBase). Defaults to 5 if not there

See Also:
Reference

inc

public static int inc
Capacity increment for references. Looks up Reference.inc (offset by propBase). Defaults to 2 if not there

See Also:
Reference

ref

protected java.util.Vector ref
Actual reference.


eager

protected boolean eager
Indicator whether reference is eager or lazy.


data

protected boolean data
Indicator whether reference is data or link.

Constructor Detail

Reference

public Reference()
Constructs an empty reference.


Reference

public Reference(java.lang.Object referencePart)
Constructs a reference with a single reference part from a String.

Parameters:
referencePart - part to be put in reference

Reference

public Reference(java.lang.String refString,
                 boolean parse)
          throws SmartFrogResolutionException
Constructs a reference with a single reference part from a String or from a string in cannonical form using the parser.

Parameters:
refString - to be put/used in reference
parse - boolean to ask for string reference to be parsed or not
Throws:
SmartFrogResolutionException - if reference is not valid

Reference

public Reference(ReferencePart referencePart)
Constructs a reference with a single reference part.

Parameters:
referencePart - part to be put in reference
Method Detail

fromString

public static Reference fromString(java.lang.String refString)
                            throws SmartFrogResolutionException
Utility method to create a reference from a string. Uses the SFParser class.

Parameters:
refString - string representing reference
Returns:
new reference parsed from string
Throws:
SmartFrogResolutionException - if illegal reference in string

copy

public java.lang.Object copy()
Returns a copy of the reference, by cloning itself and then copying all the reference parts.

Specified by:
copy in interface Copying
Returns:
copy of reference
See Also:
Copying

clone

public java.lang.Object clone()
Makes a clone of the reference. The inside ref holder is cloned, but the contained reference parts are NOT. If a CloneException occurs null is returned

Specified by:
clone in interface Copying
Overrides:
clone in class java.lang.Object
Returns:
clone of reference or null on clone error

clone

public Reference clone(int start,
                       int len)
Clone this reference from start with length elements. Reference parts are NOT copied. On clone failure, null is returned

Parameters:
start - index for copy
len - length of copy
Returns:
clone of part of reference

getEager

public boolean getEager()
Gets the eager flag for the reference.

Returns:
current eager flag
See Also:
setEager(boolean)

setEager

public boolean setEager(boolean eager)
Sets the eager flag for the reference.

Parameters:
eager - new eager flag
Returns:
old eager flag
See Also:
getEager()

getData

public boolean getData()
Gets the data flag for the reference.

Returns:
current data flag
See Also:
setData(boolean)

setData

public boolean setData(boolean data)
Sets the data flag for the reference.

Parameters:
data - new data flag
Returns:
old data flag
See Also:
getData()

equals

public boolean equals(java.lang.Object ref)
Checks if this and given reference are equal. Two references are considered to be equal if all their reference parts are equal. Reference equality does NOT mean that the two references point to the same object

Overrides:
equals in class java.lang.Object
Parameters:
ref - to be compared
Returns:
true if equal, false if not

hashCode

public int hashCode()
Returns the hashcode for this reference. Hash code for reference is made out of the sum of the parts hashcodes

Overrides:
hashCode in class java.lang.Object
Returns:
integer hashcode

elements

public java.util.Enumeration elements()
Returns an enumeration over the elements of the reference.

Returns:
enumeration of elements

size

public int size()
Returns the size of the reference.

Returns:
size of reference

elementAt

public ReferencePart elementAt(int index)
Returns element at index.

Parameters:
index - to look up
Returns:
reference to the element

setElementAt

public ReferencePart setElementAt(ReferencePart elem,
                                  int index)
Sets the element at given index to a new element.

Parameters:
elem - element to set to
index - index to set at
Returns:
previous value at given index

lastElement

public ReferencePart lastElement()
Returns last element in reference.

Returns:
last element in reference. Null if none

firstElement

public ReferencePart firstElement()
Returns first element of reference.

Returns:
first element

addElement

public ReferencePart addElement(ReferencePart o)
Adds element to the end of the reference.

Parameters:
o - reference part to add
Returns:
part that was added

addElements

public Reference addElements(Reference ref)
Adds a reference to the end of the reference. ReferenceParts in the given reference are NOT copied.

Parameters:
ref - of elements to be added
Returns:
Reference reference that was added to this one

removeElement

public boolean removeElement(ReferencePart o)
Remove element from reference.

Parameters:
o - to remove from reference
Returns:
true if element there and removed, false otherwise

resolve

public java.lang.Object resolve(ReferenceResolver rr,
                                int index)
                         throws SmartFrogResolutionException
Resolves this reference using the given reference resolver, and starting at index of this reference. If the reference size is 0 the given reference resolver is returned.

Parameters:
rr - ReferenceResolver to be used for resolving this reference
index - index of first referencepart to start resolving at
Returns:
attribute found on resolving this reference
Throws:
SmartFrogResolutionException - reference failed to resolve

resolve

public java.lang.Object resolve(RemoteReferenceResolver rr,
                                int index)
                         throws SmartFrogResolutionException
Resolves this reference using the given remote reference resolver, and starting at index of this reference. If the reference size is 0 the given reference resolver is returned.

Parameters:
rr - ReferenceResolver to be used for resolving this reference
index - index of first referencepart to start resolving at
Returns:
attribute found on resolving this reference
Throws:
SmartFrogResolutionException - if reference failed to resolve

toString

public java.lang.String toString()
Returns string representation of the reference. Overrides Object.toString.

Overrides:
toString in class java.lang.Object
Returns:
String representing the reference

SmartFrog CORE 3.10.000

(C) Copyright 1998-2006 Hewlett-Packard Development Company, LP