All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.ibm.tspaces.FieldPS

java.lang.Object
   |
   +----com.ibm.tspaces.Field
           |
           +----com.ibm.tspaces.FieldPS

public class FieldPS
extends Field
implements Serializable
FieldPS is a subclass of the T Spaces Field class. It modifies the implementation of Field so that the value of a Field that will contain a user defined object is serialized into an array of bytes prior to being sent to the server. This avoids the problem of having to have user defined class object available in the Server classpath. At the time that the FieldPS object is created or when the value is set using the setValue() method, the user defined object is serialized to a byte[] object and this is stored in the Field theValue instance variable. When the value is requested, the byte[] in "theValue" is deserialized back to the user defined object and returned to the caller.
 An Example of usage:
    	Example4aObj obj = new Example4aObj("User Object 1");
		FieldPS f2 = new FieldPS(obj);		
		Tuple tup = new Tuple("Key1",f2);
		ts.write(tup);
    At this point, the object is stored on the server only
    as a byte[] object.  Now we will read it back.  
    Note that we use the regular Field class for the template.
		Tuple template = new Tuple("Key1",new Field(Example4aObj.class) );
		mytuple = (Tuple)ts.take(template);		
		Example4aObj objreturned = (Example4aObj)mytuple.getField(1).value();
 There is no reason to believe that if you took 2 equal objects (equality defined by 
 the "equal" method) that the 2 serialized bag of bytes would be equal.  Therefore
 you should not do indexing of a FieldPS or use a FieldPS value in a 
 template.  However, you will get no warning if you try this.  Don't try it!
 Perhaps somebody should throw an exception if you even try it.

Author:
John Thomas
See Also:
Field, Tuple, TupleSpace

Constructor Index

 o FieldPS(Class)
Create a FieldPS that has the Class as its type.
 o FieldPS(Class, Serializable)
Create a FieldPS that has the value Object.
 o FieldPS(FieldPS)
Create a FieldPS from another FieldPS.
 o FieldPS(Serializable)
Create a FieldPS that has the value Object.
 o FieldPS(String, Class)
Create a named FieldPS that has the Class as its type.
 o FieldPS(String, Class, Serializable)
Create a named FieldPS that has the Class as its type and the passed Object as its value.
 o FieldPS(String, Serializable)
Create a named FieldPS that has the value Serializable.

Method Index

 o assign(FieldPS)
Assign the type and value of another FieldPS to this FieldPS.
 o main(String[])
Test routine for FieldPS
 o matches(FieldPS)
Return true if the specified FieldPS matches this FieldPS.
 o setType(Class)
Set the type of the FieldPS.
 o setValue(Serializable)
Set the value of the FieldPS to be any Serializable.
 o toString()
Return a String that represents the FieldPS.
 o type()
Return the Class instance that represents the type of the FieldPS.
 o value()
Return the value of the FieldPS.

Constructors

 o FieldPS
 public FieldPS(Serializable v) throws TupleSpaceException
Create a FieldPS that has the value Object. The type of the FieldPS is the type (Class) of the value.

Parameters:
v - The value of the FieldPS
Throws: TupleSpaceException
if there is a problem creating the FieldPS
 o FieldPS
 public FieldPS(Class t,
                Serializable v) throws TupleSpaceException
Create a FieldPS that has the value Object. The Class parameter must be the same as the type of the Object. This method is used for Objects that might be null.

Parameters:
v - The value of the FieldPS
Throws: TupleSpaceException
if there is a problem creating the FieldPS
 o FieldPS
 public FieldPS(String name,
                Class t,
                Serializable v) throws TupleSpaceException
Create a named FieldPS that has the Class as its type and the passed Object as its value. Used for named Fields with possibly null values.

Parameters:
name - The name of the FieldPS. null is allowed.
t - The type of the FieldPS.
v - The value of the FieldPS. null is allowed.
Throws: TupleSpaceException
If the type of the class does not match the type of the value.
 o FieldPS
 public FieldPS(Class t) throws TupleSpaceException
Create a FieldPS that has the Class as its type. The FieldPS does not have a value, this is used to specify a formal FieldPS that can be used in a simple query to match another FieldPS of this type that has any value. Note: this just calls the Field superclass.

Parameters:
t - The value of the class
Throws: TupleSpaceException
if there is a problem creating the FieldPS
 o FieldPS
 public FieldPS(String name,
                Class t) throws TupleSpaceException
Create a named FieldPS that has the Class as its type. The FieldPS does not have a value, this is used to specify a formal FieldPS that can be used in a simple query to match another FieldPS of this type that has any value.

Parameters:
name - The name of the FieldPS.
t - The type of the FieldPS.
Throws: TupleSpaceException
if there is a problem creating the FieldPS
 o FieldPS
 public FieldPS(String name,
                Serializable v) throws TupleSpaceException
Create a named FieldPS that has the value Serializable. The type of the FieldPS is the type (Class) of the value.

Parameters:
name - The name of the FieldPS.
v - The value of the FieldPS.
Throws: TupleSpaceException
if there is a problem creating the FieldPS
 o FieldPS
 public FieldPS(FieldPS f)
Create a FieldPS from another FieldPS. The name is not copied.

Parameters:
f - The FieldPS to copy.

Methods

 o setType
 public void setType(Class t)
Set the type of the FieldPS. This removes any value the FieldPS may have had. This is used to specify a formal FieldPS that can be used in a simple query to match a FieldPS of this type with any value.

Parameters:
t - The new type of the FieldPS.
Overrides:
setType in class Field
 o setValue
 public void setValue(Serializable v) throws TupleSpaceException
Set the value of the FieldPS to be any Serializable. The type of the FieldPS is the type (Class) of the value.

Parameters:
v - The value of the FieldPS.
Throws: TupleSpaceException
if there is a problem creating the FieldPS
Overrides:
setValue in class Field
 o assign
 public void assign(FieldPS f)
Assign the type and value of another FieldPS to this FieldPS. This does not assign the name.

Parameters:
f - The FieldPS to be assigned.
 o type
 public Class type()
Return the Class instance that represents the type of the FieldPS.

Returns:
A Class instance that represents the type of the FieldPS.
Overrides:
type in class Field
 o value
 public Serializable value()
Return the value of the FieldPS.

Returns:
An Serializable instance that is the value of the FieldPS.
Overrides:
value in class Field
 o matches
 public boolean matches(FieldPS f)
Return true if the specified FieldPS matches this FieldPS. Two Fields match if either is formal and they both have the same type. If neither is formal, then the two Fields match if they have the same type (Class) and their values are equal. FieldPS names are not compared.

Override this method to change the matching behavior.

Parameters:
f - The FieldPS to compare.
Returns:
true if the two Fields match, false otherwise.
 o toString
 public String toString()
Return a String that represents the FieldPS. If the FieldPS does not have a value then return the name of the Class that is the type of the FieldPS. If the FieldPS does have a value then return the string representation of the value of the FieldPS.

Returns:
A String that represents the FieldPS.
Overrides:
toString in class Field
 o main
 public static void main(String argv[])
Test routine for FieldPS


All Packages  Class Hierarchy  This Package  Previous  Next  Index