Package org.codehaus.groovy.runtime

Examples of org.codehaus.groovy.runtime.MethodClosure


import org.codehaus.groovy.runtime.MethodClosure;

public class Groovy4104A {
    public MethodClosure createMethodClosure() {
        return new MethodClosure(this, "someMethod");
    }
View Full Code Here


        GroovyClassLoader loader = new GroovyClassLoader(Thread.currentThread().getContextClassLoader());
        Class clazz = loader.parseClass(codeSource);
        Script script = ((Script) clazz.newInstance());

        Binding binding = new Binding();
        binding.setVariable("method", new MethodClosure(new Dummy(), "method"));
        script.setBinding(binding);

        script.run();
    }
View Full Code Here

    }

    public static List<MetaMethod> createMethodList(final String name, final Class declaringClass, final Closure closure) {
        List<MetaMethod> res = new ArrayList<MetaMethod>();
        if (closure instanceof MethodClosure) {
            MethodClosure methodClosure = (MethodClosure) closure;
            Object owner = closure.getOwner();
            Class ownerClass = (Class) (owner instanceof Class ? owner : owner.getClass());
            for (CachedMethod method : ReflectionCache.getCachedClass(ownerClass).getMethods() ) {
                if (method.getName().equals(methodClosure.getMethod())) {
                    MetaMethod metaMethod = new MethodClosureMetaMethod(name, declaringClass, closure, method);
                    res.add(adjustParamTypesForStdMethods(metaMethod, name));
                }
            }
        }
View Full Code Here

        super.setVariable("out", output.getWriter());
        super.setVariable("sout", output.getOutputStream());
        super.setVariable("html", new MarkupBuilder(output.getWriter()));
       
        // bind forward method
        MethodClosure c = new MethodClosure(this, "forward");
        super.setVariable("forward", c);
       
        // bind include method
        c = new MethodClosure(this, "include");
        super.setVariable("include", c);
       
        // bind redirect method
        c = new MethodClosure(this, "redirect");
        super.setVariable("redirect", c);
    }
View Full Code Here

     * from that result as well.
     */
    protected Map<String,Closure> buildDefaultEncoderMap() {
        Map<String,Closure> encoders = new HashMap<String,Closure>();

        encoders.put( ContentType.BINARY.toString(), new MethodClosure(this,"encodeStream") );
        encoders.put( ContentType.TEXT.toString(), new MethodClosure( this, "encodeText" ) );
        encoders.put( ContentType.URLENC.toString(), new MethodClosure( this, "encodeForm" ) );

        Closure encClosure = new MethodClosure(this,"encodeXML");
        for ( String ct : ContentType.XML.getContentTypeStrings() )
            encoders.put( ct, encClosure );
        encoders.put( ContentType.HTML.toString(), encClosure );

        encClosure = new MethodClosure(this,"encodeJSON");
        for ( String ct : ContentType.JSON.getContentTypeStrings() )
            encoders.put( ct, encClosure );

        return encoders;
    }
View Full Code Here

     * @return the default response handler map.
     */
    protected Map<Object,Closure> buildDefaultResponseHandlers() {
        Map<Object,Closure> map = new StringHashMap<Closure>();
        map.put( Status.SUCCESS,
                new MethodClosure(this,"defaultSuccessHandler"));
        map.putStatus.FAILURE,
                new MethodClosure(this,"defaultFailureHandler"));

        return map;
    }
View Full Code Here

            Script scriptObject = InvokerHelper.createScript(scriptClass, binding);
            Method methods[] = scriptClass.getMethods();
            Map<String, MethodClosure> closures = new HashMap<String, MethodClosure>();
            for (Method m : methods) {
                String name = m.getName();
                closures.put(name, new MethodClosure(scriptObject, name));
            }

            globalClosures.putAll(closures);
            final MetaClass oldMetaClass = scriptObject.getMetaClass();
            scriptObject.setMetaClass(new DelegatingMetaClass(oldMetaClass) {
View Full Code Here

  }

  private Project loadProject(String projectPath, BuildParameters params) {
    final Project project = new Project();
    // setup JDKs and global libraries
    final MethodClosure fakeClosure = new MethodClosure(new Object(), "hashCode");
    for (GlobalLibrary library : myGlobalLibraries) {
      if (library instanceof SdkLibrary) {
        final SdkLibrary sdk = (SdkLibrary)library;
        final JavaSdk jdk = project.createJavaSdk(sdk.getName(), sdk.getHomePath(), fakeClosure);
        jdk.setClasspath(sdk.getPaths());
View Full Code Here

     * </ul>
     */
    protected Map<String,Closure> buildDefaultParserMap() {
        Map<String,Closure> parsers = new HashMap<String,Closure>();

        parsers.put( ContentType.BINARY.toString(), new MethodClosure( this, "parseStream" ) );
        parsers.put( ContentType.TEXT.toString(), new MethodClosure(this,"parseText") );
        parsers.put( ContentType.URLENC.toString(), new MethodClosure(this,"parseForm") );
        parsers.put( ContentType.HTML.toString(), new MethodClosure(this,"parseHTML") );

        Closure pClosure = new MethodClosure(this,"parseXML");
        for ( String ct : ContentType.XML.getContentTypeStrings() )
            parsers.put( ct, pClosure );

        pClosure = new MethodClosure(this,"parseJSON");
        for ( String ct : ContentType.JSON.getContentTypeStrings() )
            parsers.put( ct, pClosure );

        return parsers;
    }
View Full Code Here

        } catch (Throwable t) {
            t.printStackTrace();
        }

        // bind forward method
        MethodClosure c = new MethodClosure(this, "forward");
        super.setVariable("forward", c);
       
        // bind include method
        c = new MethodClosure(this, "include");
        super.setVariable("include", c);
       
        // bind redirect method
        c = new MethodClosure(this, "redirect");
        super.setVariable("redirect", c);
    }
View Full Code Here

TOP

Related Classes of org.codehaus.groovy.runtime.MethodClosure

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.