org.argouml.cognitive
Class ItemUID

java.lang.Object
  extended byorg.argouml.cognitive.ItemUID

public class ItemUID
extends java.lang.Object

Instances of this class is supposed to be attached to other instances of other classes to uniquely identify them. It is intended that such a tagging should be persistent over saving and loading, if applicable.

The class also harbors the getIDOfObject(Object, boolean) which provides a way to get the ItemUID of any object with a method ItemUID getItemUID() and creating new ItemUIDs for any object with a method setItemUID(ItemUID) using reflection in java. A class intended to be tagged must at least provide a ItemUID getItemUID() method. It may also provide a void setItemUID(ItemUID id) such that getItemUID() will return id if a call returns successfully, and which is stored persistently should the tagged object be stored. This allows this class to automatically tag an object when necessary, but it is allowed to tag classes by other means and only provide the getItemUID() call. A critical requirement for this class is that the cognitive component is supposed to work with general objects. This class is a wrapper around places where the component needs persistent identities of objects, since I have said that some features cannot be implemented without that, such as ResolvedCritic, and so far noone has shown me wrong (though I wouldn't mind). It is for this reason that some perhaps ugly looking exceptions in this code must be considered perfectly normal conditions. Failure of some object to work with tagging must be handled by the cognitive component programmer and it is (see eg ResolvedCritic). A possible future change would be to allow tag handlers to be registered with this class to handle other preexisting tagging mechanisms, which could be used to remove the dependancy to the model component here, which I find a bit unaesthetic. So far, not enough to write it (though it is not much work).


Field Summary
protected  java.lang.String _id
          This actual ID of this instance.
protected static java.lang.Class _myclass
          Keeps a reference to the Class object of this class
protected static org.apache.log4j.Logger cat
           
 
Constructor Summary
ItemUID()
          Constructs a new ItemUID and creates a new ID for it.
ItemUID(java.lang.String param)
          Constructs a new ItemUID and uses the String param as the ID.
 
Method Summary
protected static java.lang.String createObjectID(java.lang.Object obj)
          Tries to create a new ID for the object.
static java.lang.String generateID()
          Generates a new unique ID and returns it as a String.
static java.lang.String getIDOfObject(java.lang.Object obj, boolean canCreate)
          Obtains the ID of an object and returns it as a String.
protected static java.lang.String readObjectID(java.lang.Object obj)
          Tries to read the ID of the object.
 java.lang.String toString()
          Returns the ID of this ItemUID as a String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

cat

protected static org.apache.log4j.Logger cat

_myclass

protected static final java.lang.Class _myclass
Keeps a reference to the Class object of this class


_id

protected java.lang.String _id
This actual ID of this instance.

Constructor Detail

ItemUID

public ItemUID()
Constructs a new ItemUID and creates a new ID for it.


ItemUID

public ItemUID(java.lang.String param)
Constructs a new ItemUID and uses the String param as the ID. Mainly intended to be used during loading of saved objects.

Parameters:
param - The ID to used for the new instance.
See Also:
toString()
Method Detail

toString

public java.lang.String toString()
Returns the ID of this ItemUID as a String. If everything works all such Strings will be unique. It is possible to created a new identical ItemUID using this String.

Returns:
The ID as a String.
See Also:
ItemUID(String)

generateID

public static java.lang.String generateID()
Generates a new unique ID and returns it as a String. The contents of the String is supposed to be unique with respect to all Strings generated by other instances of this class.

Returns:
A String with unique content.

getIDOfObject

public static java.lang.String getIDOfObject(java.lang.Object obj,
                                             boolean canCreate)
Obtains the ID of an object and returns it as a String. If canCreate is true it will try to create a new ID for the object if it has none.

Returns:
The ID of the object, or null.

readObjectID

protected static java.lang.String readObjectID(java.lang.Object obj)
Tries to read the ID of the object. It uses the reflective properties of java to access a method named getItemUID of the object which is expected to return an ItemUID.

Returns:
The ID of the object, or null.

createObjectID

protected static java.lang.String createObjectID(java.lang.Object obj)
Tries to create a new ID for the object. It uses the reflective properties of java to access a method named setItemUID(ItemUID). If that method exist and doesn't throw when called, then the call is assumed to have been successful and the object is responsible for remembering the ID.

Returns:
The new ID of the object, or null.


ArgoUML © 1996-2004 (20040316)ArgoUML HomepageArgoUML Developers' pageArgoUML Cookbook