/** * 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); }
/** * 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); }
/** * 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); }
/** * Evaluate a string that is possiby an expression. * Expressions must use %{} * @param text The expression text. * @param imports The imports. * @param fetcher The fetcher. * @param cl The classloader. * @return The evaluated expression or the text. */ public static Object evaluateExpressionPotentially(String text, String[] imports, IValueFetcher fetcher, ClassLoader cl) { Object ret = text; if(text!=null && isExpressionString(text)) { try { ret = (String)SJavaParser.evaluateExpression(text.substring(2, text.length()-1), imports, fetcher, cl); } catch(Exception e) { ret = text; } } return ret; }
/** * Evaluate a value. */ public static Object evaluate(jadex.bridge.service.annotation.Value value, String[] imports) throws Exception { Object ret = null; Class<?> clazz = value.clazz(); if(clazz!=null && !Object.class.equals(clazz)) { ret = clazz.newInstance(); } else if(value.value().length()>0) { ret = SJavaParser.evaluateExpression(value.value(), imports, null, null); } return ret; } }
public static void parseArg(String okey, String val, AbstractPlatformConfiguration config) { String key = okey.startsWith("-")? okey.substring(1): okey; Object value = val; if(!StarterConfiguration.RESERVED.contains(key)) { // if not reserved, value is parsed and written to root config. try { value = SJavaParser.evaluateExpression(val, null); } catch(Exception e) { System.out.println("Argument parse exception using as string: "+key+" \""+val+"\""); } config.getRootConfig().setValue(key, value); } config.getStarterConfig().parseArg(key, val, value); }
/** * Evaluate a value. */ public static Object evaluate(Value value, String[] imports) throws Exception { Object ret = null; Class<?> clazz = value.getClazz(); if(clazz!=null && !Object.class.equals(clazz)) { ret = clazz.newInstance(); } else if(value.getExpression()!=null) { ret = SJavaParser.evaluateExpression(value.getExpression(), imports, null, null); } return ret; }
ret = (IFilter<Tuple2<IService, Object[]>>)SJavaParser.evaluateExpression(val.value(), fetcher);
ret = (IFilter<Tuple2<IService, Object[]>>)SJavaParser.evaluateExpression(val.value(), fetcher);
/** * Get the number of components to start. * @return The number. */ protected int getNumber(ComponentInstanceInfo component, IModelInfo model) { Object ret = component.getNumber()!=null? SJavaParser.evaluateExpression(component.getNumber(), model.getAllImports(), this.component.getFetcher(), this.component.getClassLoader()): null; return ret instanceof Integer? ((Integer)ret).intValue(): 1; }
Object val = SJavaParser.evaluateExpression(arguments[i].getValue(), imports, fetcher, cl); ret.put(arguments[i].getName(), val); ret = (Map<String, Object>)SJavaParser.evaluateExpression(argumentsexp.getValue(), imports, fetcher, cl);
Object val = SJavaParser.evaluateExpression(arguments[i].getValue(), imports, fetcher, cl); ret.put(arguments[i].getName(), val); ret = (Map<String, Object>)SJavaParser.evaluateExpression(argumentsexp.getValue(), imports, fetcher, cl);
/** * Set an injected field value. */ protected void setFieldValue(Object val, Field field, String convert) { if(val!=null || !SReflect.isBasicType(field.getType())) { try { Object agent = microagent instanceof IPojoMicroAgent? ((IPojoMicroAgent)microagent).getPojoAgent(): microagent; if(convert!=null) { SimpleValueFetcher fetcher = new SimpleValueFetcher(getFetcher()); fetcher.setValue("$value", val); val = SJavaParser.evaluateExpression(convert, getModel().getAllImports(), fetcher, getClassLoader()); } field.setAccessible(true); field.set(agent, val); } catch(Exception e) { throw new RuntimeException(e); } } }
/** * Get the number of components to start. * @return The number. */ public int getNumber(ComponentInstanceInfo component, IModelInfo model) { assert !getComponentAdapter().isExternalThread(); Object ret = component.getNumber()!=null? SJavaParser.evaluateExpression(component.getNumber(), model.getAllImports(), getFetcher(), getClassLoader()): null; return ret instanceof Integer? ((Integer)ret).intValue(): 1; }
Object val = SJavaParser.evaluateExpression(arguments[i].getValue(), model.getAllImports(), this.component.getFetcher(), this.component.getClassLoader()); ret.put(arguments[i].getName(), val); ret = (Map<String, Object>)SJavaParser.evaluateExpression(argumentsexp.getValue(), model.getAllImports(), this.component.getFetcher(), this.component.getClassLoader());
/** * Set an injected field value. */ protected void setFieldValue(Object val, Field field, String convert) { if(val!=null || !SReflect.isBasicType(field.getType())) { try { Object agent = getComponent().getComponentFeature(IPojoComponentFeature.class).getPojoAgent(); if(convert!=null) { SimpleValueFetcher fetcher = new SimpleValueFetcher(getComponent().getFetcher()); fetcher.setValue("$value", val); val = SJavaParser.evaluateExpression(convert, getComponent().getModel().getAllImports(), fetcher, getComponent().getClassLoader()); } field.setAccessible(true); field.set(agent, val); } catch(Exception e) { throw new RuntimeException(e); } } } }
Object val = SJavaParser.evaluateExpression(arguments[i].getValue(), model.getAllImports(), getFetcher(), getClassLoader()); ret.put(arguments[i].getName(), val); ret = (Map<String, Object>)SJavaParser.evaluateExpression(argumentsexp.getValue(), model.getAllImports(), getFetcher(), getClassLoader());
/** * Get the name of components to start. * @return The name. */ protected String getName(ComponentInstanceInfo component, IModelInfo model, int cnt) { String ret = component.getName(); if(ret!=null) { SimpleValueFetcher fetcher = new SimpleValueFetcher(this.component.getFetcher()); fetcher.setValue("$n", Integer.valueOf(cnt)); try { ret = (String)SJavaParser.evaluateExpression(component.getName(), model.getAllImports(), fetcher, this.component.getClassLoader()); if(ret==null) ret = component.getName(); } catch(RuntimeException e) { } } return ret; }
val = SJavaParser.evaluateExpression(convback, getModel().getAllImports(), fetcher, getClassLoader());
/** * Get the name of components to start. * @return The name. */ public String getName(ComponentInstanceInfo component, IModelInfo model, int cnt) { assert !getComponentAdapter().isExternalThread(); String ret = component.getName(); if(ret!=null) { SimpleValueFetcher fetcher = new SimpleValueFetcher(getFetcher()); fetcher.setValue("$n", Integer.valueOf(cnt)); try { ret = (String)SJavaParser.evaluateExpression(component.getName(), model.getAllImports(), fetcher, getClassLoader()); if(ret==null) ret = component.getName(); } catch(RuntimeException e) { } } return ret; }