Example usage for org.springframework.beans BeanUtils getPropertyDescriptors

List of usage examples for org.springframework.beans BeanUtils getPropertyDescriptors

Introduction

In this page you can find the example usage for org.springframework.beans BeanUtils getPropertyDescriptors.

Prototype

public static PropertyDescriptor[] getPropertyDescriptors(Class<?> clazz) throws BeansException 

Source Link

Document

Retrieve the JavaBeans PropertyDescriptor s of a given class.

Usage

From source file:org.shept.persistence.provider.DaoUtils.java

/**
 * Checking if it is a new model (identifier == null) If the index is a
 * compound index we must check all components if just one of them is null
 * //from  w w  w. j av  a2s .c  o  m
 * @param index
 * @return
 */
public static boolean isNewModel(DaoSupport dao, Object model) {
    ClassMetadata modelMeta = getClassMetadata(dao, model);
    if (null == modelMeta) {
        return false;
    }

    Object idValue = modelMeta.getIdentifier(model, EntityMode.POJO);

    if (idValue == null) {
        return true;
    }
    Type type = modelMeta.getIdentifierType();
    if (!(type instanceof ComponentType)) {
        return false;
    }

    // didn't manage to get the individual objects of a compound index out of
    // the Hibernate metaModel API although that should be possible ...
    PropertyDescriptor[] desc = BeanUtils.getPropertyDescriptors(idValue.getClass());
    for (int i = 0; i < desc.length; i++) {
        Method mth = desc[i].getReadMethod();
        Object val = ReflectionUtils.invokeMethod(mth, idValue);
        if (null == val) {
            return true;
        }
    }

    return false;
}

From source file:org.jdal.dao.BeanFilter.java

/**
 * {@inheritDoc}//from   w  w w.  j  a va 2 s  .c o m
 */
public void clear() {
    PropertyDescriptor[] pds = BeanUtils.getPropertyDescriptors(getClass());

    for (PropertyDescriptor pd : pds) {
        if (!ignoredProperties.contains(pd.getName())) {
            try {
                pd.getWriteMethod().invoke(this, (Object) null);
            } catch (Exception e) {
                log.error("Error nullifing property: [" + pd.getName() + "]", e);
            }
        }
    }
}

From source file:org.jtalks.poulpe.web.controller.zkutils.BindUtilsWrapper.java

/**
 * Notifies the VM about all the properties inside were changed so that ZK can re-read them and update its UI.
 *
 * @param vm a visual model to iterate through all the properties and trigger ZK Binder notifications
 *///from w  w w  .jav a  2 s.  com
public void notifyAllPropsChanged(Object vm) {
    PropertyDescriptor[] props = BeanUtils.getPropertyDescriptors(vm.getClass());
    for (PropertyDescriptor prop : props) {
        postNotifyChange(vm, prop.getName());
    }
}

From source file:org.grails.jpa.domain.JpaGrailsDomainClass.java

public JpaGrailsDomainClass(Class clazz) {
    super(clazz, "");
    Annotation entityAnnotation = clazz.getAnnotation(Entity.class);
    if (entityAnnotation == null) {
        throw new GrailsDomainException(
                "Class [" + clazz.getName() + "] is not annotated with java.persistence.Entity!");
    }/*from ww w.java  2s . c  o  m*/
    PropertyDescriptor[] descriptors = BeanUtils.getPropertyDescriptors(clazz);
    evaluateClassProperties(descriptors);
    evaluateConstraints();
    propertiesArray = propertyMap.values().toArray(new GrailsDomainClassProperty[propertyMap.size()]);
    persistentPropertyArray = persistentProperties.values()
            .toArray(new GrailsDomainClassProperty[persistentProperties.size()]);
}

From source file:org.jdal.vaadin.data.ListBeanContainer.java

private void initDefaultProperties() {
    for (PropertyDescriptor pd : BeanUtils.getPropertyDescriptors(beanClass)) {
        this.properties.add(pd.getName());
        this.propertyDescriptors.put(pd.getName(), pd);
    }//w ww.  j a  v a 2 s. co  m
}

From source file:com.senacor.core.manager.BaseManagerImpl.java

public List<T> find(final T t) {
    Session session = getSession();/*  w  w w  .j a va 2  s .co m*/
    Criteria criteria = session.createCriteria(boClass);
    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    PropertyDescriptor[] descriptors = BeanUtils.getPropertyDescriptors(boClass);
    BeanWrapper beanWrapper = new BeanWrapperImpl(t);
    for (PropertyDescriptor descriptor : descriptors) {
        if (!descriptor.getName().equals("class") && !descriptor.getName().equals("id")) {
            Object value = beanWrapper.getPropertyValue(descriptor.getName());
            if (value != null) {
                criteria.add(Restrictions.eq(descriptor.getName(), value));
            }
        }
    }
    criteria.addOrder(Order.asc("id"));
    return criteria.list();
}

From source file:org.apache.syncope.core.persistence.beans.AbstractBaseBean.java

/**
 * @return fields to be excluded when computing equals() or hashcode()
 *//*from w w  w. jav a  2s.  c o  m*/
private String[] getExcludeFields() {
    Set<String> excludeFields = new HashSet<String>();

    PropertyDescriptor[] propertyDescriptors = BeanUtils.getPropertyDescriptors(getClass());
    for (int i = 0; i < propertyDescriptors.length; i++) {

        if (propertyDescriptors[i].getPropertyType().isInstance(Collections.emptySet())
                || propertyDescriptors[i].getPropertyType().isInstance(Collections.emptyList())) {

            excludeFields.add(propertyDescriptors[i].getName());
        }
    }

    return excludeFields.toArray(new String[] {});
}

From source file:cat.albirar.framework.sets.impl.ModelDescriptor.java

/**
 * Resolve properties of the model.//w  w  w. j a  va  2 s. c  om
 */
private void resolveProperties() {
    PropertyDescriptor[] pd;

    pd = BeanUtils.getPropertyDescriptors(model);
    for (PropertyDescriptor prop : pd) {
        properties.put(prop.getName(), prop);
    }
}

From source file:com.avanza.ymer.MongoQueryFactory.java

private List<PropertyDescriptor> findTemplatablePropertyDescriptors(Class<?> type) {
    ArrayList<PropertyDescriptor> result = new ArrayList<PropertyDescriptor>();
    for (PropertyDescriptor pd : BeanUtils.getPropertyDescriptors(type)) {
        if (!isNotTemplatableMethod(pd)) {
            result.add(pd);//from w w  w  .  jav a 2s  .  co m
        }
    }
    return result;
}

From source file:com.clican.pluto.common.support.spring.BeanPropertyRowMapper.java

/**
 * Initialize the mapping metadata for the given class.
 * /*from w w  w  .  j  a  v  a 2s  .c  om*/
 * @param mappedClass
 *            the mapped class.
 */
protected void initialize(Class<?> mappedClass) {
    this.mappedClass = mappedClass;
    this.mappedFields = new HashMap<String, PropertyDescriptor>();
    this.mappedProperties = new HashSet<String>();
    PropertyDescriptor[] pds = BeanUtils.getPropertyDescriptors(mappedClass);
    for (int i = 0; i < pds.length; i++) {
        PropertyDescriptor pd = pds[i];
        if (pd.getWriteMethod() != null) {
            this.mappedFields.put(pd.getName().toLowerCase(), pd);
            String underscoredName = underscoreName(pd.getName());
            if (!pd.getName().toLowerCase().equals(underscoredName)) {
                this.mappedFields.put(underscoredName, pd);
            }
            this.mappedProperties.add(pd.getName());
        }
    }
}