當前位置: 首頁>>代碼示例>>Java>>正文


Java JexlEngine類代碼示例

本文整理匯總了Java中org.apache.commons.jexl2.JexlEngine的典型用法代碼示例。如果您正苦於以下問題:Java JexlEngine類的具體用法?Java JexlEngine怎麽用?Java JexlEngine使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JexlEngine類屬於org.apache.commons.jexl2包,在下文中一共展示了JexlEngine類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: ExpressionConfigWrapper

import org.apache.commons.jexl2.JexlEngine; //導入依賴的package包/類
public ExpressionConfigWrapper(Expression expression) throws ThresholdExpressionException {
	super(expression);
	m_expression = expression;

	// Fetch an instance of the JEXL script engine
	JexlEngine expressionParser = new JexlEngine();

	BindingsSniffer sniffer = new BindingsSniffer();
	sniffer.put("math", new MathBinding());
	sniffer.put("datasources", new HashMap<String,Double>()); // To workaround NMS-5019

	// Test parsing of the expression and collect the variable names by using
	// a Bindings instance that sniffs all of the variable names
	try {
		expressionParser.createExpression(m_expression.getExpression()).evaluate(sniffer);
	} catch (Throwable e) {
		throw new ThresholdExpressionException("Could not parse threshold expression:" + e.getMessage(), e);
	}

	m_datasources = sniffer.getSniffedKeys();
}
 
開發者ID:vishwaabhinav,項目名稱:OpenNMS,代碼行數:22,代碼來源:ExpressionConfigWrapper.java

示例2: JexlMapFSMContextInstance

import org.apache.commons.jexl2.JexlEngine; //導入依賴的package包/類
public JexlMapFSMContextInstance(String sessionId, String parentSessionId, SerializableMapContext innerContext,
                                 SortedSet<State> activeStates) {
    super();

    this.sessionId = sessionId;
    this.parentSessionId = parentSessionId;
    this.innerContext = innerContext;

    this.activeStates = new ArrayList<String>(activeStates != null ? activeStates.size() : 0);
    for (State activeState : activeStates) {
        this.activeStates.add(activeState.getName());
    }

    // remove current event
    this.innerContext.removeEntry(Context.EVENT_NAME);

    jexl = new JexlEngine();
}
 
開發者ID:carlos-verdes,項目名稱:scxml-java,代碼行數:19,代碼來源:JexlMapFSMContextInstance.java

示例3: setup

import org.apache.commons.jexl2.JexlEngine; //導入依賴的package包/類
public void setup(Context context) {
  dumpHomepages = context.getConfiguration().getBoolean(HOSTDB_DUMP_HOMEPAGES, false);
  dumpHostnames = context.getConfiguration().getBoolean(HOSTDB_DUMP_HOSTNAMES, false);
  String expr = context.getConfiguration().get(HOSTDB_FILTER_EXPRESSION);
  if (expr != null) {
    // Create or retrieve a JexlEngine
    JexlEngine jexl = new JexlEngine();
    
    // Dont't be silent and be strict
    jexl.setSilent(true);
    jexl.setStrict(true);
    
    // Create an expression object
    this.expr = jexl.createExpression(expr);
  }
}
 
開發者ID:jorcox,項目名稱:GeoCrawler,代碼行數:17,代碼來源:ReadHostDb.java

示例4: isAboveThreshold

import org.apache.commons.jexl2.JexlEngine; //導入依賴的package包/類
/**
 *
 */
@Override
public boolean isAboveThreshold(MetricTimeSeries timeSeries)
{
  Set<Long> timeWindowSet = timeSeries.getTimeWindowSet();
  JexlEngine jexl = new JexlEngine();
  JexlContext context = new MapContext();
  Expression e = jexl.createExpression(this.thresholdExpr);
  for(String metricName : metricNames){
    long sum = 0;
    for (Long timeWindow : timeWindowSet) {
      sum += timeSeries.get(timeWindow, metricName).longValue();
    }
    context.set(metricName, sum);
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug(metricName + " = " + sum);
    }
  }
  return ((Boolean)e.evaluate(context)).booleanValue();
}
 
開發者ID:Hanmourang,項目名稱:Pinot,代碼行數:23,代碼來源:MultiMetricTotalAggregateBasedRollupFunction.java

示例5: testPower

import org.apache.commons.jexl2.JexlEngine; //導入依賴的package包/類
@Test
public void testPower() {
	JexlEngine engine = ExpressionEvalFactory.getInstance();
	Expression expr = engine.createExpression("X^2");

	JexlContext context = new MapContext();
	// Don't need this really
	context.set("A", 20);
	context.set("B", 0);

	ArrayList<Double> actualList = new ArrayList<>();
	for (int i = -20; i < 20; i++) {
		context.set("X", i);
		Double result = (Double) expr.evaluate(context);
		actualList.add(result);
		System.out.println(result + ",");
	}

	Double[] actual = actualList.toArray(new Double[0]);
	Double[] expected = {400.0, 361.0, 324.0, 289.0, 256.0, 225.0, 196.0,
		169.0, 144.0, 121.0, 100.0, 81.0, 64.0, 49.0, 36.0, 25.0, 16.0,
		9.0, 4.0, 1.0, 0.0, 1.0, 4.0, 9.0, 16.0, 25.0, 36.0, 49.0, 64.0,
		81.0, 100.0, 121.0, 144.0, 169.0, 196.0, 225.0, 256.0, 289.0,
		324.0, 361.0};
	Assert.assertArrayEquals("results wrong", expected, actual);
}
 
開發者ID:umeding,項目名稱:fuzzer,代碼行數:27,代碼來源:JEXLTest.java

示例6: evaluate

import org.apache.commons.jexl2.JexlEngine; //導入依賴的package包/類
@Override
public double evaluate(Map<String, Double> values) throws ThresholdExpressionException {
    // Add all of the variable values to the script context
    Map<String,Object> context = new HashMap<String,Object>();
    context.putAll(values);
    context.put("datasources", new HashMap<String, Double>(values)); // To workaround NMS-5019
    context.put("math", new MathBinding());
    double result = Double.NaN;
    try {
        // Fetch an instance of the JEXL script engine to evaluate the script expression
        Object resultObject = new JexlEngine().createExpression(m_expression.getExpression()).evaluate(new MapContext(context));
        result = Double.parseDouble(resultObject.toString());
    } catch (Throwable e) {
        throw new ThresholdExpressionException("Error while evaluating expression " + m_expression.getExpression() + ": " + e.getMessage(), e);
    }
    return result;
}
 
開發者ID:qoswork,項目名稱:opennmszh,代碼行數:18,代碼來源:ExpressionConfigWrapper.java

示例7: _resolveAllFromSameSentence

import org.apache.commons.jexl2.JexlEngine; //導入依賴的package包/類
private static void _resolveAllFromSameSentence(Document d, String filter, String comment) {        
    JexlEngine jexl = new JexlEngine();
    jexl.setSilent(JEXL_SILENT);
    jexl.setLenient(JEXL_LENIENT);
    jexl.setDebug(JEXL_DBG);
    Expression expression = jexl.createExpression(filter);
    JexlContext jexlContext = new MapContext();
    jexlContext.set("Filter", Filter.class);
    for (Mention s: d.mentions) {
        jexlContext.set("s", s);
        List<Mention> tt = MentionBrowser.getAllFromSameSentence(s, expression, jexlContext);      
        for (Mention t : tt) {
            _resolve(d, s, t, comment);
        }
        
    }
}
 
開發者ID:aznotins,項目名稱:LVCoref,代碼行數:18,代碼來源:Resolve.java

示例8: evaluate

import org.apache.commons.jexl2.JexlEngine; //導入依賴的package包/類
@Override
public double evaluate(Map<String, Double> values) throws ThresholdExpressionException {
	// Add all of the variable values to the script context
	BindingsSniffer context = new BindingsSniffer();
	context.putAll(values);
	context.set("datasources",  new HashMap<String, Double>(values)); // To workaround NMS-5019
	context.put("math", new MathBinding());
	double result = Double.NaN;
	try {
	    // Fetch an instance of the JEXL script engine to evaluate the script expression
	    Object resultObject = new JexlEngine().createExpression(m_expression.getExpression()).evaluate(context);
	    result = Double.parseDouble(resultObject.toString());
	} catch (Throwable e) {
		throw new ThresholdExpressionException("Error while evaluating expression "+m_expression.getExpression()+": " + e.getMessage(), e);
	}
	return result;
}
 
開發者ID:vishwaabhinav,項目名稱:OpenNMS,代碼行數:18,代碼來源:ExpressionConfigWrapper.java

示例9: VanillaExpressionEngine

import org.apache.commons.jexl2.JexlEngine; //導入依賴的package包/類
public VanillaExpressionEngine() {
	//Create the Jexl engine with the DatasetArthmetic object to allows basic
	//mathematical calculations to be performed on Datasets
	jexl = new JexlEngine();

	expressionListeners = new HashSet<IExpressionEngineListener>();
}
 
開發者ID:eclipse,項目名稱:scanning,代碼行數:8,代碼來源:VanillaExpressionEngine.java

示例10: ComputedAttributesHandler

import org.apache.commons.jexl2.JexlEngine; //導入依賴的package包/類
public ComputedAttributesHandler() {
    engine = new JexlEngine();
    engine.setStrict(true);
    if (Context.getConfig() != null) {
        mapDeviceAttributes = Context.getConfig().getBoolean("processing.computedAttributes.deviceAttributes");
    }
}
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:8,代碼來源:ComputedAttributesHandler.java

示例11: parseExpression

import org.apache.commons.jexl2.JexlEngine; //導入依賴的package包/類
/**
 * Parses the given experssion to a Jexl expression. This supports
 * date parsing.
 *
 * @param expr the Jexl expression
 * @return parsed Jexl expression or null in case of parse error
 */
public static Expression parseExpression(String expr) {
  if (expr == null) return null;
  
  try {
    // Translate any date object into a long, dates must be specified as 20-03-2016T00:00:00Z
    Matcher matcher = datePattern.matcher(expr);
    if (matcher.find()) {
      String date = matcher.group();
      
      // Parse the thing and get epoch!
      Date parsedDate = DateUtils.parseDateStrictly(date, new String[] {"yyyy-MM-dd'T'HH:mm:ss'Z'"});
      long time = parsedDate.getTime();
      
      // Replace in the original expression
      expr = expr.replace(date, Long.toString(time));
    }
    
    JexlEngine jexl = new JexlEngine();
    jexl.setSilent(true);
    jexl.setStrict(true);
    return jexl.createExpression(expr);
  } catch (Exception e) {
    LOG.error(e.getMessage());
  }
  
  return null;
}
 
開發者ID:jorcox,項目名稱:GeoCrawler,代碼行數:35,代碼來源:JexlUtil.java

示例12: threadFinished

import org.apache.commons.jexl2.JexlEngine; //導入依賴的package包/類
@Override
public void threadFinished() {
    JexlEngine engine = threadLocalJexl.get();
    if(engine != null) {
        engine.clearCache();
        threadLocalJexl.remove();
    }
}
 
開發者ID:johrstrom,項目名稱:cloud-meter,代碼行數:9,代碼來源:Jexl2Function.java

示例13: registerIfNeeded

import org.apache.commons.jexl2.JexlEngine; //導入依賴的package包/類
public static final void registerIfNeeded(final ExpressionEvaluator expressionEvaluator)
{
	if (expressionEvaluator instanceof JexlExpressionEvaluator)
	{
		final JexlExpressionEvaluator jexlExpressionEvaluator = (JexlExpressionEvaluator)expressionEvaluator;
		final JexlEngine jexlEngine = jexlExpressionEvaluator.getJexlEngine();

		final Map<String, Object> existingFunctions = jexlEngine.getFunctions();
		if (existingFunctions != null && existingFunctions.get(NAMESPACE) instanceof JexlCustomFunctions)
		{
			// already registered
			return;
		}

		final Map<String, Object> functions = new HashMap<>();
		if (existingFunctions != null && !existingFunctions.isEmpty())
		{
			functions.putAll(existingFunctions);
		}

		final JexlCustomFunctions functionsInstance = new JexlCustomFunctions();
		functions.put(NAMESPACE, functionsInstance);
		jexlEngine.setFunctions(functions);

		logger.debug("Registered {} to namespace {}", functionsInstance, NAMESPACE);
	}
	else
	{
		logger.warn("Skip registering our custom functions because {} is not supported", expressionEvaluator);
	}
}
 
開發者ID:metasfresh,項目名稱:metasfresh,代碼行數:32,代碼來源:JexlCustomFunctions.java

示例14: CXMQLVisualizeScript

import org.apache.commons.jexl2.JexlEngine; //導入依賴的package包/類
public CXMQLVisualizeScript() {
    super();
    engine = new JexlEngine();
    context = new CXMQLContext();
    pe = new PrimitiveEngine();
    context.set("pe", pe);
    list = new ArrayList<CXMQLExpression>();
}
 
開發者ID:shuichi,項目名稱:MediaMatrix,代碼行數:9,代碼來源:CXMQLVisualizeScript.java

示例15: newJexlEngine

import org.apache.commons.jexl2.JexlEngine; //導入依賴的package包/類
/**
 * Creates a preconfigured JexlEngine.
 * <p>The instance is configured to use function namespaces from {@link scriptella.core.EtlVariable}.
 *
 * @return instance of JexlEngine.
 */
public static JexlEngine newJexlEngine() {
    JexlEngine je = new JexlEngine();
    Map<String, Object> fMap = new HashMap<String, Object>();
    EtlVariable etl = new EtlVariable();
    fMap.put("date", etl.getDate());
    fMap.put("text", etl.getText());
    fMap.put("class", etl.getClazz());
    je.setFunctions(fMap);
    return je;
}
 
開發者ID:scriptella,項目名稱:scriptella-etl,代碼行數:17,代碼來源:JexlExpression.java


注:本文中的org.apache.commons.jexl2.JexlEngine類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。