Package org.apache.tapestry5.ioc.services

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


     * TAPESTRY-2448
     */
    @Test
    public void get_annotation_will_read_inherited_field()
    {
        PropertyAdapter pa = access.getAdapter(BeanSubclass.class).getPropertyAdapter("value");

        DataType dt = pa.getAnnotation(DataType.class);

        assertNotNull(dt);
        assertEquals(dt.value(), "fred");

    }
View Full Code Here


    }

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

        assertEquals(pa.getAnnotation(Validate.class).value(), "getter-value-overrides");
    }
View Full Code Here

    @Test
    public void using_generics()
    {
        ClassPropertyAdapter cpa1 = access.getAdapter(StringLongPair.class);

        PropertyAdapter pa1 = cpa1.getPropertyAdapter("key");
        assertSame(pa1.getType(), String.class);
        assertTrue(pa1.isCastRequired());

        assertSame(pa1.getDeclaringClass(), Pair.class);

        PropertyAdapter pa2 = cpa1.getPropertyAdapter("value");
        assertSame(pa2.getType(), Long.class);
        assertTrue(pa2.isCastRequired());

        // On the base class, which defines the generic parameter type variables,
        // the properties just look like Object.

        ClassPropertyAdapter cpa2 = access.getAdapter(Pair.class);

        pa1 = cpa2.getPropertyAdapter("key");
        assertSame(pa1.getType(), Object.class);
        assertFalse(pa1.isCastRequired());

        pa2 = cpa2.getPropertyAdapter("value");
        assertSame(pa2.getType(), Object.class);
        assertFalse(pa2.isCastRequired());

    }
View Full Code Here

    }

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

        // even thought scala accessors are present the java bean ones should be the ones used by Tapestry
        assertEquals(pa.getReadMethod().getName(), "getValue");
        assertEquals(pa.getWriteMethod().getName(), "setValue");
    }
View Full Code Here

    }

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

        assertEquals(pa.getReadMethod().getName(), "value");
        assertEquals(pa.getWriteMethod().getName(), "value_$eq");
    }
View Full Code Here

    }

    @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

    }

    @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

    }

    @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

            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

        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

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.