/** * Create a new naming strategy using an JEXL expression and the given expression. * * @param expr - the JEXL expression to use to create names. */ public JexlNamingStrategy(String expr) throws JexlException { jexl = new JexlEngine(); this.parsedExpr = jexl.createExpression(expr); }
public void setExpression(final String expr) { this.expression = jexl.createExpression(expr); }
public String getExpression() { return this.expression.getExpression(); }
Object result = null; try { final Expression e = jexl.createExpression(innerExpression); result = e.evaluate(new MapContext()); } catch (final JexlException e) { throw new IllegalArgumentException("Expression " + value + " not well formed. " + e.getMessage(), e);
public Object computeAttribute(Attribute attribute, Position position) throws JexlException { return engine.createExpression(attribute.getExpression()).evaluate(prepareContext(position)); }
/** * Format the name for the given result. * * @param result - the result of a JMX query. * @return String - the formatted string resulting from the expression, or null if the formatting fails. */ @Override public String formatName(Result result) { String formatted; JexlContext context = new MapContext(); this.populateContext(context, result); try { formatted = (String) this.parsedExpr.evaluate(context); } catch (JexlException jexlExc) { LOG.error("error applying JEXL expression to query results", jexlExc); formatted = null; } return formatted; }
public boolean isMet() { if (logger.isDebugEnabled()) { logger.debug("Testing condition " + this.expression); } return this.expression.evaluate(this.context).equals(Boolean.TRUE); }
public ComputedAttributesHandler() { engine = new JexlEngine(); engine.setStrict(true); engine.setFunctions(Collections.singletonMap("math", (Object) Math.class)); if (Context.getConfig() != null) { mapDeviceAttributes = Context.getConfig().getBoolean("processing.computedAttributes.deviceAttributes"); } }
private MapContext prepareContext(Position position) { MapContext result = new MapContext(); if (mapDeviceAttributes) { Device device = Context.getIdentityManager().getById(position.getDeviceId()); if (device != null) { for (Object key : device.getAttributes().keySet()) { result.set((String) key, device.getAttributes().get(key)); } } } Set<Method> methods = new HashSet<>(Arrays.asList(position.getClass().getMethods())); methods.removeAll(Arrays.asList(Object.class.getMethods())); for (Method method : methods) { if (method.getName().startsWith("get") && method.getParameterTypes().length == 0) { String name = Character.toLowerCase(method.getName().charAt(3)) + method.getName().substring(4); try { if (!method.getReturnType().equals(Map.class)) { result.set(name, method.invoke(position)); } else { for (Object key : ((Map) method.invoke(position)).keySet()) { result.set((String) key, ((Map) method.invoke(position)).get(key)); } } } catch (IllegalAccessException | InvocationTargetException error) { LOGGER.warn("Attribute reflection error", error); } } } return result; }
private static String resolveVariableExpression(final String value) { final JexlEngine jexl = new JexlEngine(); return resolveVariableExpression(value, value.length(), jexl); }
/** * Populate the context with values from the result. * * @param context - the expression context used when evaluating JEXL expressions. * @param result - the result of a JMX query. */ protected void populateContext(JexlContext context, Result result) { context.set(VAR_CLASSNAME, result.getClassName()); context.set(VAR_ATTRIBUTE_NAME, result.getAttributeName()); context.set(VAR_CLASSNAME_ALIAS, result.getKeyAlias()); Map<String, String> typeNameMap = TypeNameValue.extractMap(result.getTypeName()); context.set(VAR_TYPENAME, typeNameMap); String effectiveClassname = result.getKeyAlias(); if (effectiveClassname == null) { effectiveClassname = result.getClassName(); } context.set(VAR_EFFECTIVE_CLASSNAME, effectiveClassname); context.set(VAR_RESULT, result); } }
private void setCheckers(final Map<String, ConditionChecker> checkers) { this.checkers = checkers; for (final ConditionChecker checker : checkers.values()) { this.context.set(checker.getId(), checker); } updateNextCheckTime(); }
public JexlExpressionHandler() { jexl = new JadeJexlEngine(); jexl.setCache(MAX_ENTRIES); }
public JadeJexlEngine() { super(new JadeIntrospect(null), new JadeJexlArithmetic(true), null, null); setStrict(false); }
/** * Create a new naming strategy using an JEXL expression and the default expression. */ public JexlNamingStrategy() throws JexlException { jexl = new JexlEngine(); this.parsedExpr = jexl.createExpression(DEFAULT_EXPRESSION); }
public void setExpression(String expr) throws JexlException { this.parsedExpr = this.jexl.createExpression(expr); }
public Object toJson() { final Map<String, Object> jsonObj = new HashMap<>(); jsonObj.put("expression", this.expression.getExpression()); final List<Object> checkersJson = new ArrayList<>(); for (final ConditionChecker checker : this.checkers.values()) { final Map<String, Object> oneChecker = new HashMap<>(); oneChecker.put("type", checker.getType()); oneChecker.put("checkerJson", checker.toJson()); checkersJson.add(oneChecker); } jsonObj.put("checkers", checkersJson); jsonObj.put("nextCheckTime", String.valueOf(this.nextCheckTime)); return jsonObj; }
public Condition(final Map<String, ConditionChecker> checkers, final String expr, final long nextCheckTime) { this.nextCheckTime = nextCheckTime; setCheckers(checkers); this.expression = jexl.createExpression(expr); }
/** * 取得表达式字符串表示。 * * @return 表达式字符串表示 */ public String getExpressionText() { return expression.getExpression(); }
public Condition(final Map<String, ConditionChecker> checkers, final String expr) { setCheckers(checkers); this.expression = jexl.createExpression(expr); updateNextCheckTime(); }