Search in sources :

Example 11 with ScriptClassFunction

use of org.eclipse.vorto.mapping.engine.functions.ScriptClassFunction in project vorto by eclipse.

the class MappingSpecification method getScriptFunctions.

@Override
public FunctionLibrary getScriptFunctions(IScriptEvalProvider factory) {
    FunctionLibrary library = new FunctionLibrary();
    this.infoModel.getFunctionblocks().stream().forEach(property -> {
        IMappedElement mappedElement = (IMappedElement) property.getType();
        if (mappedElement.getStereotype(STEREOTYPE_FUNCTIONS).isPresent()) {
            Stereotype functionsStereoType = mappedElement.getStereotype(STEREOTYPE_FUNCTIONS).get();
            IScriptEvaluator evaluator = factory.createEvaluator(property.getName().toLowerCase());
            functionsStereoType.getAttributes().keySet().stream().filter(functionName -> !functionName.equalsIgnoreCase(STEREOTYPE_NAMESPACE)).forEach(functionName -> evaluator.addScriptFunction(new ScriptClassFunction(functionName, functionsStereoType.getAttributes().get(functionName))));
            library.addFunctions(evaluator.getFunctions());
        }
    });
    return library;
}
Also used : Stereotype(org.eclipse.vorto.model.Stereotype) IScriptEvalProvider(org.eclipse.vorto.mapping.engine.functions.IScriptEvalProvider) FunctionLibrary(org.apache.commons.jxpath.FunctionLibrary) IScriptEvaluator(org.eclipse.vorto.mapping.engine.functions.IScriptEvaluator) Infomodel(org.eclipse.vorto.model.Infomodel) ScriptClassFunction(org.eclipse.vorto.mapping.engine.functions.ScriptClassFunction) IMappedElement(org.eclipse.vorto.model.IMappedElement) FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) IScriptEvaluator(org.eclipse.vorto.mapping.engine.functions.IScriptEvaluator) IMappedElement(org.eclipse.vorto.model.IMappedElement) FunctionLibrary(org.apache.commons.jxpath.FunctionLibrary) Stereotype(org.eclipse.vorto.model.Stereotype) ScriptClassFunction(org.eclipse.vorto.mapping.engine.functions.ScriptClassFunction)

Example 12 with ScriptClassFunction

use of org.eclipse.vorto.mapping.engine.functions.ScriptClassFunction in project vorto by eclipse.

the class SpecWithMultipleParams method getScriptFunctions.

@Override
public FunctionLibrary getScriptFunctions(IScriptEvalProvider evalProvider) {
    FunctionLibrary library = new FunctionLibrary();
    IScriptEvaluator evaluator = evalProvider.createEvaluator("button");
    evaluator.addScriptFunction(new ScriptClassFunction("convertArray", "function convertArray(arrayValue,header) {  return header+String.fromCharCode(arrayValue[0])}"));
    library.addFunctions(evaluator.getFunctions());
    return library;
}
Also used : IScriptEvaluator(org.eclipse.vorto.mapping.engine.functions.IScriptEvaluator) FunctionLibrary(org.apache.commons.jxpath.FunctionLibrary) ScriptClassFunction(org.eclipse.vorto.mapping.engine.functions.ScriptClassFunction)

Aggregations

FunctionLibrary (org.apache.commons.jxpath.FunctionLibrary)12 IScriptEvaluator (org.eclipse.vorto.mapping.engine.functions.IScriptEvaluator)12 ScriptClassFunction (org.eclipse.vorto.mapping.engine.functions.ScriptClassFunction)12 IScriptEvalProvider (org.eclipse.vorto.mapping.engine.functions.IScriptEvalProvider)1 FunctionblockModel (org.eclipse.vorto.model.FunctionblockModel)1 IMappedElement (org.eclipse.vorto.model.IMappedElement)1 Infomodel (org.eclipse.vorto.model.Infomodel)1 Stereotype (org.eclipse.vorto.model.Stereotype)1