Search in sources :

Example 1 with PropertyDescriptorProperty

use of org.directwebremoting.impl.PropertyDescriptorProperty in project ma-core-public by infiniteautomation.

the class ExceptionConverter method fixMissingThrowableProperty.

/**
 * Make sure Throwable's standard properties are added
 * (fix for Bean Introspector peculiarities)
 * @param descriptors The Map of the known descriptors
 * @param name The name of the property to add
 * @param readMethodName A method name to use when getting said property
 * @throws IntrospectionException If we fail to build a PropertyDescriptor
 */
protected void fixMissingThrowableProperty(Map descriptors, String name, String readMethodName) throws IntrospectionException {
    if (!descriptors.containsKey(name) && isAllowedByIncludeExcludeRules(name)) {
        PropertyDescriptor descriptor = new PropertyDescriptor(name, Throwable.class, readMethodName, null);
        descriptors.put(name, new PropertyDescriptorProperty(descriptor));
    }
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) PropertyDescriptorProperty(org.directwebremoting.impl.PropertyDescriptorProperty)

Example 2 with PropertyDescriptorProperty

use of org.directwebremoting.impl.PropertyDescriptorProperty in project ma-core-public by infiniteautomation.

the class BeanConverter method getPropertyMapFromClass.

/* (non-Javadoc)
     * @see org.directwebremoting.extend.NamedConverter#getPropertyMap(java.lang.Class, boolean, boolean)
     */
public Map getPropertyMapFromClass(Class type, boolean readRequired, boolean writeRequired) throws MarshallException {
    try {
        BeanInfo info = Introspector.getBeanInfo(type);
        PropertyDescriptor[] descriptors = info.getPropertyDescriptors();
        Map properties = new HashMap();
        for (int i = 0; i < descriptors.length; i++) {
            PropertyDescriptor descriptor = descriptors[i];
            String name = descriptor.getName();
            // We don't marshall getClass()
            if (name.equals("class")) {
                continue;
            }
            // Access rules mean we might not want to do this one
            if (!isAllowedByIncludeExcludeRules(name)) {
                continue;
            }
            if (readRequired && descriptor.getReadMethod() == null) {
                continue;
            }
            if (writeRequired && descriptor.getWriteMethod() == null) {
                continue;
            }
            properties.put(name, new PropertyDescriptorProperty(descriptor));
        }
        return properties;
    } catch (IntrospectionException ex) {
        throw new MarshallException(type, ex);
    }
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) HashMap(java.util.HashMap) MarshallException(org.directwebremoting.extend.MarshallException) BeanInfo(java.beans.BeanInfo) IntrospectionException(java.beans.IntrospectionException) PropertyDescriptorProperty(org.directwebremoting.impl.PropertyDescriptorProperty) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

PropertyDescriptor (java.beans.PropertyDescriptor)2 PropertyDescriptorProperty (org.directwebremoting.impl.PropertyDescriptorProperty)2 BeanInfo (java.beans.BeanInfo)1 IntrospectionException (java.beans.IntrospectionException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 MarshallException (org.directwebremoting.extend.MarshallException)1