Examples of ClassFab


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

        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

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

            // The access object is created in the same package as the component, so that it can access
            // protected and package private methods.
            String accessClassName = String.format("%s$MethodAccess_%s_%s", getClassName(), sig.getMethodName(),
                    ClassFabUtils.nextUID());

            ClassFab cf = classFactory.newClass(accessClassName, AbstractMethodAccess.class);

            cf.addMethod(Modifier.PUBLIC, INVOKE_SIGNATURE, body);

            cf.addToString(String.format("MethodAccess[method %s of class %s]", sig.getMediumDescription(),
                    getClassName()));

            Class accessClass = cf.createClass();

            try
            {
                Object accessInstance = accessClass.newInstance();
View Full Code Here

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

        }

        private org.apache.tapestry5.services.FieldAccess createFieldAccess(TransformMethod reader,
                TransformMethod writer)
        {
            ClassFab cf = classFactory.newClass(org.apache.tapestry5.services.FieldAccess.class);

            addFieldAccessReadMethod(cf, reader);
            addFieldAccessWriteMethod(cf, writer);

            cf.addToString(String.format("FieldAccess<%s.%s>", getClassName(), name));

            Class accessClass = cf.createClass();

            try
            {
                return (org.apache.tapestry5.services.FieldAccess) accessClass.newInstance();
            }
View Full Code Here

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

        String componentClassName = getClassName();

        String name = ClassFabUtils.generateClassName("Instantiator");

        ClassFab cf = classFactory.newClass(name, AbstractInstantiator.class);

        Object[] componentConstructorArgs = constructorArgs.toArray(new Object[constructorArgs.size()]);

        cf.addConstructor(new Class[]
        { ComponentModel.class, String.class, Object[].class }, null, "super($1, $2, $3);");

        // Pass $1 (the InternalComponentResources object) and the constructorArgs (from the AbstractIntantiator
        // base class) into the new component instance's constructor

        cf.addMethod(Modifier.PUBLIC, NEW_INSTANCE_SIGNATURE,
                String.format("return new %s($1, constructorArgs);", componentClassName));

        Class instantiatorClass = cf.createClass();

        try
        {
            Object instance = instantiatorClass.getConstructors()[0].newInstance(componentModel,
                    String.format("Instantiator[%s]", componentClassName), componentConstructorArgs);
View Full Code Here

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

    }

    @Test
    public void add_constructor_from_base_class() throws Exception
    {
        ClassFab cf = newClassFab("MyIntHolder", AbstractIntWrapper.class);

        cf.addField("_intValue", int.class);
        cf.addConstructor(new Class[] { int.class }, null, "{ _intValue = $1; }");

        cf.addMethod(Modifier.PUBLIC, new MethodSignature(int.class, "getIntValue", null, null), "return _intValue;");

        Class targetClass = cf.createClass();
        Constructor c = targetClass.getConstructors()[0];

        AbstractIntWrapper targetBean = (AbstractIntWrapper) c.newInstance(new Object[] { new Integer(137) });

        assertEquals(targetBean.getIntValue(), 137);
View Full Code Here

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

    }

    @Test
    public void invalid_super_class() throws Exception
    {
        ClassFab cf = newClassFab("InvalidSuperClass", List.class);

        try
        {
            cf.createClass();
            unreachable();
        }
        catch (RuntimeException ex)
        {
            assertExceptionSubstring(ex, "Unable to create class InvalidSuperClass");
View Full Code Here

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

    }

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

        cf.addInterface(SimpleService.class);

        cf.addMethod(Modifier.PUBLIC, new MethodSignature(int.class, "add", new Class[] { int.class, int.class }, null),
                     "return $1 + $2;");

        Class targetClass = cf.createClass();

        SimpleService s = (SimpleService) targetClass.newInstance();

        assertEquals(207, s.add(99, 108));
    }
View Full Code Here

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

    }

    @Test
    public void attempt_to_subclass_from_final_class() throws Exception
    {
        ClassFab cf = newClassFab("StringSubclass", String.class);

        try
        {
            cf.createClass();
        }
        catch (RuntimeException ex)
        {
            assertExceptionRegexp(ex, "Unable to create class StringSubclass\\: .*");
        }
View Full Code Here

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

    }

    @Test
    public void create_class_within_non_default_package() throws Exception
    {
        ClassFab cf = newClassFab("org.apache.hivemind.InPackage", Object.class);

        Class c = cf.createClass();

        Object o = c.newInstance();

        assertEquals("org.apache.hivemind.InPackage", o.getClass().getName());
    }
View Full Code Here

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

    }

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

        cf.addInterface(Runnable.class);

        try
        {
            cf.addMethod(Modifier.PUBLIC, new MethodSignature(void.class, "run", null, null), "fail;");
        }
        catch (RuntimeException ex)
        {
            assertExceptionSubstring(ex, "Unable to add method void run() to class BadMethodBody:");
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.