de.cau.cs.kieler.sim.kiem.config.data
Class ConfigDataComponent

java.lang.Object
  extended by de.cau.cs.kieler.sim.kiem.internal.AbstractDataComponent
      extended by de.cau.cs.kieler.sim.kiem.JSONObjectDataComponent
          extended by de.cau.cs.kieler.sim.kiem.config.data.ConfigDataComponent
All Implemented Interfaces:
IDataComponent, IJSONObjectDataComponent, IExecutableExtension

public class ConfigDataComponent
extends JSONObjectDataComponent

Holds all information needed for the currently running schedule.
For example:
Aimed Step Duration
Timeouts
...and user defined variables

Rating proposed yellow
(2010-01-27)

Field Summary
static String CONFIG_ID
          The key for the config component.
 
Fields inherited from class de.cau.cs.kieler.sim.kiem.internal.AbstractDataComponent
MASTER_CMD_MACROSTEP, MASTER_CMD_PAUSE, MASTER_CMD_RUN, MASTER_CMD_STEP, MASTER_CMD_STEPBACK, MASTER_CMD_STOP
 
Constructor Summary
ConfigDataComponent()
          Creates a new ConfigDataComponent.
ConfigDataComponent(boolean initWithDefaults)
          Creates a new ConfigDataComponent.
 
Method Summary
 KiemProperty findProperty(KiemPropertyKeyWrapper key)
          Try to find the property in this configuration.
 String findPropertyValue(KiemPropertyKeyWrapper key)
          Try to find the value of a property in this configuration.
static ConfigDataComponent fromString(String input)
          Creates a new data component from a String.
 String getDataComponentId()
          Gets the String representation id of a DataComponent.
 DataComponentWrapper getWrapper()
          Getter for the wrapper.
 void initialize()
          Initialize.
 boolean isInvisible()
          If the component doesn't want to appear in the scheduling list, it may set this flag to true.
 boolean isObserver()
          To check whether the DataComponent is an observer.
 boolean isProducer()
          To check whether the DataComponent is a producer.
 KiemProperty[] provideProperties()
          Provide properties for this component.
 void removeProperty(KiemPropertyKeyWrapper key)
          Remove properties with a specified key.
 void setWrapper(DataComponentWrapper wrapperParam)
          Setter for the wrapper.
 JSONObject step(JSONObject jSONObject)
          Step method for a DataObserver and a DataPrroducer.
 String toString()
          
 KiemProperty updateProperty(KiemPropertyKeyWrapper key, String value)
          Update the property with a new value.
 void wrapup()
          Wrap-up.
 
Methods inherited from class de.cau.cs.kieler.sim.kiem.JSONObjectDataComponent
getInitialVariables, provideFilterKeysJSON, provideInitialVariables, setInitialVariables
 
Methods inherited from class de.cau.cs.kieler.sim.kiem.internal.AbstractDataComponent
checkProperties, finalize, getConfigurationElement, getCurrentComponentID, getName, getPluginId, getProperties, getShell, isDeltaObserver, isHistoryObserver, isHistoryStep, isMacroStepDone, isMaster, isMasterImplementingGUI, isMultiInstantiable, masterCommand, masterGetAimedStepDuration, masterGUI, masterGUIisEnabled, masterIsPaused, masterIsRunning, masterSetAimedStepDuration, masterSetKIEMInstance, notifyEvent, provideEventOfInterest, provideFilterKeys, setConfigurationElemenet, setCurrentComponentID, setHistoryStep, setInitializationData, setProperties
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CONFIG_ID

public static final String CONFIG_ID
The key for the config component.

See Also:
Constant Field Values
Constructor Detail

ConfigDataComponent

public ConfigDataComponent()
Creates a new ConfigDataComponent. That should be initialized with values from the default configuration.


ConfigDataComponent

public ConfigDataComponent(boolean initWithDefaults)
Creates a new ConfigDataComponent.

Parameters:
initWithDefaults - true if the component should initialize from defaults
Method Detail

findProperty

public KiemProperty findProperty(KiemPropertyKeyWrapper key)
                          throws KiemPropertyException
Try to find the property in this configuration.

Parameters:
key - the key to look for.
Returns:
the found property.
Throws:
KiemPropertyException - if no property was found.

findPropertyValue

public final String findPropertyValue(KiemPropertyKeyWrapper key)
                               throws KiemPropertyException
Try to find the value of a property in this configuration.

Parameters:
key - the key to look for.
Returns:
the found value.
Throws:
KiemPropertyException - if no value was found.

removeProperty

public final void removeProperty(KiemPropertyKeyWrapper key)
Remove properties with a specified key.

Parameters:
key - the key to look for.

updateProperty

public final KiemProperty updateProperty(KiemPropertyKeyWrapper key,
                                         String value)
Update the property with a new value.

If the property doesn't exist yet it will be created and initialized with the new value.

Parameters:
key - the key of the property to look for.
value - the new value of the property.
Returns:
the KiemProperty that was updated.

initialize

public void initialize()
                throws KiemInitializationException
Initialize. Do some initializing prior to execution. If an error occurs during initialization, the DataComponent should raise a KiemInitializationException.

Throws:
KiemInitializationException - a KiemInitializationException

getDataComponentId

public final String getDataComponentId()
Description copied from class: AbstractDataComponent
Gets the String representation id of a DataComponent. The id will be constituted by getting the pluginID and adding information about the implemented extension point, i.e., the property types and names and the type of DataProducer. Note that this class can be overridden if the implementation wants to provide its own identification.

Overrides:
getDataComponentId in class AbstractDataComponent
Returns:
".config"

isObserver

public final boolean isObserver()
To check whether the DataComponent is an observer. If the DataComponent is an observer the arguments in its step() method will be != null.

Returns:
true, if is observer

isProducer

public final boolean isProducer()
To check whether the DataComponent is a producer. If the DataComponent is a producer it should return != null in its step() method.

Returns:
true, if is producer

wrapup

public void wrapup()
            throws KiemInitializationException
Wrap-up. Do some wrapping-up after execution has finished. If an error occurs during wrap up, the DataComponent should raise a KiemInitializationException.

Throws:
KiemInitializationException - a KiemInitializationException

step

public JSONObject step(JSONObject jSONObject)
                throws KiemExecutionException
Step method for a DataObserver and a DataPrroducer.

For a producer only the argument will always be null. For an observer only this method will be called asynchronous. This may mean that in case the observer is slow, it may be skipped at some consecutive steps until it becomes ready again. If this is not desired and the observer MUST NOT be skipped, then the DataComponent should also be a DataProducer but return just null.

If an error occurs during the execution of the step method, a DataComponent should raise a KiemExecutionException that is then catched by the execution manager an brought to the user's attention.

Parameters:
jSONObject - the concrete JSONObject of input data (if observer)
Returns:
the JSONObject with the output data (if producer)
Throws:
KiemExecutionException - a KiemExecutionException

fromString

public static ConfigDataComponent fromString(String input)
Creates a new data component from a String.

Parameters:
input - the input string.
Returns:
the created component.

toString

public String toString()

Overrides:
toString in class Object

isInvisible

public boolean isInvisible()
If the component doesn't want to appear in the scheduling list, it may set this flag to true. This implies that the specific component then cannot be added or removed.

Overrides:
isInvisible in class AbstractDataComponent
Returns:
true, if is invisible

getWrapper

public DataComponentWrapper getWrapper()
Getter for the wrapper.

Returns:
the wrapper

setWrapper

public void setWrapper(DataComponentWrapper wrapperParam)
Setter for the wrapper.

Parameters:
wrapperParam - the wrapper to set

provideProperties

public KiemProperty[] provideProperties()
Provide properties for this component. The component may create and publicize its properties with this method. They will be set/modified by the execution manager during the user edits them. Whenever the user decides to run/start the execution the properties are tested (see below) and the component may use there settings.

The following lists a simple example for such properties:
\ATOverride
public KiemProperty[] provideProperties() {
KiemProperty[] properties = new KiemProperty[7];
properties[0] = new KiemProperty(
"state name",
"state");
properties[1] = new KiemProperty(
"some bool",
true);
properties[2] = new KiemProperty(
"an integer",
2);
properties[3] = new KiemProperty(
"a file",
new KiemPropertyTypeFile(),
"c:/nothing.txt");
String[] items = {"trace 1","trace 2", "trace 3", "trace 4"};
properties[4] = new KiemProperty(
"a choice",
new KiemPropertyTypeChoice(items),
items[2]);
properties[5] = new KiemProperty(
"workspace file",
new KiemPropertyTypeWorkspaceFile(),
"/nothing.txt");
properties[6] = new KiemProperty(
"editor",
new KiemPropertyTypeEditor(),
"");
return properties;
}

These are built-in types that can always be extended using the KiemProperty class.

Overrides:
provideProperties in class AbstractDataComponent
Returns:
the KiemProperty[] or null if no properties are provided