Examples of PropertyAdapter


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

    }

    @Test
    public void access_to_public_field()
    {
        PropertyAdapter pa = access.getAdapter(PublicFieldBean.class).getPropertyAdapter("value");

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

        PublicFieldBean bean = new PublicFieldBean();

        pa.set(bean, "fred");

        assertEquals(bean.value, "fred");

        bean.value = "barney";

        assertEquals(pa.get(bean), "barney");
    }
View Full Code Here

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

    }

    @Test
    public void property_is_favored_over_public_field()
    {
        PropertyAdapter pa = access.getAdapter(ShadowedPublicFieldBean.class).getPropertyAdapter("value");

        assertFalse(pa.isField());

        ShadowedPublicFieldBean bean = new ShadowedPublicFieldBean();

        pa.set(bean, "fred");

        assertNull(bean.value);

        bean.value = "barney";
        bean.setValue("wilma");

        assertEquals(pa.get(bean), "wilma");
    }
View Full Code Here

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

    }

    @Test
    public void generic_field_is_recognized()
    {
        PropertyAdapter pa = access.getAdapter(GenericStringBean.class).getPropertyAdapter("value");

        assertTrue(pa.isCastRequired());
        assertEquals(pa.getType(), String.class);
        assertSame(pa.getDeclaringClass(), GenericBean.class);
    }
View Full Code Here

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

            Method readMethod = pd.getReadMethod();

            Class propertyType = readMethod == null ? pd.getPropertyType() : GenericsUtils.extractGenericReturnType(
                    beanType, readMethod);

            PropertyAdapter pa = new PropertyAdapterImpl(this, pd.getName(), propertyType, readMethod, pd
                    .getWriteMethod());

            adapters.put(pa.getName(), pa);
        }

        // Now, add any public fields (even if static) that do not conflict

        for (Field f : beanType.getFields())
        {
            String name = f.getName();

            if (!adapters.containsKey(name))
            {
                Class propertyType = GenericsUtils.extractGenericFieldType(beanType, f);
                PropertyAdapter pa = new PropertyAdapterImpl(this, name, propertyType, f);

                adapters.put(name, pa);
            }
        }
    }
View Full Code Here

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

        adaptorFor(propertyName).set(instance, value);
    }

    private PropertyAdapter adaptorFor(String name)
    {
        PropertyAdapter pa = adapters.get(name);

        if (pa == null)
            throw new IllegalArgumentException(ServiceMessages.noSuchProperty(beanType, name));

        return pa;
View Full Code Here

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

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

    {
        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

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

        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

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

    @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

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

    @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
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.