/** * @param name the name of the variable to lookup * @return the variable value */ public Object getVariable(String name) { try { return getProxyBuilder().doGetVariable(name); } catch(MissingPropertyException mpe) { if(mpe.getProperty().equals(name) && propertyMissingDelegate != null) { return propertyMissingDelegate.call(new Object[]{name}); } throw mpe; } }
/** * Overloaded to make variables appear as bean properties or via the subscript operator */ public Object getProperty(String property) { try { return getProxyBuilder().doGetProperty(property); } catch (MissingPropertyException mpe) { if ((getContext() != null) && (getContext().containsKey(property))) { return getContext().get(property); } else { try { return getMetaClass().getProperty(this, property); } catch(MissingPropertyException mpe2) { if(mpe2.getProperty().equals(property) && propertyMissingDelegate != null) { return propertyMissingDelegate.call(new Object[]{property}); } throw mpe2; } } } }
@Override public Object getProperty(final String name) { try { return doGetProperty(name); } catch (MissingFieldException e) { if (e.getField().equals(name) && scope.containsKey(name)) { return scope.get(name); } throw e; } catch (MissingPropertyException e) { if (e.getProperty().equals(name) && scope.containsKey(name)) { return scope.get(name); } throw e; } }
/** * @param name the name of the variable to lookup * @return the variable value */ public Object getVariable(String name) { try { return getProxyBuilder().doGetVariable(name); } catch(MissingPropertyException mpe) { if(mpe.getProperty().equals(name) && propertyMissingDelegate != null) { return propertyMissingDelegate.call(new Object[]{name}); } throw mpe; } }
private static Object evaluateGroovyExpression(final String script, final Binding binding) throws GroovyException { final ClassLoader scriptClassLoader = Thread.currentThread().getContextClassLoader(); final Script groovyScript = GroovyScriptBuilder.getScript(script, scriptClassLoader); groovyScript.setBinding(binding); Object result = null; try { result = groovyScript.run(); } catch (final MissingPropertyException e) { final String lineSeparator = System.getProperty("line.separator", "\n"); final StringBuilder stb = new StringBuilder(); stb.append("Error in Groovy script: unable to use element \"" + e.getProperty() + "\""); stb.append(lineSeparator); stb.append(lineSeparator); stb.append("Possible cause:"); stb.append(lineSeparator); stb.append("- missing import"); stb.append(lineSeparator); stb.append("- variable not found (wrong name, undefined)"); stb.append(lineSeparator); stb.append("- ..."); stb.append(lineSeparator); stb.append(lineSeparator); stb.append("Script:"); stb.append(lineSeparator); stb.append("\"" + script + "\""); stb.append(lineSeparator); throw new GroovyException(stb.toString(), e); } return result; }
@Override protected DynamicInvokeResult getOpaqueProperty(String name) { try { return DynamicInvokeResult.found(groovyObject.getProperty(name)); } catch (MissingPropertyException e) { if (!name.equals(e.getProperty())) { throw e; } // Else, ignore } return DynamicInvokeResult.notFound(); }
@Override protected DynamicInvokeResult setOpaqueProperty(MetaClass metaClass, String name, Object value) { try { groovyObject.setProperty(name, value); return DynamicInvokeResult.found(); } catch (MissingPropertyException e) { if (!name.equals(e.getProperty())) { throw e; } // Else, ignore } return DynamicInvokeResult.notFound(); }
@Override public Object evaluate(final SExpression expression, final Map<String, Object> context, final Map<Integer, Object> resolvedExpressions, final ContainerState containerState) throws SExpressionEvaluationException { final String expressionContent = expression.getContent(); final ClassLoader scriptClassLoader = Thread.currentThread().getContextClassLoader(); final String expressionName = expression.getName(); try { final GroovyShell shell = new GroovyShell(scriptClassLoader); // can put the name here final Script script = shell.parse(expressionContent); final Binding binding = new Binding(context); script.setBinding(binding); return script.evaluate(expressionContent); } catch (final MissingPropertyException e) { final String property = e.getProperty(); final StringBuilder builder = new StringBuilder("Expression "); builder.append(expressionName).append(" with content: ").append(expressionContent).append(" depends on ").append(property) .append(" is neither defined in the script nor in dependencies"); throw new SExpressionEvaluationException(builder.toString(), e, expressionName); } catch (final GroovyRuntimeException e) { throw new SExpressionEvaluationException(e, expressionName); } catch (final Exception e) { throw new SExpressionEvaluationException("Script throws an exception" + expression, e, expressionName); } }
@Override public Object evaluate(final SExpression expression, final Map<String, Object> context, final Map<Integer, Object> resolvedExpressions, final ContainerState containerState) throws SExpressionEvaluationException { final String expressionContent = expression.getContent(); final ClassLoader scriptClassLoader = Thread.currentThread().getContextClassLoader(); final String expressionName = expression.getName(); try { final GroovyShell shell = new GroovyShell(scriptClassLoader); // can put the name here final Script script = shell.parse(expressionContent); final Binding binding = new Binding(context); script.setBinding(binding); return script.evaluate(expressionContent); } catch (final MissingPropertyException e) { final String property = e.getProperty(); final StringBuilder builder = new StringBuilder("Expression "); builder.append(expressionName).append(" with content: ").append(expressionContent).append(" depends on ").append(property) .append(" is neither defined in the script nor in dependencies"); throw new SExpressionEvaluationException(builder.toString(), e, expressionName); } catch (final GroovyRuntimeException e) { throw new SExpressionEvaluationException(e, expressionName); } catch (final Exception e) { throw new SExpressionEvaluationException("Script throws an exception" + expression, e, expressionName); } }
/** * Overloaded to make variables appear as bean properties or via the subscript operator */ public Object getProperty(String property) { try { return getProxyBuilder().doGetProperty(property); } catch (MissingPropertyException mpe) { if ((getContext() != null) && (getContext().containsKey(property))) { return getContext().get(property); } else { try { return getMetaClass().getProperty(this, property); } catch(MissingPropertyException mpe2) { if(mpe2.getProperty().equals(property) && propertyMissingDelegate != null) { return propertyMissingDelegate.call(new Object[]{property}); } throw mpe2; } } } }
return script.run(); } catch (final MissingPropertyException e) { final String property = e.getProperty(); throw new SExpressionEvaluationException("Expression " + expressionName + " with content = <" + expressionContent + "> depends on " + property + " is neither defined in the script nor in dependencies.", e, expressionName);
return script.run(); } catch (MissingPropertyException e) { String property = e.getProperty(); monitor.warn("variable " + property + " undefined: check naming. Adding as no-data for future evaluations.");
return script.run(); } catch (final MissingPropertyException e) { final String property = e.getProperty(); throw new SExpressionEvaluationException("Expression " + expressionName + " with content = <" + expressionContent + "> depends on " + property + " is neither defined in the script nor in dependencies.", e, expressionName);
throw new ExpressionCompilationException(expression, "No such property: " + e.getProperty()); } catch (MultipleCompilationErrorsException e) { StringWriter s = new StringWriter();
return DynamicInvokeResult.found(propertyMissing.invoke(bean, new Object[]{name})); } catch (MissingPropertyException e) { if (!name.equals(e.getProperty())) { throw e;
return DynamicInvokeResult.found(); } catch (MissingPropertyException e) { if (!name.equals(e.getProperty())) { throw e;