Class FWSimResourceTransformer
java.lang.Object
net.simplace.sim.io.FWSimIOAdapter
net.simplace.sim.io.resources.FWSimInputAdapter
net.simplace.sim.io.resources.FWSimResourceTransformer
- All Implemented Interfaces:
FWSimFieldContainer
- Direct Known Subclasses:
DefaultRuleTransformer, DefaultSQLStatementTransformer
Base class of the resource transformers (
transform element). A transformer derives a new table from
the cache of another resource (attribute resource), e.g. by an SQL statement, a rule or an
aggregation, and provides it as its own FWSimResourceCache. The transformer is configured by input
variables (input children with a value or a source rule). The data is only recalculated
if the source data or the input values changed (see isUpdated(FWSimVarMap)).- Author:
- Andreas Enders
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class FWSimIOAdapter
FWSimIOAdapter.FREQUENCE -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected HashMap<String, FWSimVariable<?>> input variables of the transformer by full name (<transformer>.<id>)protected LinkedHashMap<Integer, ColumnData> columns of the result table in database orderprotected HashMap<FWSimVariable<?>, Object> values of the input variables at the last check, to detect changesprotected Stringid of the project at the last updateprotected Stringunique id of the source data at the last update, to detect changed source dataprotected final Stringname of the database connection pool (attributeinterface, default: the default pool of the solution)protected Stringname of the source resource whose cache is transformedFields inherited from class FWSimInputAdapter
iJexlScript, iShouldCacheToDBFields inherited from class FWSimIOAdapter
iArrayMode, iFieldcount, iFrequence, iHeaderVariables, iInterface, iJexlRule, iKeyMap, iName, iOrderNumber, iProcessTime, iResourceElement, iSession, iSourceKey -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructor for instantiation via reflection (seecreateSimTransformer(String)), e.g.protectedFWSimResourceTransformer(FWSimSession aSession, Integer aOrderNumber) Creates a transformer without element (e.g.protectedFWSimResourceTransformer(FWSimSession aSession, org.jdom2.Element aResourceElement, Integer aOrderNumber) Creates the transformer from its element: creates the input variables and sets their values (element text) or rules (attributesource). -
Method Summary
Modifier and TypeMethodDescriptionvoidaddVariable(FWSimVariable<?> aVariable) Adds an input variable under its full name.org.jdom2.ElementcreateFormFields(FWSimResourceTransformer aTransformer) Creates the edit form of a transformer: name and class (editable only for a new transformer), a choice of the input variables and one field group per input variable, shown when it is chosen.static FWSimResourceTransformercreateResourceTransformer(String aClassName) Factory method for documentation purposes: likecreateResourceTransformer(FWSimSession, String, Integer)without session and with order number 0.static FWSimResourceTransformercreateResourceTransformer(FWSimSession aSession, String aClassName, Integer aOrderNumber) Factory method used by the graph panel: creates a transformer of the given class via its constructor(FWSimSession, Integer), named after the simple class name.static FWSimResourceTransformercreateResourceTransformer(FWSimSession aSession, String aClassName, Integer aOrderNumber, String aName) Factory method used by the graph panel: creates a transformer of the given class via its constructor(FWSimSession, Integer)with the given name.static FWSimResourceTransformercreateResourceTransformer(FWSimSession aSession, org.jdom2.Element aTransformElement, Integer aOrderNumber) Factory method: creates the transformer of the class given in the attributeclassvia its constructor(FWSimSession, Element, Integer).static FWSimResourceTransformercreateSimTransformer(String aClassname) Creates a transformer via its constructor without parameters, e.g.voidfillVarMap(FWSimVarMap aVarMap) Deprecated.not used; the resource manager fills the variable maps from the cachesfinal org.jdom2.ElementReturns the form of this transformer, seecreateFormFields(FWSimResourceTransformer).org.jdom2.ElementgetEditFormXML(boolean aEnabled) Returns the form of this transformer, seecreateFormFields(FWSimResourceTransformer).protected FWSimResourceCachegetSourceResourceCache(FWSimVarMap aVarMap) getVariable(String aKey) Returns an input variable.booleanisUpdated(FWSimVarMap aVarMap) Checks whether the transformer has to recalculate its data.org.jdom2.ElementtoDocXML()Creates the XML for the documentation: atransformelement with the class and the input variables defined by this transformer, sorted.org.jdom2.ElementtoXML()Creates thetransformelement with id, interface, frequency, source resource, class, header and oneinputelement per input variable (with its current value).abstract voidupdateFields(FWObservable aObservable) Takes the values of the edit form into the transformer.Methods inherited from class FWSimInputAdapter
getContentType, getData, getInputVariables, getJexlScript, getOutputVariables, getVarMap, isTransformer, setFrequenceAndRule, shouldCacheToDB, toHTMLTablestringMethods inherited from class FWSimIOAdapter
addProcessTime, checkCondition, createFormFields, createVariables, finalize, getFieldMap, getFrequence, getHeaderVariables, getHeaderXML, getInterface, getJexlRule, getKeyMap, getName, getOrderNumber, isArrayMode, isConditionCheck, removeVariable, setInterface, setOrderNumber, toString, writeHeaderList
-
Field Details
-
iIntColumnMap
columns of the result table in database order -
iSourceName
name of the source resource whose cache is transformed -
iPoolName
name of the database connection pool (attributeinterface, default: the default pool of the solution) -
iFieldMap
input variables of the transformer by full name (<transformer>.<id>) -
iLastInputValuesMap
values of the input variables at the last check, to detect changes -
iLastUniqueID
unique id of the source data at the last update, to detect changed source data -
iLastProjectID
id of the project at the last update
-
-
Constructor Details
-
FWSimResourceTransformer
protected FWSimResourceTransformer(FWSimSession aSession, org.jdom2.Element aResourceElement, Integer aOrderNumber) Creates the transformer from its element: creates the input variables and sets their values (element text) or rules (attributesource).- Parameters:
aSession- the sessionaResourceElement- thetransformelementaOrderNumber- order number of the transformer
-
FWSimResourceTransformer
Creates a transformer without element (e.g. new transformer in the graph panel, documentation): an emptytransformelement with the name given tocreateResourceTransformer(FWSimSession, String, Integer, String)(defaultNewTransformer) is used.- Parameters:
aSession- the session, may benullaOrderNumber- order number of the transformer
-
FWSimResourceTransformer
protected FWSimResourceTransformer()Constructor for instantiation via reflection (seecreateSimTransformer(String)), e.g. for the documentation.
-
-
Method Details
-
createResourceTransformer
public static FWSimResourceTransformer createResourceTransformer(FWSimSession aSession, String aClassName, Integer aOrderNumber) Factory method used by the graph panel: creates a transformer of the given class via its constructor(FWSimSession, Integer), named after the simple class name. Errors are logged.- Parameters:
aSession- the sessionaClassName- full class name of the transformeraOrderNumber- order number of the transformer- Returns:
- the transformer, or
nullif it cannot be created
-
createResourceTransformer
public static FWSimResourceTransformer createResourceTransformer(FWSimSession aSession, String aClassName, Integer aOrderNumber, String aName) Factory method used by the graph panel: creates a transformer of the given class via its constructor(FWSimSession, Integer)with the given name. Errors are logged.- Parameters:
aSession- the sessionaClassName- full class name of the transformeraOrderNumber- order number of the transformeraName- name (id) of the transformer, ornullfor the simple class name- Returns:
- the transformer, or
nullif it cannot be created
-
createResourceTransformer
Factory method for documentation purposes: likecreateResourceTransformer(FWSimSession, String, Integer)without session and with order number 0.- Parameters:
aClassName- full class name of the transformer- Returns:
- the transformer, or
nullif it cannot be created
-
createResourceTransformer
public static FWSimResourceTransformer createResourceTransformer(FWSimSession aSession, org.jdom2.Element aTransformElement, Integer aOrderNumber) throws DuplicateSimFieldException Factory method: creates the transformer of the class given in the attributeclassvia its constructor(FWSimSession, Element, Integer). Instantiation errors are logged.- Parameters:
aSession- the sessionaTransformElement- thetransformelementaOrderNumber- order number of the transformer- Returns:
- the transformer, or
nullif it cannot be created - Throws:
DuplicateSimFieldException- if a resource with the same id already exists
-
getSourceResourceCache
- Parameters:
aVarMap- variable map of the simulation (provides the session)- Returns:
- the cache of the source resource, or
nullif it has no data
-
isUpdated
Checks whether the transformer has to recalculate its data. This is the case if the input values changed, the source data changed (other unique id), or the source is a transformer that was updated. Without source cache, a new project or changed inputs cause an update. The remembered unique id and project id are updated.Note: the last condition also updates when the project id is equal to the last one. This method is called once per project by the resource manager (new project id, so the condition has no effect there) and a second time by a transformer that uses this transformer as source; in that second call the condition reports an update, so the dependent transformer is always recalculated (safe, but not optimal).
- Parameters:
aVarMap- variable map of the first simulation of the project- Returns:
trueif the data has to be recalculated
-
fillVarMap
Deprecated.not used; the resource manager fills the variable maps from the cachesCopies the current data line of the cache of this transformer into the variable map.- Parameters:
aVarMap- variable map of the simulation
-
toXML
public org.jdom2.Element toXML()Creates thetransformelement with id, interface, frequency, source resource, class, header and oneinputelement per input variable (with its current value).- Returns:
- an XML element with all settings of this container
- See Also:
-
getCreateFormXML
public final org.jdom2.Element getCreateFormXML()Returns the form of this transformer, seecreateFormFields(FWSimResourceTransformer).- Specified by:
getCreateFormXMLin interfaceFWSimFieldContainer- Overrides:
getCreateFormXMLin classFWSimIOAdapter- Returns:
- the XML form definition used by the GUI to create this container
- See Also:
-
getEditFormXML
public org.jdom2.Element getEditFormXML(boolean aEnabled) Returns the form of this transformer, seecreateFormFields(FWSimResourceTransformer).aEnabledis not used.- Specified by:
getEditFormXMLin interfaceFWSimFieldContainer- Overrides:
getEditFormXMLin classFWSimIOAdapter- Parameters:
aEnabled- iffalse, the form fields are read-only- Returns:
- the XML form definition used by the GUI to edit the settings of this container
- See Also:
-
createFormFields
Creates the edit form of a transformer: name and class (editable only for a new transformer), a choice of the input variables and one field group per input variable, shown when it is chosen.- Parameters:
aTransformer- the transformer, ornullfor a new one (then only name and class are shown)- Returns:
- the form element
-
addVariable
Adds an input variable under its full name.- Specified by:
addVariablein interfaceFWSimFieldContainer- Overrides:
addVariablein classFWSimIOAdapter- Parameters:
aVariable- the variable to add- See Also:
-
getVariable
Returns an input variable.- Specified by:
getVariablein interfaceFWSimFieldContainer- Overrides:
getVariablein classFWSimIOAdapter- Parameters:
aKey- id of the input without the transformer name- Returns:
- the input variable, or
nullif unknown - See Also:
-
updateFields
Takes the values of the edit form into the transformer.- Parameters:
aObservable- the form data
-
createSimTransformer
Creates a transformer via its constructor without parameters, e.g. for the documentation of all transformers. Errors are logged.- Parameters:
aClassname- full class name of the transformer- Returns:
- the transformer, or
nullfor abstract classes or if it cannot be created
-
toDocXML
public org.jdom2.Element toDocXML()Creates the XML for the documentation: atransformelement with the class and the input variables defined by this transformer, sorted.- Returns:
- the documentation element
-