Class FWSimResourceManager
java.lang.Object
net.simplace.sim.io.resources.FWSimResourceManager
Manages the resources of a session (one instance per session). It creates the resource adapters, transformers and
aliases from the
resources part of the solution, reads their data into FWSimResourceCaches
when a project starts (updateResources(FWSimVarMap)), and copies the current data lines into the variable
maps of the simulations in each step (updateVarMap(FWSimVarMap, boolean)). The media specific access
(database, CSV, XML, ...) is done by the adapters via their interfaces.- Author:
- Andreas Enders
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddAlias(FWSimSession aSession, org.jdom2.Element aAlias) Creates an alias from its element and adds it.addResource(FWSimSession aSession, org.jdom2.Element aResource) Creates a resource adapter from its element and adds it.voidaddResourceCreator(FWSimInputAdapter aAdapter) Adds an already created resource adapter, transformer or alias; an existing one with the same name is replaced.addTransform(FWSimSession aSession, org.jdom2.Element aTransform) Creates a transformer from its element and adds it.HashMap<String, FWSimVariable<?>> Creates the variables of all adapters (for transformers their header variables).getResourceCache(String aSourceName) getResourceCreator(String aName) referenceKeys(LinkedHashMap<String, FWSimVariable<?>> aHeaderVariables, FWSimSolution aSolution) Lets the user select the key variables of a new resource in the GUI: in a loop a model variable (source) and a header variable (target) are chosen as key pair until the user cancels or fewer than two fields are left.voidreset()Finalizes all resource adapters, transformers and aliases (e.g.booleanupdateInterface(FWSimInterface<?> aInterface, FWSimVarMap aVarMap) Replaces every resource adapter that uses an interface with the same name by a copy using the new interface (seeFWSimResourceAdapter.updateAdapter(FWSimResourceAdapter, FWSimInterface)).booleanupdateResources(FWSimVarMap aVarMap) Reads the data of all resources and transformers into their caches; called when a project starts.voidupdateVarMap(FWSimVarMap aVarMap, boolean aForceUpdate) Copies the current data lines of all caches (and aliases) into the variable map of a simulation, for each cache only if its frequency requires an update in this step (seeFWSimResourceCache.shouldUpdate(FWSimVarMap)).
-
Constructor Details
-
FWSimResourceManager
public FWSimResourceManager()
-
-
Method Details
-
addResource
public String addResource(FWSimSession aSession, org.jdom2.Element aResource) throws MissingSimResourceException, DuplicateSimFieldException Creates a resource adapter from its element and adds it.- Parameters:
aSession- the sessionaResource- theresourceelement- Returns:
- the name of the resource
- Throws:
MissingSimResourceException- if the interface is missing or not supportedDuplicateSimFieldException- if a resource with the same id already exists
-
addTransform
public String addTransform(FWSimSession aSession, org.jdom2.Element aTransform) throws MissingSimResourceException, DuplicateSimFieldException Creates a transformer from its element and adds it.- Parameters:
aSession- the sessionaTransform- thetransformelement- Returns:
- the name of the transformer
- Throws:
MissingSimResourceException- if the transformer cannot be createdDuplicateSimFieldException- if a resource with the same id already exists
-
addAlias
public String addAlias(FWSimSession aSession, org.jdom2.Element aAlias) throws MissingSimResourceException, DuplicateSimFieldException Creates an alias from its element and adds it.- Parameters:
aSession- the sessionaAlias- thealiaselement- Returns:
- the name of the alias
- Throws:
MissingSimResourceException- if the original resource is not givenDuplicateSimFieldException- if a resource with the same id already exists
-
updateResources
Reads the data of all resources and transformers into their caches; called when a project starts. Transformers are only recalculated if their source data or inputs changed; the resourcePROJECT_DATAis skipped. If a resource delivers no data, its previous cache is kept. In check level ONLY the checker checks the resources instead. Finally the aliases are connected to the caches of their original resources.- Parameters:
aVarMap- variable map of the first simulation of the project- Returns:
- always
true - Throws:
MissingSimResourceException- if a resource or the original resource of an alias is missing
-
getResourceCreator
- Parameters:
aName- name of the resource, transformer or alias- Returns:
- the
FWSimResourceAdapter,FWSimResourceTransformerorFWSimResourceAlias, ornullif unknown
-
addResourceCreator
Adds an already created resource adapter, transformer or alias; an existing one with the same name is replaced.- Parameters:
aAdapter- the adapter to add
-
updateInterface
Replaces every resource adapter that uses an interface with the same name by a copy using the new interface (seeFWSimResourceAdapter.updateAdapter(FWSimResourceAdapter, FWSimInterface)). Transformers and aliases are not replaced.- Parameters:
aInterface- the new interfaceaVarMap- not used- Returns:
trueif at least one adapter was replaced
-
createVariables
Creates the variables of all adapters (for transformers their header variables).- Returns:
- all resource variables by name
-
getResourceCache
- Parameters:
aSourceName- name of the resource or transformer- Returns:
- its cache, or
nullif no data has been read yet
-
updateVarMap
Copies the current data lines of all caches (and aliases) into the variable map of a simulation, for each cache only if its frequency requires an update in this step (seeFWSimResourceCache.shouldUpdate(FWSimVarMap)). The cachePROJECT_DATAis skipped; it is only set at the start of a simulation. Aliases whose original resource has no cache are skipped (the missing resource was already reported byupdateResources(FWSimVarMap)).- Parameters:
aVarMap- variable map of the simulationaForceUpdate-trueto update all caches regardless of their frequency (e.g. at the start)
-
getResourceAdapters
- Returns:
- all resource adapters, transformers and aliases (the live collection)
-
referenceKeys
public static Map<String,String> referenceKeys(LinkedHashMap<String, FWSimVariable<?>> aHeaderVariables, FWSimSolution aSolution) Lets the user select the key variables of a new resource in the GUI: in a loop a model variable (source) and a header variable (target) are chosen as key pair until the user cancels or fewer than two fields are left.- Parameters:
aHeaderVariables- header variables of the resourceaSolution- the solution providing the model variables- Returns:
- the selected key pairs (model variable → header variable); empty if the solution is
null
-
reset
-