Framework Professional Edition Package


org.mbs.services.cu.generator
Class DefaultControlUnitModel

java.lang.Object
  extended by org.mbs.services.cu.generator.DefaultControlUnitModel
All Implemented Interfaces:
ControlUnitModel
Direct Known Subclasses:
AbstractDeviceModel

public class DefaultControlUnitModel
extends java.lang.Object
implements ControlUnitModel

Default implementation of ControlUnitModel interface.

Since:
$Date: 2005/07/28 12:10:19 $
Author:
Stoyan Zoubev

Field Summary
protected  CUAdminCallback callback
          Reference to CUAdminCallback instance
protected  java.lang.String id
          the control unit type for which this object is model
protected  java.util.Hashtable stateVarValues
          a Hashtable with the state var values.
protected  java.lang.String type
          the control unit id for which this object is model
 
Constructor Summary
DefaultControlUnitModel(java.lang.String type, java.lang.String id)
          Constructs the model.
 
Method Summary
 CUAdminCallback getControlUnitCallback()
          Returns control unit callback.
 java.lang.String getId()
          Returns the CU Id for which this object is model.
protected  java.util.Hashtable getModelInitValues(java.util.Hashtable table)
          This method is invoked when the model is created or the model is reset.
 java.lang.String getType()
          Returns the CU TYPE for which this object is model.
 java.lang.Object queryStateVariable(java.lang.String varId)
          Retrieves state variable value by its Id.
 void release()
          Free the resources for the model.
 void reset()
          Resets the model.
 void setControlUnitCallback(CUAdminCallback callback)
           
protected  void updateStateVariableList()
          This methods is called in the constructor of the class.
 boolean updateSV(java.lang.String stateVarId, java.lang.Object stateVarValue)
          Check if the old value of the state variable stateVarId is different from the new one and notify all listeners that have registered interest in the state var with the given id.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stateVarValues

protected java.util.Hashtable stateVarValues
a Hashtable with the state var values. Key is state variable id, value is the current value of variable.


type

protected java.lang.String type
the control unit id for which this object is model


id

protected java.lang.String id
the control unit type for which this object is model


callback

protected CUAdminCallback callback
Reference to CUAdminCallback instance

Constructor Detail

DefaultControlUnitModel

public DefaultControlUnitModel(java.lang.String type,
                               java.lang.String id)
Constructs the model.

Parameters:
type - type of the control unit
id - id of the control unit
Method Detail

updateStateVariableList

protected void updateStateVariableList()
This methods is called in the constructor of the class. Its purpose is to extract all the state variable ids from stateVarValues hashtable into a String array and put that array back in the hashtable under the key ControlConstants.SV_LIST_SV_ID.

Note: ControlConstants.SV_LIST_SV_ID is not included in the array.

Note: If you add/remove values in the stateVarValues hashtable outside of the getModelInitValues method, be aware to call this method to update the state variable list.


updateSV

public boolean updateSV(java.lang.String stateVarId,
                        java.lang.Object stateVarValue)
Check if the old value of the state variable stateVarId is different from the new one and notify all listeners that have registered interest in the state var with the given id.
Note: It the given stateVarValue parameter is null, then listeners receive event for the current value of the model.

Specified by:
updateSV in interface ControlUnitModel
Parameters:
stateVarId - state variable Id
stateVarValue - a new value for the state variable, may be null
Returns:
true if state variable event is sent, otherwise false

queryStateVariable

public java.lang.Object queryStateVariable(java.lang.String varId)
                                    throws java.lang.IllegalArgumentException
Description copied from interface: ControlUnitModel
Retrieves state variable value by its Id. The state variable can be mapped directly or indirectly to the state variables of device for the particular protocol.

Specified by:
queryStateVariable in interface ControlUnitModel
Parameters:
varId - the id of required state variable.
Returns:
requested state variable value or throws IllegalArgumentException if it was not found.
Throws:
java.lang.IllegalArgumentException - if there is no state variable with this Id in this control unit
See Also:
org.mbs.services.control.generator.ControlUnitModel#queryStateVariable(java.lang.String)

getId

public java.lang.String getId()
Description copied from interface: ControlUnitModel
Returns the CU Id for which this object is model.

Specified by:
getId in interface ControlUnitModel
Returns:
the CU Id for which this object is model.
See Also:
org.mbs.services.control.generator.ControlUnitModel#getId()

getType

public java.lang.String getType()
Description copied from interface: ControlUnitModel
Returns the CU TYPE for which this object is model.

Specified by:
getType in interface ControlUnitModel
Returns:
the CU TYPE for which this object is model.
See Also:
org.mbs.services.control.generator.ControlUnitModel#getType()

reset

public void reset()
           throws java.lang.Exception
Resets the model.

Specified by:
reset in interface ControlUnitModel
Throws:
java.lang.Exception - thrown if error during reset occurs

getModelInitValues

protected java.util.Hashtable getModelInitValues(java.util.Hashtable table)
This method is invoked when the model is created or the model is reset. In the first case the table parameter is null, while in the second case it holds the current values of the state variables.

The methods should return the initial values for the model object; key is state variable id, value is the default value.

The default implementation just clears the given table, or creates a new one if it is not created.

Parameters:
table - table where to store model init values. If null, then a new Hashtable object is created.
Returns:
a Hashtable containing default values for the model object. Key is state var id, value is a default value for the state variable. The result can be either the same object passed as parameter or a new Hashtable object.

release

public void release()
Free the resources for the model. Subclasses may override this method to fit their needs.

Specified by:
release in interface ControlUnitModel

setControlUnitCallback

public void setControlUnitCallback(CUAdminCallback callback)
Specified by:
setControlUnitCallback in interface ControlUnitModel
See Also:
org.mbs.services.control.generator.ControlUnitModel#setControlUnitCallback(org.msb.services.cu.spi.CUAdminCallback)

getControlUnitCallback

public CUAdminCallback getControlUnitCallback()
Description copied from interface: ControlUnitModel
Returns control unit callback.

Specified by:
getControlUnitCallback in interface ControlUnitModel
See Also:
org.mbs.services.control.generator.ControlUnitModel#getControlUnitCallback()

Framework Professional Edition Package


Copyright © 1999-2007 ProSyst Software GmbH. All Rights Reserved