/** * 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); }
/** * 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; }
/** * 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); }
/** * 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; }
val = SJavaParser.getParsedValue(val, model.getAllImports(), null, Starter.class.getClassLoader()); Object newval = SJavaParser.evaluateExpression((String)val, null); if(newval!=null)
if(uexp!=null) Object val = SJavaParser.parseExpression(uexp, ia.getModel().getAllImports(), ia.getClassLoader()).getValue( CapabilityWrapper.getFetcher(ia, uexp.getLanguage(), vals)); if(val instanceof Boolean) Object val = SJavaParser.getParsedValue(upex, null, CapabilityWrapper.getFetcher(ia, upex.getLanguage(), vals), null); if(val instanceof Boolean)
/** * 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); }
/** * Get the number of components to start. * Allows filename to be dynamically evaluated. * @return The number. */ protected String getFilename(ComponentInstanceInfo component, IModelInfo model) { String ret = null; SubcomponentTypeInfo si = component.getType(model); ret = (String)SJavaParser.evaluateExpressionPotentially(si.getFilename(), model.getAllImports(), this.component.getFetcher(), this.component.getClassLoader()); // if(si.getFilename()!=null && si.getFilename().startsWith("%{")) // { // try // { // ret = (String)SJavaParser.evaluateExpression(si.getFilename().substring(2, si.getFilename().length()-1), model.getAllImports(), this.component.getFetcher(), this.component.getClassLoader()); // } // catch(Exception e) // { // ret = si.getFilename(); // } // } // else // { // ret = si.getFilename(); // } return ret; }
/** * 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); }
final CounterResultListener<Void> lis2 = new CounterResultListener<Void>(infos.length, lis); String sername = (String)SJavaParser.evaluateExpressionPotentially(sernames[i], component.getModel().getAllImports(), component.getFetcher(), component.getClassLoader());
/** * Parses the expression if possible. * * @param exp The expression. * @param imports The imports. * @param cl The class loader. * @return Parsed expression or unparsed if class loader is unavailable. */ protected static final UnparsedExpression parseExp(UnparsedExpression exp, String[] imports, ClassLoader cl) { if(cl != null) { try { SJavaParser.parseExpression(exp, imports, cl); } catch(Exception e) { System.err.println("Error parsing expression, name="+exp.getName()+", expstring="+exp.getValue()); throw new RuntimeException(e); } } return exp; }
/** * 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); }
/** * Returns the value as it is used in the (already loaded) model. * * @param key * @return Object */ private Object getValueFromModel(String key) { Object val; Argument argument = (Argument)model.getArgument(key); val = SJavaParser.getParsedValue(argument, model.getAllImports(), null, Starter.class.getClassLoader()); if(val == null) { // get default value val = SJavaParser.getParsedValue(argument.getDefaultValue(), model.getAllImports(), null, Starter.class.getClassLoader()); } return val; } }
Object ex = SJavaParser.getProperty(properties, RemoteServiceManagementService.REMOTE_EXCLUDED, imports, null, cl); if(ex!=null) Object syn = SJavaParser.getProperty(properties, RemoteServiceManagementService.REMOTE_SYNCHRONOUS, imports, null, cl); if(syn!=null) Object un = SJavaParser.getProperty(properties, RemoteServiceManagementService.REMOTE_UNCACHED, imports, null, cl); if(un!=null) Object mr = SJavaParser.getProperty(properties, RemoteServiceManagementService.REMOTE_METHODREPLACEMENT, imports, null, cl); if(mr!=null) Object to = SJavaParser.getProperty(properties, RemoteServiceManagementService.REMOTE_TIMEOUT, imports, null, cl); if(to!=null) Object td = SJavaParser.getProperty(properties, ITargetResolver.TARGETRESOLVER, imports, null, cl); if(td!=null)
/** * */ public IParsedExpression getParsedExpression() { return SJavaParser.parseExpression(uexp, agent.getModel().getAllImports(), agent.getClassLoader()); } }
/** * 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 the configuration name. */ protected static String getConfigurationName(IModelInfo model, Map<String, Object> cmdargs) { String configname = (String)cmdargs.get(CONFIGURATION_NAME); if(configname==null) { Object val = null; IArgument arg = model.getArgument(CONFIGURATION_NAME); if(arg!=null) { val = arg.getDefaultValue(); } val = SJavaParser.getParsedValue(val, model.getAllImports(), null, Starter.class.getClassLoader()); // val = UnparsedExpression.getParsedValue(val, model.getAllImports(), null, model.getClassLoader()); configname = val!=null ? val.toString() : null; } return configname; }
Object ex = SJavaParser.getProperty(properties, RemoteServiceManagementService.REMOTE_EXCLUDED, imports, null, cl); if(ex!=null) Object syn = SJavaParser.getProperty(properties, RemoteServiceManagementService.REMOTE_SYNCHRONOUS, imports, null, cl); if(syn!=null) Object un = SJavaParser.getProperty(properties, RemoteServiceManagementService.REMOTE_UNCACHED, imports, null, cl); if(un!=null) Object mr = SJavaParser.getProperty(properties, RemoteServiceManagementService.REMOTE_METHODREPLACEMENT, imports, null, cl); if(mr!=null) Object to = SJavaParser.getProperty(properties, RemoteServiceManagementService.REMOTE_TIMEOUT, imports, null, cl); if(to!=null)
public Object postProcess(IContext context, Object object) { ModelInfo cm = (ModelInfo)context.getRootObject(); UnparsedExpression exp = (UnparsedExpression)object; SJavaParser.parseExpression(exp, cm.getAllImports(), context.getClassLoader()); return object; }
Object newval = SJavaParser.evaluateExpression((String)val, null); if(newval!=null)