Class FWSimIOAdapter

java.lang.Object
net.simplace.sim.io.FWSimIOAdapter
All Implemented Interfaces:
FWSimFieldContainer
Direct Known Subclasses:
FWSimInputAdapter, FWSimOutputAdapter, FWSimSyncAdapter

public abstract class FWSimIOAdapter extends Object implements FWSimFieldContainer
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
  • Field Details

    • iJexlRule

      protected String iJexlRule
      rule of the adapter (attribute rule), e.g. the JEXL expression for frequency COMPLEX or the name of the boolean variable for BOOLEAN
    • iSession

      protected final FWSimSession iSession
      the session
    • iResourceElement

      protected final org.jdom2.Element iResourceElement
      source Element used for creation of the Adapter
    • iName

      protected final String iName
      Name from configuration
    • iOrderNumber

      protected int iOrderNumber
      order number for the serial order of the components
    • iInterface

      protected FWSimInterface<?> iInterface
      SimInterface used to access the data. Adapter stays media independent.
    • iHeaderVariables

      protected final LinkedHashMap<String, FWSimVariable<?>> 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 iFieldcount
      number of header variables
    • iFrequence

      protected FWSimIOAdapter.FREQUENCE iFrequence
      frequency with which the data is read or written (changeable in the GUI, see setFrequenceAndRule(FREQUENCE, String))
    • iKeyMap

      protected LinkedHashMap<String,String> iKeyMap
      key variables: model variable (attribute key) → header variable
    • iSourceKey

      protected String iSourceKey
      not used
    • iArrayMode

      protected boolean iArrayMode
      true if a header variable is an array or has a count
    • iProcessTime

      protected ProcessTime 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 - the resource, transform or output element
      aSession - the session
      aOrderNumber - 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 be null
      aName - name of the adapter
      aOrderNumber - order number of the adapter
      aInterface - the interface
      aFrequence - frequency of the adapter
      aProcessTime - runtime statistics of the adapter
      aSession - the session
    • FWSimIOAdapter

      public FWSimIOAdapter(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.
      Parameters:
      aAdapter - the adapter to copy; null only for instantiation via reflection (then only the name is set, to the simple class name)
      aInterface - the new interface
  • Method Details

    • addVariable

      public void addVariable(FWSimVariable<?> aVariable)
      Adds a header variable. Use with care: it changes the columns of the adapter.
      Specified by:
      addVariable in interface FWSimFieldContainer
      Parameters:
      aVariable - the variable to add
      See Also:
    • getVariable

      public FWSimVariable<?> getVariable(String aID)
      Returns a header variable, or null if unknown.
      Specified by:
      getVariable in interface FWSimFieldContainer
      Parameters:
      aID - id of the variable
      Returns:
      the variable
      See Also:
    • removeVariable

      public void removeVariable(String aID)
      Removes a header variable. Use with care: it changes the columns of the adapter.
      Specified by:
      removeVariable in interface FWSimFieldContainer
      Parameters:
      aID - id of the variable
      See Also:
    • getName

      public String getName()
      Specified by:
      getName in interface FWSimFieldContainer
      Returns:
      the name (id) of the adapter
    • getFrequence

      public FWSimIOAdapter.FREQUENCE getFrequence()
      Specified by:
      getFrequence in interface FWSimFieldContainer
      Returns:
      the frequency of the adapter
    • getJexlRule

      public String getJexlRule()
      Returns:
      the rule of the adapter, or null
    • setFrequenceAndRule

      public void setFrequenceAndRule(FWSimIOAdapter.FREQUENCE aFrequence, String aRule)
      Changes frequency and rule (e.g. in the GUI).
      Parameters:
      aFrequence - the frequency
      aRule - 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:
      getOrderNumber in interface FWSimFieldContainer
      Returns:
      the order number of the adapter
    • setOrderNumber

      public void setOrderNumber(int orderNumber)
      Parameters:
      orderNumber - the order number of the adapter
    • getInterface

      public FWSimInterface<?> getInterface()
      Returns:
      the interface of the adapter
    • setInterface

      public void setInterface(FWSimInterface<?> aInterface)
      Parameters:
      aInterface - the interface of the adapter
    • getKeyMap

      public HashMap<String,String> getKeyMap()
      Returns:
      the key variables (model variable → header variable), the live map
    • getHeaderVariables

      public LinkedHashMap<String, FWSimVariable<?>> getHeaderVariables()
      Returns:
      the header variables in column order, the live map
    • createVariables

      public HashMap<String, FWSimVariable<?>> createVariables()
      Returns a new map with the header variables.
      Specified by:
      createVariables in interface FWSimFieldContainer
      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

      public HashMap<String, FWSimVariable<?>> getFieldMap()
      Returns the header variables (the live map).
      Specified by:
      getFieldMap in interface FWSimFieldContainer
      Returns:
      the whole field map as created in FWSimFieldContainer.createVariables()
      See Also:
    • toString

      public String toString()
      Returns the name of the adapter.
      Overrides:
      toString in class Object
      See Also:
    • getHeaderXML

      public org.jdom2.Element getHeaderXML()
      Creates the header element with the header variables (without sys, var and dyn variables, i.e. without the automatic output columns); key variables get the attribute key.
      Returns:
      the header element
    • isArrayMode

      public boolean isArrayMode()
      Returns:
      true if 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:
      getCreateFormXML in interface FWSimFieldContainer
      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:
      getEditFormXML in interface FWSimFieldContainer
      Parameters:
      aEnabled - if false, 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 (out for outputs)
      aInterface - interface of the adapter, or null for a new one
      aAdapter - the adapter, or null for a new one
      aFrequence - frequency of the adapter, or null (ONCE)
      aEnabled - if the variable fields are editable
      Returns:
      the form element
    • writeHeaderList

      protected void writeHeaderList()
      Replaces the header of the solution element by the current header variables.
    • finalize

      public void finalize() throws Exception
      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).
      Overrides:
      finalize in class Object
      Throws:
      Exception - if finalizing the interface fails
      See Also:
    • checkCondition

      public void checkCondition(Boolean aCheckResult, String aMessage)
      Passes the check to the checker of the session.
      Specified by:
      checkCondition in interface FWSimFieldContainer
      Parameters:
      aCheckResult - result of the check; false means the condition is violated
      aMessage - message describing the condition
      See Also:
    • isConditionCheck

      public boolean isConditionCheck()
      Asks the checker of the session.
      Specified by:
      isConditionCheck in interface FWSimFieldContainer
      Returns:
      true if conditions are checked with the current check level of the session
      See Also: