at.spardat.xma.mdl.simple
Class SimpleWM

java.lang.Object
  extended byat.spardat.xma.mdl.WModel
      extended byat.spardat.xma.mdl.simple.SimpleWM
All Implemented Interfaces:
Descriptive, IAtomic, ISimpleWM, Synchronization, Transactional
Direct Known Subclasses:
SimpleWMClient

public class SimpleWM
extends WModel
implements ISimpleWM

Implements ISimpleWM.


Field Summary
protected  byte type_
          One of the type codes in enterprise.util.Types.
protected  java.lang.String value_
          A string encoded value of a particular type.
 
Fields inherited from class at.spardat.xma.mdl.WModel
S_NULL
 
Constructor Summary
SimpleWM(short id, byte type, Page pm)
          Constructs a SimpleWM.
 
Method Summary
 boolean changed()
          Yields true if this WidgetModel has changed since the last server side event (or creation).
 void clear()
          Sets this TextModel to the empty string.
 void commit()
          This method clears the change history.
 void describe(DNode n)
          describe puts all relevant information about this into the provided node.
 void equalsCS(WModel mServer, int syncPoint)
          Compares this widget model (which must be a client side one) with the server buddy mServer and returns true if they are correct with respect to syncPoint.
 int estimateMemory()
          Estimates the number of bytes this object consumes in memory.
 void externalize(XmaOutput xo, boolean forceFull)
          Externalizing either saves the actual state or deltas (changes) in a provided XMAObjectOutput.
 java.lang.String getEncodedValue()
          Returns the String encoded value of this.
 byte getType()
          Returns the type constant.
 boolean handle(ModelChangeEvent event)
          All events that might change a WidgetModel are executed via this method.
 boolean hasValue()
          Returns true if this model holds a value.
 void internalize(XmaInput in)
          Updates the state of this with information of the given XMAObjectInput.
 boolean isTrue()
          Returns true if getType() equals T_BOOLEAN and the stored value equals TRUE.
 void randomlyChange()
          Makes random changes to this
 void rollback()
          This method restores this Widget Model to its state immediately after the last server side event (or creation).
 void set(java.math.BigDecimal value)
          Sets the value from the provided BigDecimal.
 void set(boolean value)
          If getType() equals T_BOOLEAN, this method sets a boolean value, otherwise it does nothing.
 void set(java.lang.Boolean val)
          Sets the value from a Boolean.
 void set(java.lang.Byte val)
          Sets the value from a Byte.
 void set(java.util.Date value)
          Sets this from a provided java.util.Date.
 void set(double value)
          Sets the value from a double.
 void set(java.lang.Double val)
          Sets the value from a Double.
 void set(double value, int precision)
          Sets the value from a double.
 void set(java.lang.Float val)
          If the value is null, this is cleared.
 void set(int value)
          Sets this from an int.
 void set(java.lang.Integer val)
          Sets the value from an Integer.
 void set(java.lang.Long val)
          If the value is null, this is cleared.
 void set(java.lang.Short val)
          Sets the value from a Short.
 void set(java.lang.String value)
          Sets the value of this model from a string.
protected  void setInternal(java.lang.String value)
          This method requires that a legal internal representation has been constructed and manages the state in value_ and savedValue_.
protected  boolean settersShouldBeSloppy(Page pm)
          Determines if setters should ignore type violations.
 java.math.BigDecimal toBigDecimal()
          If the type of this is T_BCD, the numeric value is returned as a BigDecimal.
 byte toByte()
          Returns the value of this as byte.
 java.lang.Byte toBYTE()
          Returns the value of this as Byte or null if !
 java.util.Date toDate()
          Returns a newly constructed java.util.Date object representing the value of this.
 double toDouble()
          Extracts a double from this.
 java.lang.Double toDOUBLE()
          Returns the value of this as Double or null if !
 float toFloat()
          Extracts a float from this.
 java.lang.Float toFLOAT()
          Returns the value of this as Float or null if !
 int toInt()
          Returns the value of this as int if the type of this is T_BCD.
 java.lang.Integer toINTEGER()
          Returns the value of this as Integer or null if !
 long toLong()
          Returns the value of this as long.
 java.lang.Long toLONG()
          Returns the value of this as Long or null if !
 short toShort()
          Returns the value of this as short.
 java.lang.Short toSHORT()
          Returns the value of this as Short or null if !
 java.lang.String toString()
          Returns a String representing the value of this.
 java.lang.String toString(at.spardat.enterprise.fmt.IFmt formatter)
          Maps this to string representation using a IFmt object.
 
Methods inherited from class at.spardat.xma.mdl.WModel
cleanUpAfterServerEvent, getId
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

type_

protected byte type_
One of the type codes in enterprise.util.Types.


value_

protected java.lang.String value_
A string encoded value of a particular type. This instance is never null.

Constructor Detail

SimpleWM

public SimpleWM(short id,
                byte type,
                Page pm)
Constructs a SimpleWM.

Parameters:
id - a numeric id which identifies the WidgetModel within its Page.
type - a type constant.
pm - the Page this model belongs to
Method Detail

settersShouldBeSloppy

protected boolean settersShouldBeSloppy(Page pm)
Determines if setters should ignore type violations.


clear

public void clear()
Sets this TextModel to the empty string.

Specified by:
clear in interface ISimpleWM
Specified by:
clear in class WModel

hasValue

public boolean hasValue()
Returns true if this model holds a value.

Specified by:
hasValue in interface IAtomic
Returns:
true if this has a non empty value.

getType

public byte getType()
Returns the type constant.

Specified by:
getType in interface IAtomic
Returns:
the type constant, see Types.

toString

public java.lang.String toString()
Description copied from interface: IAtomic
Returns a String representing the value of this. Depending on the type of this, the following formats are returned:
 T_BOOLEAN     "J" or "N"
 T_STRING      the string itself
 T_BCD         -12000.32
 T_DATE        yyyyMMdd
               example: 20001231, the last day in the year 2000
 T_TIMESTAMP   yyyyMMdd HH:mm:ss.SSS z
               example: 20001231 23:59:59.999 CET denoting the last millisecond in the year 2000, central european time.
 T_DOM         key of the domain value
 
The empty string is returned if this does not store a value.

Specified by:
toString in interface IAtomic
Overrides:
toString in class WModel
See Also:
IAtomic.toString()

toString

public java.lang.String toString(at.spardat.enterprise.fmt.IFmt formatter)
Maps this to string representation using a IFmt object. The provided formatter is only used if it is type compatible with the type of this IAtomic. Otherwise, or if formatter is null, the internal String encoding is returned.

Specified by:
toString in interface IAtomic
Parameters:
formatter - the IFmt formatter. May be null.
Returns:
non null String.

set

public void set(java.lang.String value)
Sets the value of this model from a string. Clears this if value==null. Does nothing if getType() is not equal to T_STRING.

Specified by:
set in interface ISimpleWM
Parameters:
value - the string to set

toDouble

public double toDouble()
Extracts a double from this. Returns 0.0 if getType() is not equal to T_BCD or !hasValue().

Specified by:
toDouble in interface IAtomic
Returns:
double

toFloat

public float toFloat()
Description copied from interface: IAtomic
Extracts a float from this. Returns 0.0 if getType() is not equal to T_BCD or !hasValue().

Specified by:
toFloat in interface IAtomic
Returns:
the float value of this
See Also:
IAtomic.toFloat()

set

public void set(double value,
                int precision)
Sets the value from a double. Does nothing if getType() is not equal to T_BCD. Also does nothing if the provided double is NaN or Infinity.

Specified by:
set in interface ISimpleWM
Parameters:
value - the value to set
precision - the number of places after the comma used when converting the double to a string.

set

public void set(double value)
Sets the value from a double. Does nothing if getType() is not equal to T_BCD. Also does nothing if the provided double is NaN or Infinity. If the provided double (which is binary coded) would result in an unexact decimal representation, the fractional part of the result is stripped so that there are no more then 15 significant digits.

Specified by:
set in interface ISimpleWM
Parameters:
value - the value to set

set

public void set(java.math.BigDecimal value)
Description copied from interface: ISimpleWM
Sets the value from the provided BigDecimal. Clears this if value is null.

Specified by:
set in interface ISimpleWM
See Also:
ISimpleWM.set(java.math.BigDecimal)

toBigDecimal

public java.math.BigDecimal toBigDecimal()
Description copied from interface: IAtomic
If the type of this is T_BCD, the numeric value is returned as a BigDecimal. If the type is another than T_BCD or !hasValue() is true, then null is returned.

Specified by:
toBigDecimal in interface IAtomic
See Also:
IAtomic.toBigDecimal()

toInt

public int toInt()
Returns the value of this as int if the type of this is T_BCD. Returns 0 if the type is not T_BCD.

Specified by:
toInt in interface IAtomic
Returns:
the contained integer
See Also:
IAtomic.toInt()

toLong

public long toLong()
Description copied from interface: IAtomic
Returns the value of this as long. Requires that this is either empty or contains an T_BCD value. If !hasValue() or the type of this is not T_BCD, zero is returned.

Specified by:
toLong in interface IAtomic
Returns:
the contained value as long
See Also:
IAtomic.toLong()

toByte

public byte toByte()
Description copied from interface: IAtomic
Returns the value of this as byte. Requires that this is either empty or contains an T_BCD value. If !hasValue() or the type of this is not T_BCD, zero is returned.

Specified by:
toByte in interface IAtomic
Returns:
the contained value as long
See Also:
IAtomic.toByte()

toShort

public short toShort()
Description copied from interface: IAtomic
Returns the value of this as short. Requires that this is either empty or contains an T_BCD value. If !hasValue() or the type of this is not T_BCD, zero is returned.

Specified by:
toShort in interface IAtomic
Returns:
the contained value as long
See Also:
IAtomic.toShort()

toBYTE

public java.lang.Byte toBYTE()
Description copied from interface: IAtomic
Returns the value of this as Byte or null if !hasValue() or the type is not T_BCD.

Specified by:
toBYTE in interface IAtomic
See Also:
IAtomic.toByte()

toSHORT

public java.lang.Short toSHORT()
Description copied from interface: IAtomic
Returns the value of this as Short or null if !hasValue() or the type is not T_BCD.

Specified by:
toSHORT in interface IAtomic
See Also:
IAtomic.toSHORT()

toINTEGER

public java.lang.Integer toINTEGER()
Description copied from interface: IAtomic
Returns the value of this as Integer or null if !hasValue() or the type is not T_BCD.

Specified by:
toINTEGER in interface IAtomic
See Also:
IAtomic.toINTEGER()

toLONG

public java.lang.Long toLONG()
Description copied from interface: IAtomic
Returns the value of this as Long or null if !hasValue() or the type is not T_BCD.

Specified by:
toLONG in interface IAtomic
See Also:
IAtomic.toLONG()

toFLOAT

public java.lang.Float toFLOAT()
Description copied from interface: IAtomic
Returns the value of this as Float or null if !hasValue() or the type is not T_BCD.

Specified by:
toFLOAT in interface IAtomic
See Also:
IAtomic.toFLOAT()

toDOUBLE

public java.lang.Double toDOUBLE()
Description copied from interface: IAtomic
Returns the value of this as Double or null if !hasValue() or the type is not T_BCD.

Specified by:
toDOUBLE in interface IAtomic
See Also:
IAtomic.toDOUBLE()

set

public void set(java.lang.Boolean val)
Description copied from interface: ISimpleWM
Sets the value from a Boolean. If val is null, this is cleared.

Specified by:
set in interface ISimpleWM
Parameters:
val - the value to set
See Also:
ISimpleWM.set(java.lang.Boolean)

set

public void set(java.lang.Byte val)
Description copied from interface: ISimpleWM
Sets the value from a Byte.

If the value is null, this is cleared.

Specified by:
set in interface ISimpleWM
See Also:
ISimpleWM.set(java.lang.Byte)

set

public void set(java.lang.Short val)
Description copied from interface: ISimpleWM
Sets the value from a Short.

If the value is null, this is cleared.

Specified by:
set in interface ISimpleWM
See Also:
ISimpleWM.set(java.lang.Short)

set

public void set(java.lang.Integer val)
Description copied from interface: ISimpleWM
Sets the value from an Integer.

If the value is null, this is cleared.

Specified by:
set in interface ISimpleWM
See Also:
ISimpleWM.set(java.lang.Integer)

set

public void set(java.lang.Long val)
Description copied from interface: ISimpleWM
If the value is null, this is cleared.

Specified by:
set in interface ISimpleWM
See Also:
ISimpleWM.set(java.lang.Long)

set

public void set(java.lang.Float val)
Description copied from interface: ISimpleWM
If the value is null, this is cleared.

Specified by:
set in interface ISimpleWM
See Also:
ISimpleWM.set(java.lang.Float)

set

public void set(java.lang.Double val)
Description copied from interface: ISimpleWM
Sets the value from a Double.

If the value is null, this is cleared.

Specified by:
set in interface ISimpleWM
See Also:
ISimpleWM.set(java.lang.Double)

set

public void set(int value)
Sets this from an int. Does nothing if the type of this is not T_BCD.

Specified by:
set in interface ISimpleWM
Parameters:
value - the provided integer to set.

toDate

public java.util.Date toDate()
Returns a newly constructed java.util.Date object representing the value of this.

Specified by:
toDate in interface IAtomic
Returns:
null if the type is not equal to T_DATE or T_TIMESTAMP or !hasValue().

set

public void set(java.util.Date value)
Sets this from a provided java.util.Date. This method does nothing if the type is not equal to T_DATE or T_TIMESTAMP.

Specified by:
set in interface ISimpleWM
Parameters:
value - the value to set

isTrue

public boolean isTrue()
Returns true if getType() equals T_BOOLEAN and the stored value equals TRUE. If there is no value stored or the stored value is not TRUE, false is returned.

Specified by:
isTrue in interface IAtomic
Returns:
boolean indicating the value in this.

set

public void set(boolean value)
If getType() equals T_BOOLEAN, this method sets a boolean value, otherwise it does nothing.

Specified by:
set in interface ISimpleWM
Parameters:
value - the boolean value to set

changed

public boolean changed()
Description copied from class: WModel
Yields true if this WidgetModel has changed since the last server side event (or creation). Some models have a more complex state, e.g., a table has a domain and a selection, where either may change. In this case, subclasses will provide more detailed information on what aspect of the model really has changed.

Specified by:
changed in interface Transactional
Specified by:
changed in class WModel
Returns:
true if changed, false otherwise
See Also:
WModel.changed()

commit

public void commit()
Description copied from class: WModel
This method clears the change history. Calling rollback afterwards won't have any effect.

Specified by:
commit in interface Transactional
Specified by:
commit in class WModel
See Also:
WModel.commit()

handle

public boolean handle(ModelChangeEvent event)
Description copied from class: WModel
All events that might change a WidgetModel are executed via this method.

Specified by:
handle in class WModel
Parameters:
event - the event carrying the information of a change.
Returns:
true if change has been applied, false if it has been rejected.
See Also:
WModel.handle(ModelChangeEvent)

rollback

public void rollback()
Description copied from class: WModel
This method restores this Widget Model to its state immediately after the last server side event (or creation).

Specified by:
rollback in interface Transactional
Specified by:
rollback in class WModel
See Also:
WModel.rollback()

externalize

public void externalize(XmaOutput xo,
                        boolean forceFull)
                 throws java.io.IOException
Description copied from interface: Synchronization
Externalizing either saves the actual state or deltas (changes) in a provided XMAObjectOutput. The default behaviour is to serialize the changes if changes are beeing tracked. This behaviour may be overwritten by forceFull. If true, the complete state information is written.

If forceFull is false, the object implementing this interface must also implement Transactional. If the object implementing this is able to track changes, these are the changes since the last syncpoint.

Specified by:
externalize in interface Synchronization
Parameters:
xo - the serialization destination
forceFull - if true, the complete state is written and deltas are ignored.
Throws:
java.io.IOException - on serialization errors
See Also:
Synchronization.externalize(at.spardat.xma.serializer.XmaOutput, boolean)

internalize

public void internalize(XmaInput in)
                 throws java.io.IOException,
                        java.lang.ClassNotFoundException
Description copied from interface: Synchronization
Updates the state of this with information of the given XMAObjectInput. in either contains changes or the complete new state information. If in contains changes the implementing class also must implement Transactional and the state after calling internalize is !Transactional.changed(), e.g., a syncpoint is defined.

This method is not allowed to throw Exceptions because that would leave models in an inconsistent state. Thrown exceptions are considered to be programming errors. Internalize must not throw technical exceptions which indicate system or ressource failures. That implies that the person implementing internalize is not allowed to access ressources outside the JVM, either directly or via calls to other methods. Examples of ressource access which must not be triggered are calls to communication of file system services.

Specified by:
internalize in interface Synchronization
Parameters:
in - the XMAObjectInput. If a XMAObjectInputChangeListener is set in the object in, it will be notified after applying changes read from in.
Throws:
java.lang.ClassNotFoundException - on serialization errors
java.io.IOException - on serialization errors
See Also:
Synchronization.internalize(at.spardat.xma.serializer.XmaInput)

setInternal

protected void setInternal(java.lang.String value)
This method requires that a legal internal representation has been constructed and manages the state in value_ and savedValue_. If there is no saved state (savedValue_ equals null) and the provided value is different, the state is saved before. If there is a value provided which equals the saved state, the saved state is cleared. Either way, the provided value becomes the one stored in instance variable value_.

Parameters:
value - the new value to set

describe

public void describe(DNode n)
Description copied from interface: Descriptive
describe puts all relevant information about this into the provided node. The implementing method may construct subnodes of node.

Specified by:
describe in interface Descriptive
Overrides:
describe in class WModel
See Also:
Descriptive.describe(at.spardat.xma.mdl.util.DNode)

randomlyChange

public void randomlyChange()
Makes random changes to this

Specified by:
randomlyChange in class WModel

equalsCS

public void equalsCS(WModel mServer,
                     int syncPoint)
Description copied from class: WModel
Compares this widget model (which must be a client side one) with the server buddy mServer and returns true if they are correct with respect to syncPoint. If syncPoint is zero, the client model has been externalized and the changes have been applied to the server model. If synPoint is one, the server model has been externalized and the chagnes have been applied to the client model.

This method is for debugging purpose and assumes that client and server models are running within the same VM. It tests if the models the programmer views after a synchronization operation are consistent.

This method requires that this is a client side model.

This method does not throw an exception if models are the same in terms of their contained model data. If it is allowed that models differ (for example some one way tables), this method must take this fact into account. If the models differ, this indicates a programming error and a RuntimeException is thrown.

Specified by:
equalsCS in class WModel
Parameters:
mServer - the server side model partner for this.
syncPoint - 0 if the point in time is after a client to server sychnronization, 1 if the point is after a server to client synchronization.
See Also:
WModel.equalsCS(at.spardat.xma.mdl.WModel, int)

estimateMemory

public int estimateMemory()
Estimates the number of bytes this object consumes in memory.

Specified by:
estimateMemory in class WModel
Returns:
estimated number of bytes this model consumes in memory

getEncodedValue

public java.lang.String getEncodedValue()
Description copied from interface: IAtomic
Returns the String encoded value of this. Returns the empty String if !hasValue().

Specified by:
getEncodedValue in interface IAtomic
See Also:
IAtomic.getEncodedValue()