fr.ocelet.runtime
Class AbstractEntity

Package class diagram package AbstractEntity
java.lang.Object
  extended by fr.ocelet.runtime.AbstractEntity
All Implemented Interfaces:
Entity, Role
Direct Known Subclasses:
Model

public abstract class AbstractEntity
extends java.lang.Object
implements Entity

Contains the common behavior for all kinds of entities. Maintains the list of properties and their transaction mechanism.


Field Summary
protected  java.util.HashMap<java.lang.String,Hproperty<?>> propmap
           
protected  boolean transaction
           
 
Constructor Summary
protected AbstractEntity()
           
 
Method Summary
protected  void defProperty(java.lang.String pname, Hproperty<?> hp)
          Defines and adds a new property to this entity.
<T> T
getProperty(java.lang.String pname)
          Property getter.
<T> T
getProperty(java.lang.String pname, int hindex)
          Property getter.
<T> void
setProperty(java.lang.String pname, AffectOperator<T> ao, T val)
          The behavior of this property setter is different if the transaction is true or false.
<T> void
setProperty(java.lang.String pname, T val)
          The behavior of this property setter is different if the transaction is true or false.
 void tabort()
          Ends a transaction aborting any property change.
 void tbegin()
          Begins a transaction for this entity.
 void tcommit()
          Ends a transaction for this entity.
 java.lang.String toString()
          Overrides the Object.toString()
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

transaction

protected boolean transaction

propmap

protected java.util.HashMap<java.lang.String,Hproperty<?>> propmap
Constructor Detail

AbstractEntity

protected AbstractEntity()
Method Detail

defProperty

protected void defProperty(java.lang.String pname,
                           Hproperty<?> hp)
Defines and adds a new property to this entity.

Parameters:
pname - Name of the property to add to this entity
hp - The property itself

setProperty

public <T> void setProperty(java.lang.String pname,
                            T val)
The behavior of this property setter is different if the transaction is true or false. If transaction is false, the property is directly set to val. If transaction is true, val is added to the property's list of new value candidates and that list will be later processed, at the end of the transaction. Note that when the transaction end, an AffectOperator will be used to compute the new values candidate list. If no AffectOperator has been given to the property, the Any is the default affectation operator that will be used.

Specified by:
setProperty in interface Role
Parameters:
pname - Name of the property
val - Candidate new value for the property.

setProperty

public <T> void setProperty(java.lang.String pname,
                            AffectOperator<T> ao,
                            T val)
The behavior of this property setter is different if the transaction is true or false. If transaction is false, the property is directly set to val. If transaction is true, val is added to the property's list of new value candidates and that list will be later processed, at the end of the transaction. This method should only be called when transaction is true

Specified by:
setProperty in interface Role
Parameters:
pname - Name of the property
ao - The affectation operator Class to be applied when the transaction will end.
val - Candidate new value for the property.

getProperty

public <T> T getProperty(java.lang.String pname)
Property getter. The returned value is the last valid state of the property. It means that if new values have been assigned to that property but the transaction has not been yet committed, the value returned is the state before assigning those new values.

Specified by:
getProperty in interface Role
Parameters:
pname - Name of the property to get.
Returns:
The value corresponding to the last valid state of that property.

getProperty

public <T> T getProperty(java.lang.String pname,
                         int hindex)
Property getter. The returned value is the historic state of the property pointed by the null or negative index given in argument. A call to getProperty(name,0) is equivalent to getProperty(name).

Parameters:
pname - Name of the property to get.
hindex - Null or negative index to indicate at what point of the history the value must be read
Returns:
The value corresponding to the historic state pointed by hindex.

tbegin

public void tbegin()
Begins a transaction for this entity. Any call to setProperty will just add the new values given to a new value candidate list and the new state of the property will not be update until we get a call to tcommit().

Specified by:
tbegin in interface Role

tcommit

public void tcommit()
Ends a transaction for this entity. All it's properties are assigned their new values of any has been assigned during the transaction. It means that the entity officially switches from state n to state n+1.

Specified by:
tcommit in interface Role

tabort

public void tabort()
Ends a transaction aborting any property change. All values assigned to any property since the last tbegin() are lost.

Specified by:
tabort in interface Role

toString

public java.lang.String toString()
Overrides the Object.toString()

Overrides:
toString in class java.lang.Object
Returns:
A string in the form prop1_name=prop1_value; prop2_name=prop2_value; etc.