Package org.fugerit.java.script.helper
Class EvalScriptWithJsonDataModel
java.lang.Object
org.fugerit.java.script.helper.EvalScriptWithJsonDataModel
- All Implemented Interfaces:
EvalScript
EvalScript decorator.
The Map dataModel will be transformed into a json styled LinkedHashMap.
-
Constructor Summary
ConstructorsConstructorDescriptionEvalScriptWithJsonDataModel(EvalScript evalScript) Add decoration to a give EvalScript -
Method Summary
Modifier and TypeMethodDescriptiondefaultDataModelConversion(Map<String, Object> dataModel) Default data model conversion Only basic types will be used : String, Number, Boolean, Array, Object as Map.It will handle a script and bind a data model.static EvalScriptnewEvalScriptWithJsonDataModel(String scriptExtension) It will decorate a EvalScriptWithDataModel instance with default data model binding name.static EvalScriptnewEvalScriptWithJsonDataModel(String scriptExtension, String dataModelBindingName) It will decorate a EvalScriptWithDataModel instance.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.fugerit.java.script.helper.EvalScript
handle, handle, handleEx
-
Constructor Details
-
EvalScriptWithJsonDataModel
Add decoration to a give EvalScript- Parameters:
evalScript- the EvalScript instance to decorate
-
-
Method Details
-
defaultDataModelConversion
Default data model conversion Only basic types will be used : String, Number, Boolean, Array, Object as Map. For instance the object :
will result in : originalDataModel : {vehicle=Vehicle{age=10, plate='AA780BB'}} jsonStyleDataModel : {vehicle={plate=AA780BB, age=10}}class Vehicle { private String plate; private int age; public Vehicle(int age, String plate) { this.age = age; this.plate = plate; } public String getPlate() { return plate; } public int getAge() { return age; } @Override public String toString() { return "Vehicle{age="+age+", plate='"+plate+"'}"; } } Map<String, Object> dataModel = new HashMap<>(); dataModel.put( "vehicle", new Vehicle( 10, "AA780BB" ) ); Map<String, Object> jsonStyleDataModel = EvalScriptWithJsonDataModel.defaultDataModelConversion( dataModel ); log.info( "originalDataModel : {}", dataModel ); log.info( "jsonStyleDataModel : {}", jsonStyleDataModel );- Parameters:
dataModel- the data model to convert- Returns:
- the data model converted to map of simple types
-
handleEx
Description copied from interface:EvalScriptIt will handle a script and bind a data model. Any class implementing EvalScript will need to provide at least this method.- Specified by:
handleExin interfaceEvalScript- Parameters:
reader- the reader over scriptdataModel- the data model to bind- Returns:
- the result of script processing
- Throws:
ScriptException- in case of script handling issues
-
newEvalScriptWithJsonDataModel
public static EvalScript newEvalScriptWithJsonDataModel(String scriptExtension, String dataModelBindingName) It will decorate a EvalScriptWithDataModel instance.- Parameters:
scriptExtension- the extension to be used for the ScriptEnginedataModelBindingName- the data model binding name- Returns:
- the new EvalScript
-
newEvalScriptWithJsonDataModel
It will decorate a EvalScriptWithDataModel instance with default data model binding name.- Parameters:
scriptExtension- the extension to be used for the ScriptEngine- Returns:
- the new EvalScript
-