public ClassPropertyAdapterImpl()

in beanmodel/src/main/java/org/apache/tapestry5/beanmodel/internal/services/ClassPropertyAdapterImpl.java [39:145]


    public ClassPropertyAdapterImpl(Class beanType, List<PropertyDescriptor> descriptors)
    {
        this.beanType = beanType;

        // lazy init
        Map<String, List<Method>> nonBridgeMethods = null;

        for (PropertyDescriptor pd : descriptors)
        {
            // Indexed properties will have a null propertyType (and a non-null
            // indexedPropertyType). We ignore indexed properties.

            String name = pd.getName();

            if (adapters.containsKey(name))
            {
                continue;
            }

            final Class<?> thisPropertyType = pd.getPropertyType();
            if (thisPropertyType == null)
                continue;

            Method readMethod = pd.getReadMethod();
            Method writeMethod = pd.getWriteMethod();

            // TAP5-1493
            if (readMethod != null && readMethod.isBridge())
            {
                if (nonBridgeMethods == null)
                {
                    nonBridgeMethods = groupNonBridgeMethodsByName(beanType);
                }
                readMethod = findMethodWithSameNameAndParamCount(readMethod, nonBridgeMethods);
            }

            // TAP5-1548, TAP5-1885: trying to find a getter which Introspector missed
            if (readMethod == null) {
                final String prefix = thisPropertyType != boolean.class ? "get" : "is";
                try
                {
                    Method method = beanType.getMethod(prefix + capitalize(name));
                    final Class<?> returnType = method.getReturnType();
                    if (returnType.equals(thisPropertyType) || returnType.isInstance(thisPropertyType)) {
                        readMethod = method;
                    }
                }
                catch (SecurityException e) {
                    // getter not usable.
                }
                catch (NoSuchMethodException e)
                {
                    // getter doesn't exist.
                }
            }

            if (writeMethod != null && writeMethod.isBridge())
            {
                if (nonBridgeMethods == null)
                {
                    nonBridgeMethods = groupNonBridgeMethodsByName(beanType);
                }
                writeMethod = findMethodWithSameNameAndParamCount(writeMethod, nonBridgeMethods);
            }

            // TAP5-1548, TAP5-1885: trying to find a setter which Introspector missed
            if (writeMethod == null) {
                try
                {
                    Method method = beanType.getMethod("set" + capitalize(name), pd.getPropertyType());
                    final Class<?> returnType = method.getReturnType();
                    if (returnType.equals(void.class)) {
                        writeMethod = method;
                    }
                }
                catch (SecurityException e) {
                    // setter not usable.
                }
                catch (NoSuchMethodException e)
                {
                    // setter doesn't exist.
                }
            }

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

            PropertyAdapter pa = new PropertyAdapterImpl(this, name, propertyType, readMethod, writeMethod);

            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);
            }
        }
    }