Package org.apache.tapestry.ioc.services

Examples of org.apache.tapestry.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(_targetClass, name));

        return pa;
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 property_adapter_read_only_property()
    {
        ClassPropertyAdapter cpa = _access.getAdapter(Bean.class);
        PropertyAdapter pa = cpa.getPropertyAdapter("readOnly");

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

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

    private Method writeMethodForTerm(Class activeType, String expression, String term)
    {
        if (term.endsWith(PARENS)) return null;

        ClassPropertyAdapter classAdapter = _access.getAdapter(activeType);
        PropertyAdapter adapter = classAdapter.getPropertyAdapter(term);

        if (adapter == null)
            throw new RuntimeException(ServicesMessages.noSuchProperty(
                    activeType,
                    term,
                    expression,
                    classAdapter.getPropertyNames()));

        return adapter.getWriteMethod();
    }
View Full Code Here

            return method;
        }

        ClassPropertyAdapter classAdapter = _access.getAdapter(activeType);
        PropertyAdapter adapter = classAdapter.getPropertyAdapter(term);

        if (adapter == null)
            throw new RuntimeException(ServicesMessages.noSuchProperty(
                    activeType,
                    term,
                    expression,
                    classAdapter.getPropertyNames()));

        Method m = adapter.getReadMethod();

        if (m == null && mustExist)
            throw new RuntimeException(ServicesMessages.writeOnlyProperty(
                    term,
                    activeType,
View Full Code Here

    }

    public <T> T build(Object source, String propertyName, Class<T> propertyType)
    {
        Class sourceClass = source.getClass();
        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));

        ClassFab cf = _classFactory.newClass(propertyType);

        cf.addField("_source", Modifier.PRIVATE | Modifier.FINAL, sourceClass);

        cf.addConstructor(new Class[]
        { sourceClass }, null, "_source = $1;");

        String body = format("return _source.%s();", adapter.getReadMethod().getName());

        MethodSignature sig = new MethodSignature(propertyType, "_delegate", null, null);
        cf.addMethod(Modifier.PRIVATE, sig, body);

        String toString = format("<Shadow: property %s of %s>", propertyName, source);
View Full Code Here

        Map<String, Runnable> worksheet = newMap();

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

            if (!pa.isRead()) continue;

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

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

            final String dataType = _dataTypeAnalyzer.identifyDataType(pa);

            // If an unregistered type, then ignore the property.
View Full Code Here

        List<PropertyOrder> properties = newList();

        for (String name : propertyNames)
        {

            PropertyAdapter pa = classAdapter.getPropertyAdapter(name);
            List<String> propertyConstraints = CollectionFactory.newList();

            OrderBefore beforeAnnotation = pa.getAnnotation(OrderBefore.class);

            if (beforeAnnotation != null)
                propertyConstraints.add("before:" + beforeAnnotation.value());

            OrderAfter afterAnnotation = pa.getAnnotation(OrderAfter.class);

            if (afterAnnotation != null)
                propertyConstraints.add("after:" + afterAnnotation.value());

            if (!propertyConstraints.isEmpty()) constraints.put(name, propertyConstraints);

            Method readMethod = pa.getReadMethod();

            Location location = classFactory.getMethodLocation(readMethod);

            properties.add(new PropertyOrder(name, computeDepth(readMethod), location.getLine()));
        }
View Full Code Here

        List<String> propertyNames = newList();

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

            if (!pa.isRead())
                continue;

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

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

            String dataType = _dataTypeAnalyzer.identifyDataType(pa);

            // If an unregistered type, then ignore the property.
View Full Code Here

        List<PropertyOrder> properties = newList();

        for (String name : propertyNames)
        {

            PropertyAdapter pa = classAdapter.getPropertyAdapter(name);
            List<String> propertyConstraints = CollectionFactory.newList();

            OrderBefore beforeAnnotation = pa.getAnnotation(OrderBefore.class);

            if (beforeAnnotation != null) propertyConstraints.add("before:" + beforeAnnotation.value());

            OrderAfter afterAnnotation = pa.getAnnotation(OrderAfter.class);

            if (afterAnnotation != null) propertyConstraints.add("after:" + afterAnnotation.value());

            if (!propertyConstraints.isEmpty()) constraints.put(name, propertyConstraints);

            Method readMethod = pa.getReadMethod();

            Location location = classFactory.getMethodLocation(readMethod);

            properties.add(new PropertyOrder(name, computeDepth(readMethod), location.getLine()));
        }
View Full Code Here

TOP

Related Classes of org.apache.tapestry.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.