com.ibm.tspaces.xtuples
Class XTuple

java.lang.Object
  |
  +--com.ibm.tspaces.xtuples.XTuple

public class XTuple
extends java.lang.Object
implements java.io.Serializable

XTuple.java * XTuple is the object that each XMLized Tuple contains. It is a wrapper class for the XML data unsuitable for representation in the top-level tuple, which also includes methods to access the data and traverse the Tuple Tree. The data portion includes attributes, which are stored in a vector of name, value pair objects, an object reference to the TupleTree object, and Tuple references for its children Tuples in the Tuple tree.

Tuples which are part of the special Tuple Tree structure all have a well defined format:
NamedField(tupleName) = (String), NamedField(tupleData) = (XTuple), ... rest of the fields can contain the regular tuple data. This should only include 1 s * manipulation by TSpaces or whatever internal mechanisms are inside TSpaces,tring field for recently converted XML tags, but after we may have more than one value field. The Tuple Tree to XML conversion will deal with that.

 The internals of the XTuple object are as follows:
 1. Vector: attributes stored as TAttr objects
 2. TupleTree: reference to TupleTree object
 3. Vector: childTuples stored as TupleID objects
 4. TupleID: parent tuple reference through TupleID
 5. NamedField(tupleType) = (int), 
 

Author:
Ben Y. Zhao
See Also:
TupleTree, XMLField, SuperTuple, XTupleException, Serialized Form

Field Summary
static int CDATA_TUPLE
           
static int ELEMENT_TUPLE
           
static int TEXT_TUPLE
           
 
Constructor Summary
XTuple(TupleTree tt, com.ibm.tspaces.server.TSDB dbPtr, java.lang.String cID)
           
 
Method Summary
 void appendChild(SuperTuple newChild)
          Method to append a child to the end of the children list
 void appendChild(TupleID newChildTID)
          Method to append a child to the end of the children list, via TupleID
 java.lang.String getAttribute(java.lang.String attrName)
          Method to get a single attribute by name.
 java.util.Vector getAttributes()
          Method to return a Vector of all attributes For code consistency and security, the Vector returned is actually just a clone of the Vector, so all additions to the attribute list and removals of attributes have to be done by using the class methods provided in this class.
 java.util.Vector getChildTupleIds()
          Get the child tuple ids of the current Tuple we need this on the client side because we cannot get the list of tuples using the server-side methods, ie: db.fetchTupleById(...) in "getTuple(...)" after we get this, we can manually read each tuple by it's id.
 java.util.Vector getChildTuples()
          Get all child tuples of the current Tuple
 SuperTuple getFirstChild()
          Method to return the first child of the Tuple Returns null if no children tuples exist
 SuperTuple getLastChild()
          Gets the last child (if any) of the current tuple, otherwise null
 TupleID getParentID()
          Method to get the TupleID of the parent tuple without actually retrieving the tuple itself.
 SuperTuple getParentTuple()
          Method to grab the parent Tuple
 TupleTree getTupleTree()
          TupleTree getTupleTree() ** get the tupletree reference
 int getTupleType()
          Method to return the TupleType as a constant int
 java.lang.String getTupleValue(SuperTuple thisTuple)
          Method that gets the tuple value of the tuple passed in.
 boolean hasChildTuples()
          Method to check if a tuple has any children tuples
 boolean insertBefore(SuperTuple newChild, SuperTuple refChild)
          Method to insert a child before a reference child in the child list
 boolean removeAttribute(java.lang.String attrName)
          Method to remove an attribute from a Tuple The method returns true if the attribute was found.
 boolean removeChild(Tuple oldChild)
          Method to remove a child reference from the child tuple vector.
 boolean replaceChild(SuperTuple newChild, SuperTuple oldChild)
          Method to replace a child tuple with a new child tuple in the child list The method returns true or false depending on whether the oldchild could be found or not.
 void setAttribute(java.lang.String attrName, java.lang.String attrValue)
          Method to set an attribute for a Tuple If the attribute exists, it's first removed, and then replaced with the new attribute
 void setParentTuple(TupleID parentID)
          Method to set the parent node by inserting a reference to the parent tuple's TupleID
 void setTupleType(int tt)
          Method to set the TupleType as a constant int
 void setTupleValue(SuperTuple thisTuple, java.lang.String newValue)
          Method that sets the tupleContent field of a tuple passed in as an argument.
 java.lang.String toString()
          This method basically does a core dump of the contents of the current XTuple class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CDATA_TUPLE

public static final int CDATA_TUPLE

ELEMENT_TUPLE

public static final int ELEMENT_TUPLE

TEXT_TUPLE

public static final int TEXT_TUPLE
Constructor Detail

XTuple

public XTuple(TupleTree tt,
              com.ibm.tspaces.server.TSDB dbPtr,
              java.lang.String cID)
Method Detail

getTupleTree

public TupleTree getTupleTree()
TupleTree getTupleTree() ** get the tupletree reference
Returns:
tupletree

getChildTuples

public java.util.Vector getChildTuples()
Get all child tuples of the current Tuple
Returns:
vector containing a bunch of Tuple objects

getChildTupleIds

public java.util.Vector getChildTupleIds()
Get the child tuple ids of the current Tuple we need this on the client side because we cannot get the list of tuples using the server-side methods, ie: db.fetchTupleById(...) in "getTuple(...)" after we get this, we can manually read each tuple by it's id. Tom Fischer (9/10/99)
Returns:
a vector containing a bunch of TupleID objects (representing the children)

getFirstChild

public SuperTuple getFirstChild()
Method to return the first child of the Tuple Returns null if no children tuples exist
Returns:
Tuple: the child tuple, null if none

getLastChild

public SuperTuple getLastChild()
Gets the last child (if any) of the current tuple, otherwise null
Returns:
the last child tuple if it exists, or null otherwise

hasChildTuples

public boolean hasChildTuples()
Method to check if a tuple has any children tuples
Returns:
true or false depending on whether it has children tuples

insertBefore

public boolean insertBefore(SuperTuple newChild,
                            SuperTuple refChild)
Method to insert a child before a reference child in the child list
Parameters:
newChild - - The new tuple to be inserted
refChild - - The old tuple in front of which the new child will be added

appendChild

public void appendChild(SuperTuple newChild)
Method to append a child to the end of the children list
Parameters:
newChild - - The new child to be added to the child tuple list

appendChild

public void appendChild(TupleID newChildTID)
Method to append a child to the end of the children list, via TupleID
Parameters:
newChildTID - - The new child's TupleID

removeChild

public boolean removeChild(Tuple oldChild)
Method to remove a child reference from the child tuple vector. If the child is not found inside the vector, the method returns false.
Returns:
boolean: whether the child ref is found

replaceChild

public boolean replaceChild(SuperTuple newChild,
                            SuperTuple oldChild)
Method to replace a child tuple with a new child tuple in the child list The method returns true or false depending on whether the oldchild could be found or not.

Returns:
boolean whether the oldchild was found

getParentTuple

public SuperTuple getParentTuple()
Method to grab the parent Tuple
Returns:
The tuple that is returned by DB.fetchTupleById(TupleID) It will return null if the parentTuple value is null.

getParentID

public TupleID getParentID()
Method to get the TupleID of the parent tuple without actually retrieving the tuple itself.
Returns:
TupleID of the parentTuple, or null if none exists

setParentTuple

public void setParentTuple(TupleID parentID)
Method to set the parent node by inserting a reference to the parent tuple's TupleID
Parameters:
parentID - The TupleID of the parent tuple

getTupleType

public int getTupleType()
                 throws XTupleException
Method to return the TupleType as a constant int
Returns:
The tupleType as an int

setTupleType

public void setTupleType(int tt)
                  throws XTupleException
Method to set the TupleType as a constant int

getTupleValue

public java.lang.String getTupleValue(SuperTuple thisTuple)
                               throws TupleSpaceException
Method that gets the tuple value of the tuple passed in. If the tuple has no current tupleContent field set, then we return null.
Parameters:
thisTuple - The tuple whose value we're reading
Returns:
string encoding the value of the Tuple.

setTupleValue

public void setTupleValue(SuperTuple thisTuple,
                          java.lang.String newValue)
                   throws TupleSpaceException
Method that sets the tupleContent field of a tuple passed in as an argument. If the tuple had no previous value, the field is added with the new value.
Parameters:
thisTuple - the tuple whose value is to be set
newValue - The new value of the String

getAttribute

public java.lang.String getAttribute(java.lang.String attrName)
Method to get a single attribute by name.
Parameters:
String - attrName in String format
Returns:
String encoding the attribute value

setAttribute

public void setAttribute(java.lang.String attrName,
                         java.lang.String attrValue)
Method to set an attribute for a Tuple If the attribute exists, it's first removed, and then replaced with the new attribute
Parameters:
attrName - The attribute name as a String
attrValue - The attribute value as a String

removeAttribute

public boolean removeAttribute(java.lang.String attrName)
Method to remove an attribute from a Tuple The method returns true if the attribute was found. If the attribute does not exist, then the method returns false.

Parameters:
attrName - The name of the attribute to be removed as a String
Returns:
boolean: whether the attribute was found in the Tuple

getAttributes

public java.util.Vector getAttributes()
Method to return a Vector of all attributes For code consistency and security, the Vector returned is actually just a clone of the Vector, so all additions to the attribute list and removals of attributes have to be done by using the class methods provided in this class.
Returns:
Vector which contains copies of all attributes in this node.

toString

public java.lang.String toString()
This method basically does a core dump of the contents of the current XTuple class. It will print out all of the values, including the attributes, pointer to tree, child tuple references, parent tuple reference, and clientID

Overrides:
toString in class java.lang.Object
Returns:
Pretty print string with all the class contents