Package groovy.lang

Examples of groovy.lang.Script


        DispatchContext dctx = dispatcher.getLocalContext(localName);
        gContext.put("dctx", dctx);
        gContext.put("dispatcher", dctx.getDispatcher());
        gContext.put("delegator", dispatcher.getDelegator());
        try {
            Script script = InvokerHelper.createScript(GroovyUtil.getScriptClassFromLocation(this.getLocation(modelService)), GroovyUtil.getBinding(gContext));
            Object resultObj = null;
            if (UtilValidate.isEmpty(modelService.invoke)) {
                resultObj = script.run();
            } else {
                resultObj = script.invokeMethod(modelService.invoke, EMPTY_ARGS);
            }
            if (resultObj != null && resultObj instanceof Map<?, ?>) {
                return cast(resultObj);
            } else if (gContext.get("result") != null && gContext.get("result") instanceof Map<?, ?>) {
                return cast(gContext.get("result"));
View Full Code Here


            DescriptorParser contentHandler) throws SAXException, IOException
    {
        HiveMindBuilder builder = new HiveMindBuilder(contentHandler);

        GroovyCodeSource source = new GroovyCodeSource(resource.getResourceURL());
        Script script;

        try
        {
            script = getGroovyShell().parse(source);
        }
        catch (Exception e)
        {
            throw new ApplicationRuntimeException(e);
        }

        Binding processorBinding = new Binding();
        processorBinding.setVariable("processor", builder);

        script.setBinding(processorBinding);

        script.run();

        return contentHandler.getModuleDescriptor();
    }
View Full Code Here

        mock.startElement("", "module", "module", attrs);
        mock.endElement("", "module", "module");

        replayControls();

        Script script = new GroovyShell().parse("processor.module(id:'basic', version:'1.0.0')");

        runScript(script, mock);
    }
View Full Code Here

        parser.initialize(resource, getClassResolver());

        GroovyCodeSource source = new GroovyCodeSource(resource.getResourceURL());

        Script script = new GroovyShell().parse(source);

        try
        {
            runScript(script, parser);
View Full Code Here

                builder.name(propertyName);
                builder.beanClass(instance.getClass());
                return builder.build();
            }
        } else if (instance instanceof Script) {
            Script script = (Script)instance;
            if(script.getBinding().hasVariable(propertyName)) {
                return ScriptVariableProperty.getProperty(script, propertyName);
            } else
                return null;
        }else {
            return null;
View Full Code Here

   */
  public static void main(final String[] args) throws InstantiationException, Exception {
    Binding binding = new Binding();
    binding.setVariable("foo", new Integer(2));
    GroovyShell shell = new GroovyShell(binding);
    Script script = shell.parse("service.with{sru()} ;x = 123; return foo * 10;");
    MetaClass metaClass = script.getMetaClass();
    Binding binding2 = script.getBinding();
    // Object property = script.getProperty("service");
    script.setProperty("service", new CustomerService() {

      @Override
      public void sru() {
        System.out.println("sruuu");

      }

    });
    script.run();

    String fileName = "src/main/java/Tester.groovy";
    GroovyClassLoader gcl = new GroovyClassLoader();
    Class clazz = gcl.parseClass(new File(fileName));
    Field[] fields = clazz.getFields();
View Full Code Here

  public static void main(final String[] args) {
    Binding binding = new Binding();
    binding.setVariable("foo", new Integer(2));
    GroovyShell shell = new GroovyShell(binding);
    long start = System.currentTimeMillis();
    Script script = shell.parse("x = 123; return foo * 10");
    MetaClass metaClass = script.getMetaClass();
    Binding binding2 = script.getBinding();
    for (int i = 0; i < 1000; i++) {
      script.run();
    }
    long end = System.currentTimeMillis() - start;
    System.out.println("Parsowenie " + end);

    start = System.currentTimeMillis();
View Full Code Here

    protected String assertionFailureMessage(Exchange exchange) {
        return "groovy: " + text;
    }

    public Object evaluate(Exchange exchange) {
        Script script = ExchangeHelper.newInstance(exchange, scriptType);
        // lets configure the script
        configure(exchange, script);
        return script.run();
    }
View Full Code Here

    public static Object runScriptAtLocation(String location, String methodName, Map<String, Object> context) throws GeneralException {
        return runScriptAtLocation(location, methodName, context, null);
    }

    public static Object runScriptAtLocation(String location, String methodName, Map<String, Object> context, GroovyClassLoader groovyClassLoader) throws GeneralException {
        Script script = InvokerHelper.createScript(getScriptClassFromLocation(location, groovyClassLoader), getBinding(context));
        Object result = null;
        if (UtilValidate.isEmpty(methodName)) {
            result = script.run();
        } else {
            result = script.invokeMethod(methodName, new Object[] { context });
        }
        return result;
    }
View Full Code Here

        // use application classloader if given
        ClassLoader cl = exchange.getContext().getApplicationContextClassLoader();
        GroovyShell shell = cl != null ? new GroovyShell(cl) : new GroovyShell();

        // need to re-parse script due thread-safe with binding
        Script script = shell.parse(text);
        configure(exchange, script.getBinding());
        Object value = script.evaluate(text);

        return exchange.getContext().getTypeConverter().convertTo(type, value);
    }
View Full Code Here

TOP

Related Classes of groovy.lang.Script

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.