Package com.ontology2.haruhi.flows

Source Code of com.ontology2.haruhi.flows.SpringStep

package com.ontology2.haruhi.flows;

import java.util.*;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;

public abstract class SpringStep extends FlowStep {
    private static final Log logger = LogFactory.getLog(SpringStep.class);
    final List<String> argDefinitions;
   
    public SpringStep(List<String> argDefinitions) {
        this.argDefinitions=argDefinitions;
    }
   
    public List<String> getStepArgs(Map<String,Object> local,List<String> flowArgs) {
        SpringStepContext stepContext=new SpringStepContext(flowArgs,local);
        ExpressionParser parser = new SpelExpressionParser();
        List<String> stepArgs=new ArrayList<>();
       
        for(String that:argDefinitions) {
            Expression e=parser.parseExpression(that);
            StandardEvaluationContext c=new StandardEvaluationContext(stepContext);
            stepContext.assignVariables(c);
            String value = e.getValue(c,String.class);
            logger.trace("parsing ["+that+"] with result +["+value+"]");
            stepArgs.add(value);
        };
       
        return stepArgs;
    };
   
    public List<String> getStepArgs(String... flowArgs) {
        return getStepArgs(new HashMap<String,Object>(),Arrays.asList(flowArgs));
    }

}
TOP

Related Classes of com.ontology2.haruhi.flows.SpringStep

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.