Search in sources :

Example 56 with IntrospectionException

use of java.beans.IntrospectionException in project Openfire by igniterealtime.

the class JiveBeanInfo method getPropertyDescriptors.

@Override
public PropertyDescriptor[] getPropertyDescriptors() {
    Class beanClass = getBeanClass();
    String[] properties = getPropertyNames();
    PropertyDescriptor[] descriptors = new PropertyDescriptor[properties.length];
    try {
        // name and description using the localized data.
        for (int i = 0; i < descriptors.length; i++) {
            PropertyDescriptor newDescriptor = new PropertyDescriptor(properties[i], beanClass);
            if (bundle != null) {
                newDescriptor.setDisplayName(bundle.getString(properties[i] + ".displayName"));
                newDescriptor.setShortDescription(bundle.getString(properties[i] + ".shortDescription"));
            }
            descriptors[i] = newDescriptor;
        }
        return descriptors;
    } catch (IntrospectionException ie) {
        Log.error(ie.getMessage(), ie);
        throw new Error(ie.toString());
    }
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) IntrospectionException(java.beans.IntrospectionException)

Example 57 with IntrospectionException

use of java.beans.IntrospectionException in project tomcat by apache.

the class BeanELResolver method getFeatureDescriptors.

@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
    if (base == null) {
        return null;
    }
    try {
        BeanInfo info = Introspector.getBeanInfo(base.getClass());
        PropertyDescriptor[] pds = info.getPropertyDescriptors();
        for (int i = 0; i < pds.length; i++) {
            pds[i].setValue(RESOLVABLE_AT_DESIGN_TIME, Boolean.TRUE);
            pds[i].setValue(TYPE, pds[i].getPropertyType());
        }
        return Arrays.asList((FeatureDescriptor[]) pds).iterator();
    } catch (IntrospectionException e) {
    //
    }
    return null;
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) BeanInfo(java.beans.BeanInfo) IntrospectionException(java.beans.IntrospectionException)

Example 58 with IntrospectionException

use of java.beans.IntrospectionException in project Openfire by igniterealtime.

the class BeanUtils method setProperties.

/**
     * Sets the properties of a Java Bean based on the String name/value pairs in
     * the specifieed Map. Because this method has to know how to convert a
     * String value into the correct type for the bean, only a few bean property
     * types are supported. They are: String, boolean, int, long, float, double,
     * Color, and Class.<p>
     *
     * If key/value pairs exist in the Map that don't correspond to properties
     * of the bean, they will be ignored.
     *
     * @param bean the JavaBean to set properties on.
     * @param properties String name/value pairs of the properties to set.
     */
public static void setProperties(Object bean, Map<String, String> properties) {
    try {
        // Loop through all the property names in the Map
        for (String propName : properties.keySet()) {
            try {
                // Create a property descriptor for the named property. If
                // the bean doesn't have the named property, an
                // Introspection will be thrown.
                PropertyDescriptor descriptor = new PropertyDescriptor(propName, bean.getClass());
                // Load the class type of the property.
                Class propertyType = descriptor.getPropertyType();
                // Get the value of the property by converting it from a
                // String to the correct object type.
                Object value = decode(propertyType, properties.get(propName));
                // Set the value of the bean.
                descriptor.getWriteMethod().invoke(bean, value);
            } catch (IntrospectionException ie) {
            // Ignore. This exception means that the key in the map
            // does not correspond to a property of the bean.
            } catch (InvocationTargetException ite) {
            // Ignore. This exception most often occurs when a
            // value in the map is null and the target method doesn't
            // support null properties.
            }
        }
    } catch (Exception e) {
        Log.error(e.getMessage(), e);
    }
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) IntrospectionException(java.beans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IntrospectionException(java.beans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 59 with IntrospectionException

use of java.beans.IntrospectionException in project Openfire by igniterealtime.

the class WorkgroupBeanInfo method getPropertyDescriptors.

public PropertyDescriptor[] getPropertyDescriptors() {
    Class beanClass = getBeanClass();
    String[] properties = getPropertyNames();
    PropertyDescriptor[] descriptors = new PropertyDescriptor[properties.length];
    try {
        // name and description using the localized data.
        for (int i = 0; i < descriptors.length; i++) {
            PropertyDescriptor newDescriptor = new PropertyDescriptor(properties[i], beanClass);
            if (bundle != null) {
                try {
                    newDescriptor.setDisplayName(bundle.getString(properties[i] + ".displayName"));
                } catch (MissingResourceException ignored) {
                }
                try {
                    newDescriptor.setShortDescription(bundle.getString(properties[i] + ".shortDescription"));
                } catch (MissingResourceException ignored) {
                }
                // used to set this value.
                try {
                    String largeText = bundle.getString(properties[i] + ".useLargeTextField");
                    if ("true".equals(largeText)) {
                        newDescriptor.setValue("useLargeTextField", "true");
                    }
                } catch (MissingResourceException ignored) {
                }
            }
            descriptors[i] = newDescriptor;
        }
        return descriptors;
    } catch (IntrospectionException ie) {
        Log.error(ie.getMessage(), ie);
        throw new Error(ie.toString());
    }
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) MissingResourceException(java.util.MissingResourceException) IntrospectionException(java.beans.IntrospectionException)

Example 60 with IntrospectionException

use of java.beans.IntrospectionException in project SQLWindowing by hbutani.

the class SerializationUtils method makeTransient.

public static void makeTransient(Class<?> beanClass, String pdName) {
    BeanInfo info;
    try {
        info = Introspector.getBeanInfo(beanClass);
        PropertyDescriptor[] propertyDescriptors = info.getPropertyDescriptors();
        for (int i = 0; i < propertyDescriptors.length; ++i) {
            PropertyDescriptor pd = propertyDescriptors[i];
            if (pd.getName().equals(pdName)) {
                pd.setValue("transient", Boolean.TRUE);
            }
        }
    } catch (IntrospectionException ie) {
        throw new RuntimeException(ie);
    }
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) BeanInfo(java.beans.BeanInfo) IntrospectionException(java.beans.IntrospectionException)

Aggregations

IntrospectionException (java.beans.IntrospectionException)111 PropertyDescriptor (java.beans.PropertyDescriptor)65 Method (java.lang.reflect.Method)46 BeanInfo (java.beans.BeanInfo)44 MockJavaBean (org.apache.harmony.beans.tests.support.mock.MockJavaBean)24 InvocationTargetException (java.lang.reflect.InvocationTargetException)18 IndexedPropertyDescriptor (java.beans.IndexedPropertyDescriptor)17 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)10 Field (java.lang.reflect.Field)9 EventSetDescriptor (java.beans.EventSetDescriptor)7 List (java.util.List)6 Map (java.util.Map)6 MessageFormat (java.text.MessageFormat)5 UUID (java.util.UUID)5 Assert (org.springframework.util.Assert)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 Optional (java.util.Optional)4 RecursiveChildrenListManager (cern.gp.explorer.test.helpers.RecursiveChildrenListManager)3 SimpleDemoBean (cern.gp.explorer.test.helpers.SimpleDemoBean)3