Class JSONInterface
java.lang.Object
net.simplace.sim.io.interfaces.FWSimInterface<JSONDataContainer>
net.simplace.sim.io.interfaces.JSONInterface
Interface for JSON data, used for resources. The data is fetched with HTTP GET from a URL (e.g. a web service) or
taken from a string, parsed and optionally narrowed down by a path. Settings:
url (may contain
${...} tokens), path (names separated by /) and content (JSON
string, or the name of a variable holding it).- Author:
- Andreas Enders
-
Nested Class Summary
Nested classes/interfaces inherited from class FWSimInterface
FWSimInterface.INTERFACE_TYPE -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StringJSON string (may contain tokens), or the name of a variable holding itprotected Stringpath to the data within the JSON document, names separated by/protected StringURL of the JSON data, may contain tokensFields inherited from class FWSimInterface
iColumnMap, iColumnNamesInt, iIntColumnNames -
Constructor Summary
ConstructorsModifierConstructorDescriptionJSONInterface(String aName, String aURL, String aPath, String aVarName) Creates the interface without element.protectedJSONInterface(String aName, FWSimInterface.INTERFACE_TYPE aInterfaceType, int aPoolSize) Creates the interface without element; to be called by subclasses.protectedJSONInterface(String aName, org.jdom2.Element aInterfaceElement) Creates the interface from its element (childrenurl,path,content). -
Method Summary
Modifier and TypeMethodDescriptionvoidfinalize()Nothing to release.getInterface(FWSimVarMap aVarMap, FWSimVariable.CONTENT_TYPE aContentType) Fetches and parses the JSON data: from the URL (tokens replaced) or from the content.getURL()read(FWSimSession aFwSimSession, String aProjectID, Object aCache, LinkedHashMap<String, String> aKeyMap, FWSimInputAdapter aResourceAdapter, String aUniqueID, FWSimInterface.INTERFACE_TYPE aInterfaceType) Converts JSON data (aJSONDataContainer) into a resource cache: each object of an array (or the single object) becomes a data line, seereadDataFromJSONObject(String, LinkedHashMap, FWSimResourceCache, PreparedStatement, boolean, Object).voidorg.jdom2.ElementtoXML()Adds URL, path and content (if set) to the element of the base class.Methods inherited from class FWSimInterface
checkHeaderForColMode, createInterface, createInterface, createStatisticInterface, getInterfaceElement, getInterfaceType, getName, getPoolSize, readColArray, readColArray, toString, transformArrays, writeToDatabase
-
Field Details
-
iURL
URL of the JSON data, may contain tokens -
iPath
path to the data within the JSON document, names separated by/ -
iContent
JSON string (may contain tokens), or the name of a variable holding it
-
-
Constructor Details
-
JSONInterface
Creates the interface without element; to be called by subclasses.- Parameters:
aName- name of the interfaceaInterfaceType- type of the interfaceaPoolSize- pool size (not used)
-
JSONInterface
Creates the interface from its element (childrenurl,path,content).- Parameters:
aName- name of the interfaceaInterfaceElement- theinterfaceelement
-
JSONInterface
Creates the interface without element.- Parameters:
aName- name of the interfaceaURL- URL of the JSON data, may benullaPath- path to the data within the JSON document, may benullaVarName- JSON string or name of a variable holding it (used if no URL is given)
-
-
Method Details
-
getInterface
Fetches and parses the JSON data: from the URL (tokens replaced) or from the content. If the content after token replacement does not start with{or[, it is taken as the name of a variable holding the JSON string. A JSON object is narrowed down by the path.- Specified by:
getInterfacein classFWSimInterface<JSONDataContainer>- Parameters:
aVarMap- variable map used for replacing tokens (e.g. in file names), may benullaContentType-resfor reading,outfor writing- Returns:
- the data, or
nullif it cannot be fetched or parsed (the error is logged) or the path leads nowhere - See Also:
-
getURL
- Returns:
- the URL of the JSON data (with tokens)
-
setURL
- Parameters:
aURL- the URL of the JSON data
-
toXML
public org.jdom2.Element toXML()Adds URL, path and content (if set) to the element of the base class.- Overrides:
toXMLin classFWSimInterface<JSONDataContainer>- Returns:
- the
interfaceelement
-
finalize
Nothing to release.- Specified by:
finalizein classFWSimInterface<JSONDataContainer>- Throws:
Exception- if releasing fails- See Also:
-
read
public FWSimResourceCache read(FWSimSession aFwSimSession, String aProjectID, Object aCache, LinkedHashMap<String, String> aKeyMap, FWSimInputAdapter aResourceAdapter, String aUniqueID, FWSimInterface.INTERFACE_TYPE aInterfaceType) throws MissingSimResourceExceptionConverts JSON data (aJSONDataContainer) into a resource cache: each object of an array (or the single object) becomes a data line, seereadDataFromJSONObject(String, LinkedHashMap, FWSimResourceCache, PreparedStatement, boolean, Object). Errors are logged and a partly filled cache is returned.- Specified by:
readin classFWSimInterface<JSONDataContainer>- Parameters:
aFwSimSession- the sessionaProjectID- id of the current projectaCache- the data read, in the format of the interface (e.g.String[][], result set, XML element)aKeyMap- key variables of the resourceaResourceAdapter- the adapter the cache belongs toaUniqueID- unique id of the source dataaInterfaceType- type of the source interface- Returns:
- the new resource cache
- Throws:
MissingSimResourceException- if the data cannot be converted- See Also:
-