Class CSVResourceAdapter
java.lang.Object
net.simplace.sim.io.FWSimIOAdapter
net.simplace.sim.io.resources.FWSimInputAdapter
net.simplace.sim.io.resources.FWSimResourceAdapter<List<String>>
net.simplace.sim.io.resources.adapter.CSVResourceAdapter
- All Implemented Interfaces:
FWSimFieldContainer
Resource adapter for CSV files (
CSVInterface). The file is registered in the file pool of the interface; its
lines (optionally only the lines to read, after skipping header lines) are read into a FWSimResourceCache.
A file is only read again if its unique id changed.- Author:
- Andreas Enders
-
Nested Class Summary
Nested classes/interfaces inherited from class FWSimIOAdapter
FWSimIOAdapter.FREQUENCE -
Field Summary
Fields inherited from class FWSimResourceAdapter
iLinesToReadFields 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
ConstructorsConstructorDescriptionCSVResourceAdapter(String aFileName, String aContent, String aComponentName, String aDivider, int aOrderNumber, FWSimSession aFwSimSession, FWSimIOAdapter.FREQUENCE aFrequence, Map<String, String> aKeyMap, Integer[] aLinesToRead, Integer aSkipHeaderLines) Creates the adapter from the graph panel: creates the CSV interface and derives the header variables from the file or content (seereadHeaderList(String, String, String, String, Map, FWSimSession)).CSVResourceAdapter(FWSimResourceAdapter<?> aAdapter, CSVInterface aInterface) Copy constructor used when the interface is replaced; the key variables are taken over.CSVResourceAdapter(org.jdom2.Element aResourceElement, FWSimSession aSession, int aOrderNumber) Creates the adapter from aresourceelement of the solution. -
Method Summary
Modifier and TypeMethodDescriptiongetData(FWSimVarMap aVarMap) Registers the file of the current simulation in the file pool and reads it, if it was updated.getData(FWSimVarMap aVarMap, FileData aFileData) Reads a CSV file into a new cache, unless it is the same file (unique id) as last time.readHeaderList(String aFileName, String aContent, String aComponentName, String aDivider, Map<String, String> aKeyMap, FWSimSession aSession) Creates the header variables from the first line of the file or content (column names); the data type of each column is guessed from the value in the second line (a missing line or value counts as empty text, i.e.Methods inherited from class FWSimResourceAdapter
createAdapterFromObservable, createResourceAdapter, getLinesToRead, setLinesToRead, toXML, updateAdapterMethods inherited from class FWSimInputAdapter
getContentType, getInputVariables, getJexlScript, getOutputVariables, getVarMap, isTransformer, setFrequenceAndRule, shouldCacheToDB, toHTMLTablestringMethods inherited from class FWSimIOAdapter
addProcessTime, addVariable, checkCondition, createFormFields, createVariables, finalize, getCreateFormXML, getEditFormXML, getFieldMap, getFrequence, getHeaderVariables, getHeaderXML, getInterface, getJexlRule, getKeyMap, getName, getOrderNumber, getVariable, isArrayMode, isConditionCheck, removeVariable, setInterface, setOrderNumber, toString, writeHeaderList
-
Constructor Details
-
CSVResourceAdapter
public CSVResourceAdapter(org.jdom2.Element aResourceElement, FWSimSession aSession, int aOrderNumber) Creates the adapter from aresourceelement of the solution.- Parameters:
aResourceElement- theresourceelementaSession- the sessionaOrderNumber- order number of the adapter
-
CSVResourceAdapter
public CSVResourceAdapter(String aFileName, String aContent, String aComponentName, String aDivider, int aOrderNumber, FWSimSession aFwSimSession, FWSimIOAdapter.FREQUENCE aFrequence, Map<String, String> aKeyMap, Integer[] aLinesToRead, Integer aSkipHeaderLines) throws IOException, SimFieldMissingExceptionCreates the adapter from the graph panel: creates the CSV interface and derives the header variables from the file or content (seereadHeaderList(String, String, String, String, Map, FWSimSession)).- Parameters:
aFileName- CSV fileaContent- CSV content instead of a file, may benullaComponentName- name of the adapter and the interfaceaDivider- column divideraOrderNumber- order number of the adapteraFwSimSession- the sessionaFrequence- frequency the data is read withaKeyMap- key variables; if empty, the user is asked to select themaLinesToRead- lines to read, ornullfor allaSkipHeaderLines- number of header lines to skip- Throws:
IOException- if the file cannot be readSimFieldMissingException- if no key variables are given or selected
-
CSVResourceAdapter
Copy constructor used when the interface is replaced; the key variables are taken over.- Parameters:
aAdapter- the adapter to copyaInterface- the new interface
-
-
Method Details
-
getData
Registers the file of the current simulation in the file pool and reads it, if it was updated.- Specified by:
getDatain classFWSimInputAdapter- Parameters:
aVarMap- variable map of the simulation (e.g. for the key values of the rule)- Returns:
- the new cache, or
nullif the file is unchanged (the previous cache stays valid) - Throws:
MissingSimResourceException- if the data cannot be read- See Also:
-
getData
public FWSimResourceCache getData(FWSimVarMap aVarMap, FileData aFileData) throws MissingSimResourceException Reads a CSV file into a new cache, unless it is the same file (unique id) as last time.- Parameters:
aVarMap- variable map of the simulationaFileData- the file- Returns:
- the new cache, or
nullif the file was already read - Throws:
MissingSimResourceException- if the file is not available, has fewer than two columns (wrong divider or encoding) or cannot be read
-
readHeaderList
public Map<String,String> readHeaderList(String aFileName, String aContent, String aComponentName, String aDivider, Map<String, String> aKeyMap, FWSimSession aSession) throws IOExceptionCreates the header variables from the first line of the file or content (column names); the data type of each column is guessed from the value in the second line (a missing line or value counts as empty text, i.e.FWSimVariable.DATA_TYPE.CHAR). If no key variables are given, the user is asked to select them.- Parameters:
aFileName- CSV file, only read ifaContentisnullaContent- CSV content instead of a file, may benullaComponentName- name of the adapter (not used)aDivider- column divider, default TABaKeyMap- key variables, may benullor emptyaSession- the session (provides the model variables for the key selection)- Returns:
- the key variables (model variable → column), or
nullif none were given or selected - Throws:
IOException- if the file cannot be read or the file/content is empty
-