Example usage for java.beans PropertyDescriptor getPropertyType

List of usage examples for java.beans PropertyDescriptor getPropertyType

Introduction

In this page you can find the example usage for java.beans PropertyDescriptor getPropertyType.

Prototype

public synchronized Class<?> getPropertyType() 

Source Link

Document

Returns the Java type info for the property.

Usage

From source file:ar.com.fdvs.dj.domain.builders.ReflectiveReportBuilder.java

/**
 * Calculates the column width according to its type.
 * @param _property the property.//from   ww  w .  j  a  va2  s .  co  m
 * @return the column width.
 */
private static int getColumnWidth(final PropertyDescriptor _property) {
    final Class type = _property.getPropertyType();
    if (Float.class.isAssignableFrom(type) || Double.class.isAssignableFrom(type)) {
        return 70;
    } else if (type == Boolean.class) {
        return 10;
    } else if (Number.class.isAssignableFrom(type)) {
        return 60;
    } else if (type == String.class) {
        return 100;
    } else if (Date.class.isAssignableFrom(type)) {
        return 50;
    } else {
        return 50;
    }
}

From source file:com.nec.nsgui.model.biz.cifs.NSBeanUtil.java

/**
*  The bean members' type is limited to String and String[]
*//*  w w  w .java2 s  .c  o m*/
public static void setProperties(Object bean, String[] valueArray, String delimiter) throws Exception {
    if (bean == null || valueArray == null || valueArray.length == 0) {
        return;
    }
    Map map = new TreeMap();
    for (int i = 0; i < valueArray.length; i++) {
        String keyAndValue = valueArray[i];
        if (keyAndValue == null || keyAndValue.indexOf(KEY_VALUE_SPLITER) == -1) {
            continue;
        } else {
            String[] tmpArray = valueArray[i].split(KEY_VALUE_SPLITER, 2);
            String key = tmpArray[0].trim();
            if (delimiter != null) {
                PropertyDescriptor descriptor = PropertyUtils.getPropertyDescriptor(bean, key);
                Class propertyType = descriptor.getPropertyType();
                if (propertyType.isArray()) {
                    String[] values = tmpArray[1].split(delimiter);
                    map.put(key, values);
                    continue;
                }
            }
            String value = tmpArray[1];
            map.put(key, value);
        }
    }
    if (map.size() > 0) {
        BeanUtils.populate(bean, map);
    }
    return;
}

From source file:PropertyUtils.java

/**
 * Set nested property given by property path, starting at specified
 * index. Dynamically create beans if necessary. Take care not to
 * leave the bean changed if an exception occurs.
 *///  ww  w  .jav  a  2 s  .  com
private static void setNestedPropertyWithCreate(Object bean, String[] path, int start, Object value)
        throws NoSuchMethodException, IllegalAccessException, InvocationTargetException,
        InstantiationException {
    for (int i = start; i < path.length - 1; i++) {
        Object object = getProperty(bean, path[i]);
        if (object == null) {
            PropertyDescriptor descr = getPropertyDescriptor(bean.getClass(), path[i]);
            object = descr.getPropertyType().newInstance();
            setNestedPropertyWithCreate(object, path, i + 1, value);
            setProperty(bean, path[i], object);
            return;
        }
        bean = object;
    }
    setProperty(bean, path[path.length - 1], value);
}

From source file:org.jkcsoft.java.util.Beans.java

public static String toBeanString(Object bean) {
    StringBuilder sb = new StringBuilder(Strings.restAfterLast(bean.getClass().getName(), "."));

    PropertyDescriptor[] pds = getPropertyDescriptors(bean.getClass());

    for (int idxPd = 0; idxPd < pds.length; idxPd++) {
        PropertyDescriptor pd = pds[idxPd];
        if (pd.getPropertyType().isPrimitive() || pd.getPropertyType().equals(Long.class)
                || pd.getPropertyType().equals(Integer.class) || pd.getPropertyType().equals(String.class)) {
            try {
                sb.append(" [" + pd.getName() + "] " + get(bean, pd.getName()));
            } catch (Exception e) {
                sb.append(" [" + pd.getName() + "] " + e.getMessage());
            }/*from  ww w.j ava2  s .  co  m*/
        }
    }

    return sb.toString();
}

From source file:org.kuali.rice.krad.util.DataTypeUtil.java

/**
 * Given a BusinessObject class and an attribute name, determines the class of that attribute on the BusinessObject class
 * @param boClass a class extending BusinessObject
 * @param attributeKey the name of a field on that class
 * @return the Class of the given attribute
 *///from   w  ww. java2s  .  co  m
private static Class<?> thieveAttributeType(Class<?> boClass, String attributeKey) {
    for (PropertyDescriptor prop : PropertyUtils.getPropertyDescriptors(boClass)) {
        if (prop.getName().equals(attributeKey)) {
            return prop.getPropertyType();
        }
    }
    return null;
}

From source file:org.jdal.beans.PropertyUtils.java

public static PropertyDescriptor getPropertyDescriptor(Class<?> clazz, String propertyPath) {
    PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(clazz,
            getFirstPropertyName(getFirstPropertyName(propertyPath)));

    if (isNested(propertyPath)) // recurse
        return getPropertyDescriptor(pd.getPropertyType(), getNestedPath(propertyPath));

    return pd;/*from   w  w  w  .  j  a va  2 s  .  com*/
}

From source file:org.kuali.ext.mm.utility.BeanDDCreator.java

public static boolean isNormalProperty(PropertyDescriptor p) {
    return p.getPropertyType() != null && !BusinessObject.class.isAssignableFrom(p.getPropertyType())
            && !p.getName().equals("objectId") && !p.getName().equals("class")
            && !p.getName().startsWith("boNote") && !p.getName().startsWith("autoIncrementSet")
            && !p.getPropertyType().equals(List.class) && !p.getName().equals("newCollectionRecord");
}

From source file:com.gisgraphy.helper.BeanHelper.java

public static Class getBeanPropertyClass(final Object bean, final String propertyName)
        throws IntrospectionException {
    final PropertyDescriptor[] propDescriptors = BeanHelper.getBeanProperties(bean);
    for (final PropertyDescriptor propDescriptor : propDescriptors) {
        if (propertyName.equals(propDescriptor.getName())) {
            return propDescriptor.getPropertyType();
        }// w w w.  j ava  2 s  . c  o m
    }
    return null;
}

From source file:org.apache.ignite.cache.store.cassandra.common.PropertyMappingHelper.java

/**
 * Checks if property descriptor describes primitive property (int, boolean, long and etc.)
 *
 * @param desc property descriptor./*from   w w  w .j  a  v a2  s.  com*/
 *
 * @return {@code true} property is primitive
 */
public static boolean isPrimitivePropertyDescriptor(PropertyDescriptor desc) {
    return PropertyMappingHelper.JAVA_TO_CASSANDRA_MAPPING.containsKey(desc.getPropertyType());
}

From source file:org.granite.grails.integration.GrailsExternalizer.java

public static boolean isIgnored(PropertyDescriptor property) {
    if (EVENTS.contains(property.getName()))
        return true;
    if (property.getName().equals("errors") && property.getPropertyType() != null
            && property.getPropertyType().getName().equals(ERRORS))
        return true;
    return false;
}