/** * Evaluates a java expression. * @param fetcher Expression parameters can be supplied as value fetcher. * @return The evaluated object. */ public static Object evaluateExpression(String exptxt, String[] imports, IValueFetcher fetcher, ClassLoader classloader) { IParsedExpression exp = parser.parseExpression(exptxt, imports, null, classloader); return exp.getValue(fetcher); }
/** * Evaluates a java expression. * @param fetcher Expression parameters can be supplied as value fetcher. * @return The evaluated object. */ public static Object evaluateExpression(String exptxt, IValueFetcher fetcher) { return evaluateExpression(exptxt, null, fetcher, null); }
public void setValue(Object value) { this.value = value; if(type == null) type = ((IParsedExpression)value).getStaticType(); }
/** * Execute the query using a local parameter. * @param name The name of the local parameter. * @param value The value of the local parameter. * @return the result value of the query. */ public Object execute(String name, Object value) { SimpleValueFetcher fet = new SimpleValueFetcher(CapabilityWrapper.getFetcher(getAgent(), uexp.getLanguage())); fet.setValue(name, value); return getParsedExpression().getValue(fet); }
/** * Get a parsed value. * Handles values, which may be parsed or unparsed, * and always returns a parsed value. * @param value The value. * @return The parsed and evaluated value. */ public static Object getParsedValue(Object value, String[] imports, IValueFetcher fetcher, ClassLoader classloader) { if(value instanceof UnparsedExpression) { // todo: language UnparsedExpression upe = (UnparsedExpression)value; IParsedExpression pe = parseExpression(upe, imports, classloader); value = pe!=null ? pe.getValue(fetcher) : null; } return value; }
public void run() { object = expression.getValue(new OAVBDIFetcher(state, scope)); } };
/** * Wrap the fetcher to include the element itself. */ public SimpleValueFetcher wrapFetcher(final IValueFetcher fetcher) { SimpleValueFetcher ret = new SimpleValueFetcher(fetcher); ret.setValue(getFetcherName(), this); return ret; }
/** * Create a new ExpressionCondition. */ public ExpressionCondition(UnparsedExpression expression, IValueFetcher fetcher) { this.expression = expression; this.fetcher = new SimpleValueFetcher(fetcher); }
/** * Parse the expression. * The result is cached for later accesses. */ public static IParsedExpression parseExpression(UnparsedExpression ue, String[] imports, ClassLoader classloader) { IParsedExpression ret = (IParsedExpression)ue.getParsed(); // todo: language if(ret==null && ue.getValue()!=null) { ret = SJavaParser.parseExpression(ue.getValue(), imports, classloader); ue.setParsedExp(ret); } return ret; }
/** * Add reason to fetcher. */ @Override public SimpleValueFetcher wrapFetcher(IValueFetcher fetcher) { SimpleValueFetcher ret = super.wrapFetcher(fetcher); if(reason instanceof RParameterElement) { ret.setValue(((RParameterElement)reason).getFetcherName(), reason); } return ret; }
/** * Get a parsed property. * Handles properties, which may be parsed or unparsed, * and always returns a parsed property value. * @param name The property name. * @return The property value or null if property not defined. */ public static Object getProperty(Map<String, Object> properties, String name, String[] imports, IValueFetcher fetcher, ClassLoader classloader) { return getParsedValue(properties!=null ? properties.get(name) : null, imports, fetcher, classloader); }
/** * Evaluates a java expression. * @return The evaluated object. */ public static IParsedExpression parseExpression(String exptxt, String[] imports, ClassLoader classloader) { return parser.parseExpression(exptxt, imports, null, classloader); }
/** * Get a parsed property. * Unlike raw properties, which may be parsed or unparsed, * this method always returns parsed property values. * @param name The property name. * @return The property value or null if property not defined. */ public Object getProperty(String name, ClassLoader cl) { // Todo: caching of parsed values? return SJavaParser.getProperty(getProperties(), name, getAllImports(), null, cl); }
public String convertObject(Object val, Object context) { String ret = null; if(val instanceof IParsedExpression) { ret = ((IParsedExpression)val).getExpressionText(); } return ret; } }
/** * Get an object from the map. * @param name The name * @return The value. */ public Object get(Object name) { return ((IMapAccess)beliefbase).get(prefix+name); }
/** * Returns a property. * @param name name of the property * @return the property */ public Object getProperty(String name) { Object ret = super.getProperty(name); if(ret instanceof IParsedExpression) { ret = ((IParsedExpression)ret).getValue(fetcher); } return ret; } }
/** * Evaluate an expression string (using "" -> null mapping) as annotations * do not support null values. */ protected Object evaluateExpression(String exp, String[] imports, IValueFetcher fetcher, ClassLoader classloader) { return exp.length()==0? null: SJavaParser.evaluateExpression(exp, imports, null, classloader); }
/** * Get a parsed property. * Unlike raw properties, which may be parsed or unparsed, * this method always returns parsed property values. * @param name The property name. * @return The property value or null if property not defined. */ public Object getProperty(String name, ClassLoader cl) { // Todo: caching of parsed values? return SJavaParser.getProperty(getProperties(), name, getAllImports(), null, cl); }
/** * */ public static Object execute(IOAVState state, IParsedExpression exp, Object scope, String[] names, Object[] values) { OAVBDIFetcher fetcher = new OAVBDIFetcher(state, scope); for(int i=0; i<names.length; i++) fetcher.setValue(names[i], values[i]); return exp.getValue(fetcher); }
/** * Evaluate an expression string (using "" -> null mapping) as annotations * do not support null values. */ protected Object evaluateExpression(String exp, String[] imports, IValueFetcher fetcher, ClassLoader classloader) { return exp.length()==0? null: SJavaParser.evaluateExpression(exp, imports, null, classloader); }