Framework Professional Edition Package


org.mbs.services.cu.generator
Class DefaultControlUnit

java.lang.Object
  extended by org.mbs.services.cu.generator.ServiceObject
      extended by org.mbs.services.cu.generator.DefaultControlUnit
All Implemented Interfaces:
ControlConstants, ControlUnit, ManagedControlUnit
Direct Known Subclasses:
DeviceControlUnit, TokenControlUnit

public class DefaultControlUnit
extends ServiceObject
implements ManagedControlUnit, ControlConstants

This is implementation of the the main interface of the Control Unit abstraction layer.

Author:
Stoyan Zoubev

Field Summary
static java.lang.String ACTION_PREFIX
           
static boolean CHECK_INPUT
           
protected  java.lang.Object controller
          the controller used by the ControlUnit to send commands to the control unit
protected  java.util.Dictionary controllerMethods
          the cached controller methods
protected  ControlUnitModel model
          the model holding the current state of the control unit
 
Fields inherited from interface org.mbs.services.cu.ControlConstants
CONSTRUCTOR_PREFIX, DESTRUCTOR, EVENT_FILTER, EVENT_SYNC, EVENT_TYPE, FINDER_PREFIX, ID, PARENT_ID, PARENT_ROOT, PARENT_TYPE, STATE_VARIABLE_ID, SV_LIST_SV_ID, TYPE, VERSION
 
Constructor Summary
DefaultControlUnit(ControlUnitModel model, java.lang.Object controller)
          Instantiate the ControlUnit.
 
Method Summary
protected  void checkActionInputArguments(java.lang.String actionId, java.lang.Object args)
          This method is invoked when invoking an action if CHECK_INPUT flag is set.
protected  void fillDefaultProperties(java.util.Dictionary props)
          This method is invoked when service is registed.
 java.lang.String getId()
          Returns id of the control unit which uniquely identifies it in the scope of its parent.
 java.lang.String getType()
          Returns type of the control unit.
 java.lang.Object invokeAction(java.lang.String actionId, java.lang.Object args)
          Executes the specified action over this control unit.
 java.lang.Object queryStateVariable(java.lang.String svarId)
          Returns the value of a specified state variable.
 void release()
          Release the resources used by this ControlUnit
 void setControlUnitCallback(CUAdminCallback callback)
          Supplies the Control Unit admin callback interface to the implementation of the ManagedControlUnit service.
 
Methods inherited from class org.mbs.services.cu.generator.ServiceObject
registerService, unregisterService
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHECK_INPUT

public static final boolean CHECK_INPUT

ACTION_PREFIX

public static final java.lang.String ACTION_PREFIX
See Also:
Constant Field Values

controller

protected java.lang.Object controller
the controller used by the ControlUnit to send commands to the control unit


model

protected ControlUnitModel model
the model holding the current state of the control unit


controllerMethods

protected java.util.Dictionary controllerMethods
the cached controller methods

Constructor Detail

DefaultControlUnit

public DefaultControlUnit(ControlUnitModel model,
                          java.lang.Object controller)
Instantiate the ControlUnit.

Parameters:
model - model of the control unit
controller - controller for the control unit
Method Detail

getType

public java.lang.String getType()
Description copied from interface: ControlUnit
Returns type of the control unit.

Specified by:
getType in interface ControlUnit
Returns:
the type of the control unit
See Also:
org.msb.services.cu.ControlUnit#getType()

getId

public java.lang.String getId()
Description copied from interface: ControlUnit
Returns id of the control unit which uniquely identifies it in the scope of its parent.

Specified by:
getId in interface ControlUnit
Returns:
the id of the control unit
See Also:
org.msb.services.cu.ControlUnit#getId()

fillDefaultProperties

protected void fillDefaultProperties(java.util.Dictionary props)
This method is invoked when service is registed. The implementation of the method should put the necessary properties in the given props dictionary. For control units these default properties are type and id.

Specified by:
fillDefaultProperties in class ServiceObject
Parameters:
props - dictionary where default properties are stored.

release

public void release()
Release the resources used by this ControlUnit


invokeAction

public java.lang.Object invokeAction(java.lang.String actionId,
                                     java.lang.Object args)
                              throws java.lang.Exception
Description copied from interface: ControlUnit
Executes the specified action over this control unit. Actions supported by a control unit and the number and types of the input and output arguments of each action are defined by the metadata of the control unit.

Specified by:
invokeAction in interface ControlUnit
Parameters:
actionId - the id of the action
args - the input argument(s). If the argument is only one this is the argument itself. If the arguments are more then one, the value must be a Object[] and arguments are retrieved from that array.
Returns:
the output argument(s) or null if the action does not return value.
Throws:
java.lang.Exception - if an error occurs while executing action.
java.lang.IllegalArgumentException - if this control unit does not have action with the supplied Id or the arguments number and/or types do not match the action arguments.
See Also:
org.msb.services.cu.ControlUnit#invokeAction(java.lang.String, java.lang.Object)

checkActionInputArguments

protected void checkActionInputArguments(java.lang.String actionId,
                                         java.lang.Object args)
This method is invoked when invoking an action if CHECK_INPUT flag is set. By default, this method does nothing.

Parameters:
actionId - id of the control unit action
args - action input arguments
Throws:
java.lang.IllegalArgumentException - thrown if an argument is invalid

queryStateVariable

public java.lang.Object queryStateVariable(java.lang.String svarId)
Description copied from interface: ControlUnit
Returns the value of a specified state variable. State variables supported by a control unit and their types are defined by the metadata of the control unit.

Specified by:
queryStateVariable in interface ControlUnit
Parameters:
svarId - the id of the variable
Returns:
value of the variable
See Also:
org.msb.services.cu.ControlUnit#queryStateVariable(java.lang.String)

setControlUnitCallback

public void setControlUnitCallback(CUAdminCallback callback)
Description copied from interface: ManagedControlUnit
Supplies the Control Unit admin callback interface to the implementation of the ManagedControlUnit service.
This method is invoked by the Control Unit Admin bundle with a non-null argument after registration of the ManagedControlUnit service or after startup of the Control Unit Admin for already registered control units.
It is supposed that the Managed Control Unit will assign this reference to an instance variable and use it later to notify the Control Unit Admin for changes in the state variables of the Control Unit.
The method is invoked with a null argument during unregistration of the ManagedControlUnit service or when the Control Unit Admin is stopped.

Specified by:
setControlUnitCallback in interface ManagedControlUnit
Parameters:
callback - reference to the control unit callback interface or null if previously set reference is not longer valid.
See Also:
org.msb.services.cu.spi.ManagedControlUnit#setControlUnitCallback(org.msb.services.cu.spi.CUAdminCallback)

Framework Professional Edition Package


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