Homepage

org.tinymarbles.model
Class PType

java.lang.Object
  extended by org.tinymarbles.model.Persistent<String>
      extended by org.tinymarbles.model.PType

public class PType
extends Persistent<String>

Describes a persistent type.

Author:
duke

Constructor Summary
protected PType()
          Protected constructor for Hibernate
  PType(String name)
          Public constructor
 
Method Summary
protected  void add(PAttribute att)
          Used internally.
 void addDirtyInstance(PObject dirty)
          Add dirty PObject instance
 List<PAttribute> attributes()
          Gets an ordered list of persistent attributes.
 String describe()
          Builds a description based on the attributes defined for this type.
 boolean equals(Object obj)
           
 void fromMap(Map<String,Class<? extends PValue>> map)
          Populates this PType with new attributes based on a Map of Attribute names and its respectives value classes
 PAttribute getAttribute(String attName)
          Gets the persistent attribute with the given name
 Set<String> getAttributeNames()
          Gets the set of attribute names from this type.
protected  Map<String,PAttribute> getAttributes()
          Used internally.
 Set<PObject> getDirtyInstances()
          List all dirty instances from this type
 String getName()
          Gets the name of this type
 String getPersistentIdentifier()
          Returns the persistent identifier for the type.
 Integer getVersion()
          Used internally.
 boolean hasAttribute(String attName)
          Returns true if this type has an attribute with name attName.
 int hashCode()
           
 boolean isPersistent()
          Asks if the object is known by the repository
 PObject newInstance()
          Creates a new persistent object of this type.
 PObject newInstance(String systemId)
          Creates a new persistent object of this type.
 PType put(String attName, Class<? extends PValue> valueClass)
          Same as putAttribute but returns this instance to allow chaining.
 PAttribute putAttribute(String attName, Class<? extends PValue> valueClass)
          Puts an attribute in this type.
 void remove(String attName)
          Removes an attribute from this type.
 void removeDirtyInstance(PObject dirty)
          Remove dirty PObject instance
protected  void setAttributes(Map<String,PAttribute> attributes)
          Used internally.
 Map<String,Class<? extends PValue>> toMap()
          Gets a map with all attributes and its valueclass
 String toString()
          Returns a string representation of this instance.
 
Methods inherited from class org.tinymarbles.model.Persistent
delete, refresh, save
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PType

public PType(String name)
Public constructor

Parameters:
name - the name of the type. Must be unique in the repository

PType

protected PType()
Protected constructor for Hibernate

Method Detail

getVersion

public Integer getVersion()
Used internally. Gets the version of this type. Used for optimistic locking.

Returns:
the type's current version.

getAttributes

protected Map<String,PAttribute> getAttributes()
Used internally. Gets the persistent collection of attributes

Returns:
the attribute mapping

getAttributeNames

public Set<String> getAttributeNames()
Gets the set of attribute names from this type. The set is immutable.

Returns:
the set of attribute names for this type.
See Also:
attributes()

setAttributes

protected void setAttributes(Map<String,PAttribute> attributes)
Used internally. Sets the persistent collection of attributes

Parameters:
attributes - the attribute mapping

getName

public String getName()
Gets the name of this type

Returns:
the name of the type

putAttribute

public PAttribute putAttribute(String attName,
                               Class<? extends PValue> valueClass)
                        throws TypeMismatchException
Puts an attribute in this type. If an attribute with the same name and the same value class already exists in this type, it is returned.

Parameters:
attName - the name of the attribute
valueClass - the class of the implementation of this attribute.
Returns:
the persistent attribute definition
Throws:
TypeMismatchException - if there is another attribute with the same name, but a different value class
See Also:
getAttribute(String)

put

public PType put(String attName,
                 Class<? extends PValue> valueClass)
          throws TypeMismatchException
Same as putAttribute but returns this instance to allow chaining.

Parameters:
attName - the name of the attribute
valueClass - the class of the implementation of this attribute.
Returns:
this instance
Throws:
TypeMismatchException - if there is another attribute with the same name, but a different value class
See Also:
putAttribute(String, Class)

add

protected void add(PAttribute att)
Used internally. Adds an attribute to the persistent collection

Parameters:
att - the attribute to add

remove

public void remove(String attName)
Removes an attribute from this type.

Parameters:
attName - the name of the attribute to be removed

hasAttribute

public boolean hasAttribute(String attName)
Returns true if this type has an attribute with name attName. Returns false otherwise.

Parameters:
attName -
Returns:
true if the attribute is present

getAttribute

public PAttribute getAttribute(String attName)
                        throws UnknownAttributeException
Gets the persistent attribute with the given name

Parameters:
attName - the name of the attribute
Returns:
the persistent attribute
Throws:
UnknownAttributeException - if no attribute with the given name is defined

toMap

public Map<String,Class<? extends PValue>> toMap()
Gets a map with all attributes and its valueclass

Returns:
map with attribute name and value class

fromMap

public void fromMap(Map<String,Class<? extends PValue>> map)
             throws UnknownAttributeException
Populates this PType with new attributes based on a Map of Attribute names and its respectives value classes

Parameters:
map - a map of attribute names and values
Throws:
UnknownAttributeException - if a attribute in the map doesn't exist

attributes

public List<PAttribute> attributes()
Gets an ordered list of persistent attributes. The list is not modifiable. The attributes have an index and are sorted by their index order.

Returns:
an unmodifiable list with the attributes
See Also:
PAttribute.getIndex()

describe

public String describe()
Builds a description based on the attributes defined for this type.

Returns:
a formated description string

toString

public String toString()
Returns a string representation of this instance.

Overrides:
toString in class Object
See Also:
describe()

getPersistentIdentifier

public String getPersistentIdentifier()
Returns the persistent identifier for the type. In this case, the type's name

Specified by:
getPersistentIdentifier in class Persistent<String>
Returns:
the persistent identifier
See Also:
getName()

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

isPersistent

public boolean isPersistent()
Description copied from class: Persistent
Asks if the object is known by the repository

Specified by:
isPersistent in class Persistent<String>
Returns:
true if the object was saved at least once, false otherwise
See Also:
Persistent.getPersistentIdentifier()

newInstance

public PObject newInstance(String systemId)
Creates a new persistent object of this type.

Parameters:
systemId - the system ID of the object
Returns:
a new, unsaved persistent object
See Also:
newInstance()

newInstance

public PObject newInstance()
Creates a new persistent object of this type.

Returns:
a new, unsaved persistent object
See Also:
newInstance(String)

getDirtyInstances

public Set<PObject> getDirtyInstances()
List all dirty instances from this type

Returns:
a Set, dirty PObjects instances

addDirtyInstance

public void addDirtyInstance(PObject dirty)
Add dirty PObject instance

Parameters:
dirty - a PObject that must be saved

removeDirtyInstance

public void removeDirtyInstance(PObject dirty)
Remove dirty PObject instance

Parameters:
dirty - a PObject that must be removed

Homepage