Package org.apache.tapestry5.ioc.services

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


    }

    public <T> T build(final Object source, final String propertyName, final Class<T> propertyType)
    {
        final Class sourceClass = source.getClass();
        final PropertyAdapter adapter = propertyAccess.getAdapter(sourceClass).getPropertyAdapter(propertyName);

        // TODO: Perhaps extend ClassPropertyAdapter to do these checks?

        if (adapter == null)
            throw new RuntimeException(ServiceMessages.noSuchProperty(sourceClass, propertyName));

        if (!adapter.isRead())
            throw new RuntimeException(ServiceMessages.readNotSupported(source, propertyName));

        if (!propertyType.isAssignableFrom(adapter.getType()))
            throw new RuntimeException(ServiceMessages.propertyTypeMismatch(propertyName, sourceClass,
                    adapter.getType(), propertyType));

        ClassInstantiator instantiator = proxyFactory.createProxy(propertyType, new PlasticClassTransformer()
        {
            public void transform(PlasticClass plasticClass)
            {
                final PlasticField sourceField = plasticClass.introduceField(sourceClass, "source").inject(source);

                PlasticMethod delegateMethod = plasticClass.introducePrivateMethod(propertyType.getName(),
                        "readProperty", null, null);

                // You don't do this using MethodAdvice, because then we'd have to use reflection to access the read
                // method.

                delegateMethod.changeImplementation(new InstructionBuilderCallback()
                {
                    public void doBuild(InstructionBuilder builder)
                    {
                        builder.loadThis().getField(sourceField);
                        builder.invoke(sourceClass, propertyType, adapter.getReadMethod().getName());

                        // Now add the null check.

                        builder.dupe().when(Condition.NULL, new InstructionBuilderCallback()
                        {
View Full Code Here


    {
        List<PropertyOrder> properties = CollectionFactory.newList();

        for (String name : propertyNames)
        {
            PropertyAdapter pa = classAdapter.getPropertyAdapter(name);

            Method readMethod = pa.getReadMethod();

            Location location = readMethod == null ? null : classFactory.getMethodLocation(readMethod);

            int line = location == null ? -1 : location.getLine();
View Full Code Here

        BeanModel<T> model = new BeanModelImpl<T>(beanClass, propertyConduitSource, typeCoercer, messages, locator);

        for (final String propertyName : adapter.getPropertyNames())
        {
            PropertyAdapter pa = adapter.getPropertyAdapter(propertyName);

            if (!pa.isRead())
            {
                continue;
            }

            if (isStaticFieldProperty(pa))
            {
                continue;
            }

            if (pa.getAnnotation(NonVisual.class) != null)
            {
                continue;
            }

            if (filterReadOnlyProperties && !pa.isUpdate())
            {
                continue;
            }

            final String dataType = dataTypeAnalyzer.identifyDataType(pa);
View Full Code Here

    @Test
    public void property_adapter_read_only_property()
    {
        ClassPropertyAdapter cpa = access.getAdapter(Bean.class);
        PropertyAdapter pa = cpa.getPropertyAdapter("readOnly");

        assertTrue(pa.isRead());
        assertFalse(pa.isUpdate());
        assertFalse(pa.isCastRequired());

        assertNull(pa.getWriteMethod());
        assertEquals(pa.getReadMethod(), findMethod(Bean.class, "getReadOnly"));
    }
View Full Code Here

    @Test
    public void property_adapter_write_only_property()
    {
        ClassPropertyAdapter cpa = access.getAdapter(Bean.class);
        PropertyAdapter pa = cpa.getPropertyAdapter("writeOnly");

        assertFalse(pa.isRead());
        assertTrue(pa.isUpdate());

        assertEquals(pa.getWriteMethod(), findMethod(Bean.class, "setWriteOnly"));
        assertNull(pa.getReadMethod());
    }
View Full Code Here

    }

    @Test
    public void read_static_field()
    {
        PropertyAdapter adapter = access.getAdapter(Bean.class).getPropertyAdapter("pi");

        assertSame(adapter.get(null), Bean.PI);
    }
View Full Code Here

    }

    @Test
    public void static_final_fields_may_not_be_changed()
    {
        PropertyAdapter adapter = access.getAdapter(Bean.class).getPropertyAdapter("pi");

        try
        {
            adapter.set(null, 3.0d);
            unreachable();
        } catch (RuntimeException ex)
        {
            // The exact text varies from JDK to JDK
            assertMessageContains(ex, "final", "PI");
View Full Code Here

    }

    @Test
    public void get_annotation_when_annotation_not_present()
    {
        PropertyAdapter pa = access.getAdapter(AnnotatedBean.class).getPropertyAdapter("readWrite");

        assertNull(pa.getAnnotation(Scope.class));
    }
View Full Code Here

    }

    @Test
    public void get_annotation_with_annotation_on_write_method()
    {
        PropertyAdapter pa = access.getAdapter(AnnotatedBean.class).getPropertyAdapter("annotationOnWrite");

        Scope annotation = pa.getAnnotation(Scope.class);
        assertNotNull(annotation);

        assertEquals(annotation.value(), "onwrite");
    }
View Full Code Here

    }

    @Test
    public void read_method_annotation_overrides_write_method_annotation()
    {
        PropertyAdapter pa = access.getAdapter(AnnotatedBean.class).getPropertyAdapter("annotationOnRead");

        Scope annotation = pa.getAnnotation(Scope.class);
        assertNotNull(annotation);

        assertEquals(annotation.value(), "onread");
    }
View Full Code Here

TOP

Related Classes of org.apache.tapestry5.ioc.services.PropertyAdapter

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.