Example usage for java.beans PropertyDescriptor getName

List of usage examples for java.beans PropertyDescriptor getName

Introduction

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

Prototype

public String getName() 

Source Link

Document

Gets the programmatic name of this feature.

Usage

From source file:org.jdal.text.FormatUtils.java

/**
 * Field for property name, if any//from w  w  w . ja v  a  2s  . co m
 * @param pd PropertyDescriptor
 * @return property field or null if none.
 */
public static Field getDeclaredField(PropertyDescriptor pd) {

    try {
        return pd.getReadMethod().getDeclaringClass().getDeclaredField(pd.getName());
    } catch (Exception e) {
        if (log.isDebugEnabled())
            log.debug("Cannot access to field: " + pd.getName());

        return null;
    }
}

From source file:gov.nih.nci.cabig.ctms.web.WebTools.java

public static SortedMap<String, Object> requestPropertiesToMap(HttpServletRequest request) {
    BeanWrapper wrapped = new BeanWrapperImpl(request);
    SortedMap<String, Object> map = new TreeMap<String, Object>();
    for (PropertyDescriptor descriptor : wrapped.getPropertyDescriptors()) {
        String name = descriptor.getName();
        if (!EXCLUDED_REQUEST_PROPERTIES.contains(name) && descriptor.getReadMethod() != null) {
            Object propertyValue;
            try {
                propertyValue = wrapped.getPropertyValue(name);
            } catch (InvalidPropertyException e) {
                log.debug("Exception reading request property " + name, e);
                propertyValue = e.getMostSpecificCause();
            }/*from ww w . j a  v a  2s  .com*/
            map.put(name, propertyValue);
        }
    }
    return map;
}

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

/**
 * Checks if a property is valid to be included in the report.
 * @param _property the property./*  www.jav  a2  s . co  m*/
 * @return true if the property is not class, and it is of a valid type.
 */
private static boolean isValidProperty(final PropertyDescriptor _property) {
    return !"class".equals(_property.getName()) && isValidPropertyClass(_property);
}

From source file:com.esofthead.mycollab.common.interceptor.aspect.AuditLogUtil.java

static public String getChangeSet(Object oldObj, Object newObj, List<String> excludeFields,
        boolean isSelective) {
    Class cl = oldObj.getClass();
    List<AuditChangeItem> changeItems = new ArrayList<>();

    try {//from w  w w.j a  v  a 2s .c o m
        BeanInfo beanInfo = Introspector.getBeanInfo(cl, Object.class);

        for (PropertyDescriptor propertyDescriptor : beanInfo.getPropertyDescriptors()) {
            String fieldName = propertyDescriptor.getName();
            if (excludeFields.contains(fieldName)) {
                continue;
            }
            String oldProp = getValue(PropertyUtils.getProperty(oldObj, fieldName));

            Object newPropVal;
            try {
                newPropVal = PropertyUtils.getProperty(newObj, fieldName);
            } catch (Exception e) {
                continue;
            }
            String newProp = getValue(newPropVal);

            if (!oldProp.equals(newProp)) {
                if (isSelective && newProp.equals("")) {
                } else {
                    AuditChangeItem changeItem = new AuditChangeItem();
                    changeItem.setField(fieldName);
                    changeItem.setNewvalue(newProp);
                    changeItem.setOldvalue(oldProp);
                    changeItems.add(changeItem);
                }
            }
        }
    } catch (Exception e) {
        LOG.error("There is error when convert changeset", e);
        return null;
    }

    return (changeItems.size() > 0) ? JsonDeSerializer.toJson(changeItems) : null;
}

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();
        }/*from ww  w .  j av  a2s . co  m*/
    }
    return null;
}

From source file:com.aw.support.beans.BeanUtils.java

public static Object copyProperties(Object source, Object target, String[] propertyNamesToIgnore,
        boolean ignoreProxy, boolean ignoreCollections) {
    List<String> propertyNamesToIgnoreList = propertyNamesToIgnore == null ? Collections.EMPTY_LIST
            : Arrays.asList(propertyNamesToIgnore);
    BeanWrapper sourceWrap = new BeanWrapperImpl(source);
    BeanWrapper targetWrap = new BeanWrapperImpl(target);
    for (PropertyDescriptor propDescriptor : sourceWrap.getPropertyDescriptors()) {
        String propName = propDescriptor.getName();
        //chequear que no esta en la lista a ignorar
        if (propertyNamesToIgnoreList.contains(propName))
            continue;
        //chequear que se puede leer
        if (!sourceWrap.isReadableProperty(propName))
            continue;
        //chequear que se puede escribir
        if (!targetWrap.isWritableProperty(propName))
            continue;

        Object sourceValue = sourceWrap.getPropertyValue(propName);

        //chequear que objeto no es un proxy
        if (ignoreProxy && sourceValue != null && Proxy.isProxyClass(sourceValue.getClass()))
            continue;

        //chequear que objeto no una collection
        if (ignoreCollections && sourceValue instanceof Collection)
            continue;

        targetWrap.setPropertyValue(propName, sourceValue);
    }//from w w  w.  j a va2  s .  c  o m
    return target;
}

From source file:de.xwic.appkit.core.transport.xml.EtoSerializer.java

/**
 * @param o/* w ww . j  av  a2  s  .c  o  m*/
 * @return
 * @throws IntrospectionException
 */
private static Map<String, PropertyDescriptor> getMap(final Object o) throws IntrospectionException {
    final BeanInfo beanInfo = Introspector.getBeanInfo(o.getClass(), Introspector.USE_ALL_BEANINFO);
    final List<PropertyDescriptor> asList = Arrays.asList(beanInfo.getPropertyDescriptors());
    final Map<String, PropertyDescriptor> map = MapUtil.generateMap(asList,
            new Function<PropertyDescriptor, String>() {

                @Override
                public String evaluate(final PropertyDescriptor obj) {
                    return obj.getName();
                }
            });
    return map;
}

From source file:es.pode.soporte.auditoria.registrar.BeanDescripcion.java

/** 
 * Mtodo para recuperar informacin de un objeto a travs de reflexin 
 *   //from  ww w  . ja  va 2s .c o m
 * @param objeto Objeto al cual se le realiza la reflexin 
 * @param atributo Valor que se recupera del objeto
 * @return valor Se devuelve el valor del atributo buscado
 */
public static String describe(Object objeto, String atributo) {

    if (objeto == null)
        return null;

    Object valor = null;

    Class clase = objeto.getClass();
    if (clase.isArray() || java.util.Collection.class.isAssignableFrom(clase))
        log.warn("El atributo es un array y debera ser un String");
    else {
        log("Reflexin del objeto: " + objeto);

        BeanWrapper wrapper = new BeanWrapperImpl(objeto);
        PropertyDescriptor descriptors[] = wrapper.getPropertyDescriptors();

        for (int i = 0; i < descriptors.length; i++) {
            PropertyDescriptor pd = descriptors[i];

            if (pd.getReadMethod() != null && pd.getWriteMethod() != null) {
                String name = pd.getName();

                /* Capturamos el valor del atributo que nos interesa */
                if (name.equals(atributo)) {
                    log("Nombre atributo: " + name);
                    valor = wrapper.getPropertyValue(name);

                    /* Si el valor es nulo registramos un "" */
                    if (valor == null) {
                        log("El valor del atributo interceptado es nulo");
                        return null;
                    } else
                        return valor.toString();
                }
            }
        }
    }

    return null;
}

From source file:net.mojodna.searchable.SearchableBeanUtils.java

/**
 * Gets the name of the property that should be used to generate a search
 * excerpt.// w w w .j av  a 2  s  .  co m
 * 
 * @param clazz Class to reflect on.
 * @return Name of the excerptable property; null if none present.
 */
public static String getExcerptPropertyName(final Class<? extends Result> clazz) {
    final PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(clazz);
    for (final PropertyDescriptor d : descriptors) {
        if (AnnotationUtils.isAnnotationPresent(d.getReadMethod(), Searchable.Excerptable.class))
            return d.getName();
    }

    return null;
}

From source file:com.glaf.core.util.Tools.java

public static Map<String, Class<?>> getPropertyMap(Class<?> clazz) {
    Map<String, Class<?>> dataMap = new java.util.HashMap<String, Class<?>>();
    PropertyDescriptor[] propertyDescriptor = BeanUtils.getPropertyDescriptors(clazz);
    for (int i = 0; i < propertyDescriptor.length; i++) {
        PropertyDescriptor descriptor = propertyDescriptor[i];
        String propertyName = descriptor.getName();
        if (propertyName.equalsIgnoreCase("class")) {
            continue;
        }/*from ww  w.  j av a  2  s . c  o  m*/
        dataMap.put(propertyName, descriptor.getPropertyType());
    }
    return dataMap;
}