thinkmap.client
Class EntityId

java.lang.Object
  extended by thinkmap.client.EntityId
All Implemented Interfaces:
Serializable

public final class EntityId
extends Object
implements Serializable

An EntityId is an object that uniquely identifies an entity in a datasource. An EntityId consists of an "entity type" and a set of keys. The entity type determines the "type" or namespace of entity this id (usually the same as the table name in a database) and the keys represent a set of identifiers that are unique to that namespace. EntityIds can be in two modes: open or closed, once an EntityId is closed, it becomes immutable and cannot be altered.

Version:
$Revision: 1.8 $
See Also:
Serialized Form

Constructor Summary
EntityId()
          Creates a new EntityId object.
EntityId(EntityId id)
          Creates a new EntityId object that is identical to another EntityId.
EntityId(String entityType)
          Creates a new EntityId object of a particular entity type.
EntityId(String entityType, Object... keyValues)
          Creates a new EntityId object with the specified type and keys.
 
Method Summary
 void addKey(Object o)
          Adds a key to this EntityId.
 void close()
          Close this EntityId and make it immutable.
 boolean equals(Object a)
           
static boolean equals(Object o1, Object o2)
          A utility method for comparing objects.
static EntityId fromString(String idString)
          Parse a string representing an EntityId.
 String getEntityType()
          Get the EntityId's type name
 Object getKey(int i)
          Get the key at the specified index.
 int getKeyCount()
          Get the number of keys this EntityId contains.
 Object[] getKeys()
          Get the keys of this EntityId.
 int hashCode()
           
 boolean isClosed()
          Determines if this EntityId is closed and is immutable.
 void setEntityType(String type)
          Set the EntityId's type name.
 void setKeys(Object[] keys)
          Set the keys of this EntityId.
 String toString()
           
 void writeTo(IEntityHandler handler, boolean md)
          Serializes this EntityId over the given datasource entity handler.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EntityId

public EntityId()
Creates a new EntityId object. Keys and entitytype must be set/added later.


EntityId

public EntityId(String entityType)
Creates a new EntityId object of a particular entity type. Keys must be set/added later.


EntityId

public EntityId(String entityType,
                Object... keyValues)
Creates a new EntityId object with the specified type and keys. This id is marked as closed and keys and type cannot be added or set later.

Parameters:
entityType - entity type name
keyValues - an array of objects to use as keys

EntityId

public EntityId(EntityId id)
         throws IllegalArgumentException
Creates a new EntityId object that is identical to another EntityId.

Parameters:
id - the EntityId to copy
Throws:
IllegalArgumentException - if the EntityId to copy was not closed.
Method Detail

getEntityType

public String getEntityType()
Get the EntityId's type name

Returns:
type name

setEntityType

public void setEntityType(String type)
                   throws IllegalArgumentException
Set the EntityId's type name.

Parameters:
type - new type name
Throws:
IllegalArgumentException - if the EntityId is closed.

getKeyCount

public int getKeyCount()
Get the number of keys this EntityId contains.

Returns:
key count

getKey

public Object getKey(int i)
Get the key at the specified index.

Parameters:
i - key index
Returns:
the
i
th key

getKeys

public Object[] getKeys()
Get the keys of this EntityId.

Returns:
an array of keys

setKeys

public void setKeys(Object[] keys)
             throws IllegalArgumentException
Set the keys of this EntityId.

Parameters:
keys - an array of keys
Throws:
IllegalArgumentException - if the EntityId is closed.

addKey

public void addKey(Object o)
            throws IllegalArgumentException
Adds a key to this EntityId.

Parameters:
o - a key to add
Throws:
IllegalArgumentException - if the EntityId is closed.

isClosed

public boolean isClosed()
Determines if this EntityId is closed and is immutable.

Returns:
true if this EntityId is closed and is immutable

close

public void close()
Close this EntityId and make it immutable.


writeTo

public void writeTo(IEntityHandler handler,
                    boolean md)
Serializes this EntityId over the given datasource entity handler.

Parameters:
handler - the IEntityHandler to write this EntityId to
md - true if this id represents metadata, false if it represents data. If true is passed, all keys must be of type java.lang.Class.

fromString

public static EntityId fromString(String idString)
Parse a string representing an EntityId. The string should be of the form type:key[,key[...]]

Parameters:
idString - a string representing an EntityId
Returns:
the EntityId represented by the given string

hashCode

public final int hashCode()
Overrides:
hashCode in class Object

equals

public final boolean equals(Object a)
Overrides:
equals in class Object

equals

public static final boolean equals(Object o1,
                                   Object o2)
A utility method for comparing objects. This will handle null objects correctly.

Parameters:
o1 - first object
o2 - second object
Returns:
true if the objects are equal.

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2013 Thinkmap, Inc. All Rights Reserved.