Class FWSimIOAdapter
java.lang.Object
net.simplace.sim.io.FWSimIOAdapter
- All Implemented Interfaces:
FWSimFieldContainer
- Direct Known Subclasses:
FWSimInputAdapter, FWSimOutputAdapter, FWSimSyncAdapter
Base class of the resource adapters, transformers and output adapters. As
FWSimFieldContainer it provides
the header variables (the columns of the data) to the model and the GUI. The adapter reads its configuration from
the solution element: id, interface, frequency, rule and the header with one element per variable
(attribute key marks the key variables). The media specific access is done by the
FWSimInterface.
createFormFields(CONTENT_TYPE, FWSimInterface, FWSimIOAdapter, FREQUENCE, boolean) creates the GUI form to
create or edit an adapter.
- Author:
- Andreas Enders
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumFrequency with which the data is read (resources) or written (outputs). -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleantrueif a header variable is an array or has acountprotected intnumber of header variablesprotected FWSimIOAdapter.FREQUENCEfrequency with which the data is read or written (changeable in the GUI, seesetFrequenceAndRule(FREQUENCE, String))protected final LinkedHashMap<String, FWSimVariable<?>> header variables (columns) by full name, in column order.protected FWSimInterface<?> SimInterface used to access the data.protected Stringrule of the adapter (attributerule), e.g.protected LinkedHashMap<String, String> key variables: model variable (attributekey) → header variableprotected final StringName from configurationprotected intorder number for the serial order of the componentsprotected ProcessTimeruntime statistics of the adapterprotected final org.jdom2.Elementsource Element used for creation of the Adapterprotected final FWSimSessionthe sessionprotected Stringnot used -
Constructor Summary
ConstructorsModifierConstructorDescriptionFWSimIOAdapter(FWSimIOAdapter aAdapter, FWSimInterface<?> aInterface) Copy constructor used when the interface of an adapter is replaced; name, rule, header, frequency, order number, session and runtime statistics are taken over.FWSimIOAdapter(org.jdom2.Element aResourceElement, String aName, int aOrderNumber, FWSimInterface<?> aInterface, FWSimIOAdapter.FREQUENCE aFrequence, ProcessTime aProcessTime, FWSimSession aSession) Creates the adapter from explicit values (graph panel, calibration); the header is not read from the element.protectedFWSimIOAdapter(org.jdom2.Element aResourceElement, FWSimSession aSession, int aOrderNumber) Creates the adapter from its solution element: reads id, interface, frequency, rule and header. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddProcessTime(long aProcessTime) Adds a measured processing time to the runtime statistics of the adapter.voidaddVariable(FWSimVariable<?> aVariable) Adds a header variable.voidcheckCondition(Boolean aCheckResult, String aMessage) Passes the check to the checker of the session.static org.jdom2.ElementcreateFormFields(FWSimVariable.CONTENT_TYPE aContentType, FWSimInterface<?> aInterface, FWSimIOAdapter aAdapter, FWSimIOAdapter.FREQUENCE aFrequence, boolean aEnabled) Creates the GUI form of an adapter: name, data type (DATABASE/CSV/MEMORY for outputs, DATABASE/CSV/XML for resources), frequency, rule, pool size, the database settings, file name and divider (shown depending on the data type) and, for an existing adapter, a field group per header variable.HashMap<String, FWSimVariable<?>> Returns a new map with the header variables.voidfinalize()Finalizes the interface of the adapter (also if it is shared with other adapters - a shared interface is then finalized once per adapter; this only closes its files/pool again, which is harmless, and happens when the session ends, after all adapters have finished).org.jdom2.ElementReturns the form for creating a new adapter of this content type.org.jdom2.ElementgetEditFormXML(boolean aEnabled) Returns the form for editing this adapter.HashMap<String, FWSimVariable<?>> Returns the header variables (the live map).org.jdom2.ElementCreates theheaderelement with the header variables (withoutsys,varanddynvariables, i.e.getName()intgetVariable(String aID) Returns a header variable, ornullif unknown.booleanbooleanAsks the checker of the session.voidremoveVariable(String aID) Removes a header variable.voidsetFrequenceAndRule(FWSimIOAdapter.FREQUENCE aFrequence, String aRule) Changes frequency and rule (e.g.voidsetInterface(FWSimInterface<?> aInterface) voidsetOrderNumber(int orderNumber) toString()Returns the name of the adapter.protected voidReplaces theheaderof the solution element by the current header variables.Methods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface FWSimFieldContainer
getContentType, getInputVariables, getOutputVariables, getVarMap, toXML
-
Field Details
-
iJexlRule
rule of the adapter (attributerule), e.g. the JEXL expression for frequency COMPLEX or the name of the boolean variable for BOOLEAN -
iSession
the session -
iResourceElement
protected final org.jdom2.Element iResourceElementsource Element used for creation of the Adapter -
iName
Name from configuration -
iOrderNumber
protected int iOrderNumberorder number for the serial order of the components -
iInterface
SimInterface used to access the data. Adapter stays media independent. -
iHeaderVariables
header variables (columns) by full name, in column order. Defined in the solution e.g. as<header> <res id="CURRENTDATE" datatype="DATE" key="CURRENT.DATE"/> <res id="Rain" unit="mm" datatype="DOUBLE"/> ... </header>. Output adapters additionally get the columns project id, current date and simulation id at the beginning.- See Also:
-
iFieldcount
protected int iFieldcountnumber of header variables -
iFrequence
frequency with which the data is read or written (changeable in the GUI, seesetFrequenceAndRule(FREQUENCE, String)) -
iKeyMap
key variables: model variable (attributekey) → header variable -
iSourceKey
not used -
iArrayMode
protected boolean iArrayModetrueif a header variable is an array or has acount -
iProcessTime
runtime statistics of the adapter
-
-
Constructor Details
-
FWSimIOAdapter
protected FWSimIOAdapter(org.jdom2.Element aResourceElement, FWSimSession aSession, int aOrderNumber) Creates the adapter from its solution element: reads id, interface, frequency, rule and header.- Parameters:
aResourceElement- theresource,transformoroutputelementaSession- the sessionaOrderNumber- order number of the adapter- Throws:
RuntimeException- if the frequency is COMPLEX or BOOLEAN and no rule is given
-
FWSimIOAdapter
public FWSimIOAdapter(org.jdom2.Element aResourceElement, String aName, int aOrderNumber, FWSimInterface<?> aInterface, FWSimIOAdapter.FREQUENCE aFrequence, ProcessTime aProcessTime, FWSimSession aSession) Creates the adapter from explicit values (graph panel, calibration); the header is not read from the element.- Parameters:
aResourceElement- the solution element, may benullaName- name of the adapteraOrderNumber- order number of the adapteraInterface- the interfaceaFrequence- frequency of the adapteraProcessTime- runtime statistics of the adapteraSession- the session
-
FWSimIOAdapter
Copy constructor used when the interface of an adapter is replaced; name, rule, header, frequency, order number, session and runtime statistics are taken over.- Parameters:
aAdapter- the adapter to copy;nullonly for instantiation via reflection (then only the name is set, to the simple class name)aInterface- the new interface
-
-
Method Details
-
addVariable
Adds a header variable. Use with care: it changes the columns of the adapter.- Specified by:
addVariablein interfaceFWSimFieldContainer- Parameters:
aVariable- the variable to add- See Also:
-
getVariable
Returns a header variable, ornullif unknown.- Specified by:
getVariablein interfaceFWSimFieldContainer- Parameters:
aID- id of the variable- Returns:
- the variable
- See Also:
-
removeVariable
Removes a header variable. Use with care: it changes the columns of the adapter.- Specified by:
removeVariablein interfaceFWSimFieldContainer- Parameters:
aID- id of the variable- See Also:
-
getName
- Specified by:
getNamein interfaceFWSimFieldContainer- Returns:
- the name (id) of the adapter
-
getFrequence
- Specified by:
getFrequencein interfaceFWSimFieldContainer- Returns:
- the frequency of the adapter
-
getJexlRule
- Returns:
- the rule of the adapter, or
null
-
setFrequenceAndRule
Changes frequency and rule (e.g. in the GUI).- Parameters:
aFrequence- the frequencyaRule- the rule, empty for none (required for COMPLEX and BOOLEAN)- Throws:
IllegalArgumentException- if the frequency is COMPLEX or BOOLEAN and no rule is given
-
getOrderNumber
public int getOrderNumber()- Specified by:
getOrderNumberin interfaceFWSimFieldContainer- Returns:
- the order number of the adapter
-
setOrderNumber
public void setOrderNumber(int orderNumber) - Parameters:
orderNumber- the order number of the adapter
-
getInterface
- Returns:
- the interface of the adapter
-
setInterface
- Parameters:
aInterface- the interface of the adapter
-
getKeyMap
-
getHeaderVariables
- Returns:
- the header variables in column order, the live map
-
createVariables
Returns a new map with the header variables.- Specified by:
createVariablesin interfaceFWSimFieldContainer- Returns:
- the variables, keyed by name
- See Also:
-
addProcessTime
public void addProcessTime(long aProcessTime) Adds a measured processing time to the runtime statistics of the adapter.- Parameters:
aProcessTime- processing time in milliseconds
-
getFieldMap
Returns the header variables (the live map).- Specified by:
getFieldMapin interfaceFWSimFieldContainer- Returns:
- the whole field map as created in
FWSimFieldContainer.createVariables() - See Also:
-
toString
-
getHeaderXML
public org.jdom2.Element getHeaderXML()Creates theheaderelement with the header variables (withoutsys,varanddynvariables, i.e. without the automatic output columns); key variables get the attributekey.- Returns:
- the
headerelement
-
isArrayMode
public boolean isArrayMode()- Returns:
trueif the adapter has array variables (array elements are handled as separate values)
-
getCreateFormXML
public org.jdom2.Element getCreateFormXML()Returns the form for creating a new adapter of this content type.- Specified by:
getCreateFormXMLin interfaceFWSimFieldContainer- 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 for editing this adapter.- Specified by:
getEditFormXMLin interfaceFWSimFieldContainer- 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
public static org.jdom2.Element createFormFields(FWSimVariable.CONTENT_TYPE aContentType, FWSimInterface<?> aInterface, FWSimIOAdapter aAdapter, FWSimIOAdapter.FREQUENCE aFrequence, boolean aEnabled) Creates the GUI form of an adapter: name, data type (DATABASE/CSV/MEMORY for outputs, DATABASE/CSV/XML for resources), frequency, rule, pool size, the database settings, file name and divider (shown depending on the data type) and, for an existing adapter, a field group per header variable.- Parameters:
aContentType- content type of the adapter (outfor outputs)aInterface- interface of the adapter, ornullfor a new oneaAdapter- the adapter, ornullfor a new oneaFrequence- frequency of the adapter, ornull(ONCE)aEnabled- if the variable fields are editable- Returns:
- the form element
-
writeHeaderList
protected void writeHeaderList()Replaces theheaderof the solution element by the current header variables. -
finalize
Finalizes the interface of the adapter (also if it is shared with other adapters - a shared interface is then finalized once per adapter; this only closes its files/pool again, which is harmless, and happens when the session ends, after all adapters have finished). -
checkCondition
Passes the check to the checker of the session.- Specified by:
checkConditionin interfaceFWSimFieldContainer- Parameters:
aCheckResult- result of the check;falsemeans the condition is violatedaMessage- message describing the condition- See Also:
-
isConditionCheck
public boolean isConditionCheck()Asks the checker of the session.- Specified by:
isConditionCheckin interfaceFWSimFieldContainer- Returns:
trueif conditions are checked with the current check level of the session- See Also:
-