Package org.apache.tapestry.ioc.services

Examples of org.apache.tapestry.ioc.services.ClassFab


        return serviceInterface.cast(interceptor);
    }

    private Class createInterceptorClass(Class serviceInterface, String serviceId)
    {
        ClassFab cf = _classFactory.newClass(serviceInterface);

        cf.addField("_delegate", serviceInterface);
        cf.addField("_logger", ServiceLogger.class);

        cf.addConstructor(new Class[]
        { serviceInterface, ServiceLogger.class }, null, "{ _delegate = $1; _logger = $2; }");

        addMethods(cf, serviceInterface, serviceId);

        return cf.createClass();
    }
View Full Code Here


    }

    private Class createProxyClass(String serviceId, Class serviceInterface, boolean eagerLoad,
            String proxyDescription)
    {
        ClassFab cf = _registry.newClass(serviceInterface);

        cf.addField("_creator", ObjectCreator.class);
        cf.addField("_delegate", serviceInterface);
        cf.addField("_shutdown", boolean.class);

        cf.addConstructor(new Class[]
        { ObjectCreator.class }, null, "_creator = $1;");

        addDelegateGetter(cf, serviceInterface, serviceId);

        addShutdownListenerMethod(cf);

        cf.proxyMethodsToDelegate(serviceInterface, "_delegate()", proxyDescription);

        // For eager load services, add an eagerLoadService() method that calls _delegate(), to
        // force the creation of the service.

        if (eagerLoad)
        {
            cf.addInterface(EagerLoadServiceProxy.class);

            cf.addMethod(Modifier.PUBLIC, new MethodSignature(void.class, "eagerLoadService", null,
                    null), "_delegate();");
        }

        return cf.createClass();
    }
View Full Code Here

    }

    @SuppressWarnings("unchecked")
    private <S> Class<S> createClass(Class<S> serviceInterface)
    {
        ClassFab cf = _classFactory.newClass(serviceInterface);

        MethodIterator mi = new MethodIterator(serviceInterface);

        while (mi.hasNext())
        {
            MethodSignature sig = mi.next();

            cf.addNoOpMethod(sig);
        }

        if (!mi.getToString())
            cf.addToString(format("<NoOp %s>", serviceInterface.getName()));

        return cf.createClass();
    }
View Full Code Here

    public ClassFab newClass(Class serviceInterface)
    {
        String name = ClassFabUtils.generateClassName(serviceInterface);

        ClassFab cf = newClass(name, Object.class);

        cf.addInterface(serviceInterface);

        return cf;
    }
View Full Code Here

        // for the same interface may occur. We just let that happen, and there'll
        // be two different classes corresponding to the same interface.

        String name = ClassFabUtils.generateClassName(commandInterface);

        ClassFab cf = _classFactory.newClass(name, Object.class);

        addInfrastructure(cf, commandInterface);

        addMethods(cf, commandInterface);

        return cf.createClass();
    }
View Full Code Here

    public void new_class_with_name_and_base_class() throws Exception
    {
        ClassFactory factory = new ClassFactoryImpl();
        String name = ClassFabUtils.generateClassName(Runnable.class);

        ClassFab cf = factory.newClass(name, Object.class);
        cf.addInterface(Runnable.class);

        addRunMethod(cf);

        Class newClass = cf.createClass();

        Runnable instance = (Runnable) newClass.newInstance();

        instance.run();
    }
View Full Code Here

    public void new_class_with_non_object_base_class() throws Exception
    {
        ClassFactory factory = new ClassFactoryImpl();
        String name = ClassFabUtils.generateClassName(Runnable.class);

        ClassFab cf = factory.newClass(name, BaseClass.class);
        cf.addInterface(Runnable.class);

        Class newClass = cf.createClass();

        Runnable instance = (Runnable) newClass.newInstance();

        instance.run();
    }
View Full Code Here

    @Test
    public void new_class_with_interface() throws Exception
    {
        ClassFactory factory = new ClassFactoryImpl();

        ClassFab cf = factory.newClass(Runnable.class);

        addRunMethod(cf);

        Class newClass = cf.createClass();

        Runnable instance = (Runnable) newClass.newInstance();

        instance.run();
    }
View Full Code Here

        ClassFactory factory = new ClassFactoryImpl();

        Class clazz = SimpleBean.class;

        ClassFab cf = factory.newClass(clazz.getName() + "$$Proxy", clazz);

        cf.addInterface(Serializable.class);

        Class proxyClass = cf.createClass();

        SimpleBean simple = (SimpleBean) proxyClass.newInstance();

        assertTrue(simple instanceof Serializable);
View Full Code Here

    }

    @Test
    public void create_simple_bean() throws Exception
    {
        ClassFab cf = newClassFab("TargetBean", Object.class);

        cf.addField("_stringValue", String.class);

        MethodSignature setStringValue = new MethodSignature(void.class, "setStringValue",
                new Class[]
                { String.class }, null);

        cf.addMethod(Modifier.PUBLIC, setStringValue, "_stringValue = $1;");

        MethodSignature getStringValue = new MethodSignature(String.class, "getStringValue", null,
                null);

        cf.addMethod(Modifier.PUBLIC, getStringValue, "return _stringValue;");

        Class targetClass = cf.createClass();

        Object targetBean = targetClass.newInstance();

        _access.set(targetBean, "stringValue", "Fred");
View Full Code Here

TOP

Related Classes of org.apache.tapestry.ioc.services.ClassFab

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.