Package java.beans

Examples of java.beans.IndexedPropertyDescriptor


    {
      return typeFromDescriptor;
    }
    if (pd instanceof IndexedPropertyDescriptor)
    {
      final IndexedPropertyDescriptor idx = (IndexedPropertyDescriptor) pd;
      return idx.getIndexedPropertyType();
    }
    throw new BeanException("Unable to determine the property type.");
  }
View Full Code Here


        for (PropertyDescriptor element : propertyDesc) {
            if (element.getName().equals("class")) {
                assertNull(element.getWriteMethod());
                assertNotNull(element.getReadMethod());
            } else {
                IndexedPropertyDescriptor indexedDesc =
                        (IndexedPropertyDescriptor) element;
               
                assertEquals("fox501", element.getName());
                assertEquals(String[].class.getName(), element
                        .getPropertyType().getName());
                assertNotNull(element.getWriteMethod());
                assertNotNull(element.getReadMethod());
                assertNotNull(indexedDesc.getIndexedReadMethod());
                assertNull(indexedDesc.getIndexedWriteMethod());
                assertEquals(String.class.getName(), indexedDesc
                        .getIndexedPropertyType().getName());
            }
        }
    }
View Full Code Here

        for (PropertyDescriptor element : propertyDesc) {
            if (element.getName().equals("class")) {
                assertNull(element.getWriteMethod());
                assertNotNull(element.getReadMethod());
            } else {
                IndexedPropertyDescriptor indexedDesc = (IndexedPropertyDescriptor) element;
                assertEquals("fox501", element.getName());
                assertEquals(String[].class.getName(), element
                        .getPropertyType().getName());
                assertNull(element.getWriteMethod());
                assertNotNull(element.getReadMethod());
                assertNull(indexedDesc.getIndexedReadMethod());
                assertNotNull(indexedDesc.getIndexedWriteMethod());
                assertEquals(String.class.getName(), indexedDesc
                        .getIndexedPropertyType().getName());
            }
        }
    }
View Full Code Here

        for (PropertyDescriptor element : propertyDesc) {
            if (element.getName().equals("class")) {
                assertNull(element.getWriteMethod());
                assertNotNull(element.getReadMethod());
            } else {
                IndexedPropertyDescriptor indexedDesc = (IndexedPropertyDescriptor) element;
                assertEquals("fox501", element.getName());
                assertNull(element.getPropertyType());
                assertNull(element.getWriteMethod());
                assertNull(element.getReadMethod());
                assertNull(indexedDesc.getIndexedReadMethod());
                assertNotNull(indexedDesc.getIndexedWriteMethod());
                assertEquals(Integer.class.getName(), indexedDesc
                        .getIndexedPropertyType().getName());
            }
        }
    }
View Full Code Here

        for (PropertyDescriptor element : pds) {
            if (element.getName().equals("class")) {
                assertNull(element.getWriteMethod());
                assertNotNull(element.getReadMethod());
            } else {
                IndexedPropertyDescriptor indexedDesc =
                        (IndexedPropertyDescriptor) element;
               
                assertEquals("fox401", element.getName());
                assertEquals(String[].class.getName(), element
                        .getPropertyType().getName());
                assertEquals(String.class.getName(), indexedDesc
                        .getIndexedPropertyType().getName());
                assertNotNull(element.getWriteMethod());
                assertNotNull(element.getReadMethod());
                assertNotNull(indexedDesc.getIndexedReadMethod());
                assertNotNull(indexedDesc.getIndexedWriteMethod());
            }
        }
    }
View Full Code Here

    public static Object getValue(Object bean,
            PropertyDescriptor propertyDescriptor, int index){
        if (propertyDescriptor instanceof IndexedPropertyDescriptor){
            Object value;
            try {
                IndexedPropertyDescriptor ipd =
                    (IndexedPropertyDescriptor)propertyDescriptor;
                Method method = ipd.getIndexedReadMethod();
                if (method != null){
                    return method.invoke(bean, new Object[]{new Integer(index)});
                }
            }
            catch (Exception ex){
View Full Code Here

     */
    public static void setValue(Object bean,
              PropertyDescriptor propertyDescriptor, int index, Object value){
        if (propertyDescriptor instanceof IndexedPropertyDescriptor){
            try {
                IndexedPropertyDescriptor ipd =
                      (IndexedPropertyDescriptor)propertyDescriptor;
                Method method = ipd.getIndexedWriteMethod();
                if (method != null){
                    method.invoke(bean,
                        new Object[]{new Integer(index),
                                     convert(value, ipd.getIndexedPropertyType())});
                    return;
                }
            }
            catch (Exception ex){
                throw new RuntimeException("Cannot access property: " +
View Full Code Here

        //     JDK 1.3.1_04: returns valid Method objects from these methods.
        //     JDK 1.4.2_05: returns null from these methods.
        //
        for (int i = 0; i < descriptors.length; i++) {
            if (descriptors[i] instanceof IndexedPropertyDescriptor) {
                IndexedPropertyDescriptor descriptor =  (IndexedPropertyDescriptor)descriptors[i];
                String propName = descriptor.getName().substring(0, 1).toUpperCase() +
                                  descriptor.getName().substring(1);

                if (descriptor.getReadMethod() == null) {
                    String methodName = descriptor.getIndexedReadMethod() != null
                                        ? descriptor.getIndexedReadMethod().getName()
                                        : "get" + propName;
                    Method readMethod = MethodUtils.getMatchingAccessibleMethod(beanClass,
                                                            methodName,
                                                            EMPTY_CLASS_PARAMETERS);
                    if (readMethod != null) {
                        try {
                            descriptor.setReadMethod(readMethod);
                        } catch(Exception e) {
                            log.error("Error setting indexed property read method", e);
                        }
                    }
                }
                if (descriptor.getWriteMethod() == null) {
                    String methodName = descriptor.getIndexedWriteMethod() != null
                                      ? descriptor.getIndexedWriteMethod().getName()
                                      : "set" + propName;
                    Method writeMethod = MethodUtils.getMatchingAccessibleMethod(beanClass,
                                                            methodName,
                                                            LIST_CLASS_PARAMETER);
                    if (writeMethod == null) {
                        Method[] methods = beanClass.getMethods();
                        for (int j = 0; j < methods.length; j++) {
                            if (methods[j].getName().equals(methodName)) {
                                Class[] parameterTypes = methods[j].getParameterTypes();
                                if (parameterTypes.length == 1 &&
                                    List.class.isAssignableFrom(parameterTypes[0])) {
                                    writeMethod = methods[j];
                                    break;
                                }
                            }
                        }
                    }
                    if (writeMethod != null) {
                        try {
                            descriptor.setWriteMethod(writeMethod);
                        } catch(Exception e) {
                            log.error("Error setting indexed property write method", e);
                        }
                    }
                }
View Full Code Here

     * Test Read Method for an Array
     */
    public void testArrayReadMethod() {

        try {
            IndexedPropertyDescriptor descriptor =
                 (IndexedPropertyDescriptor)propertyUtilsBean.getPropertyDescriptor(bean, "stringArray");
            assertNotNull("No Array Read Method", descriptor.getReadMethod());
        } catch(Exception e) {
            fail("Threw exception " + e);
        }
    }
View Full Code Here

     * Test Write Method for an Array
     */
    public void testArrayWriteMethod() {

        try {
            IndexedPropertyDescriptor descriptor =
                 (IndexedPropertyDescriptor)propertyUtilsBean.getPropertyDescriptor(bean, "stringArray");
            assertNotNull("No Array Write Method", descriptor.getWriteMethod());
        } catch(Exception e) {
            fail("Threw exception " + e);
        }
    }
View Full Code Here

TOP

Related Classes of java.beans.IndexedPropertyDescriptor

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.