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:com.thesoftwarefactory.vertx.web.model.Form.java

/**
 * Build a new Form instance from the specified class
 * // w w w .  j  a va 2 s. c  o m
 * @param cls
 * @param fieldPrefix: if not null, the prefix is prepended to each field name 
 * @return
 */
public final static <T> Form<T> fromClass(Class<T> cls, String fieldPrefix) {
    Objects.requireNonNull(cls);

    Form<T> result = new Form<T>();
    if (fieldPrefix != null) {
        result.fieldPrefix = fieldPrefix;
    }

    // discover properties
    for (PropertyDescriptor property : BeanUtils.getPropertyDescriptors(cls)) {
        if (property.getReadMethod() != null && property.getWriteMethod() != null) {
            // the property has a getter and setter
            String fieldName = fieldPrefix != null ? fieldPrefix + property.getName() : property.getName();
            result.addField(result.new Field(fieldName, Form.fieldTypefromClass(property.getPropertyType())));
        }
    }

    return result;
}

From source file:name.martingeisse.wicket.autoform.describe.DefaultAutoformBeanDescriberHelper.java

@Override
protected String getPropertyName(final PropertyDescriptor propertyDescriptor) {
    return propertyDescriptor.getName();
}

From source file:net.jakubholy.jeeutils.jsfelcheck.util.BeanPropertyUtils.java

/**
 * Find the type of the given property.// w ww .ja  v a  2s.co m
 * @param propertyName (required)
 * @return the type of the property or null if not found
 */
public Class<?> getPropertyTypeOf(String propertyName) {
    PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(type);
    for (PropertyDescriptor descriptor : descriptors) {
        if (descriptor.getName().equals(propertyName)) {
            return descriptor.getPropertyType();
        }
    }

    LOG.fine("No property '" + propertyName + "' found on the class " + type.getName());

    return null;
}

From source file:com.cyclopsgroup.tornado.utils.BeanDynaTagSupport.java

/**
 * Overwrite or implement method getAttributeType()
 *
 * @see com.cyclopsgroup.waterview.utils.DynaTagSupport#getAttributeType(java.lang.String)
 *//*w ww.j  a  v  a  2 s.  co  m*/
public Class getAttributeType(String attributeName) throws JellyTagException {
    if (beanClass == null) {
        return super.getAttributeType(attributeName);
    }
    PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(beanClass);
    for (int i = 0; i < descriptors.length; i++) {
        PropertyDescriptor descriptor = descriptors[i];
        if (descriptor.getName().equals(attributeName)) {
            return descriptor.getPropertyType();
        }
    }
    return super.getAttributeType(attributeName);
}

From source file:com.wavemaker.json.type.reflect.WMPropertyUtilsBean.java

@Override
public PropertyDescriptor[] getPropertyDescriptors(Class klass) {
    PropertyDescriptor[] pds = super.getPropertyDescriptors(klass);

    for (PropertyDescriptor pd : pds) {
        String name = pd.getName();
        Field fld = null;/*from   w  w w .  j ava2s .  c  o  m*/
        try {
            fld = klass.getDeclaredField(name);
        } catch (NoSuchFieldException ex) {
        }

        if (fld != null) {
            continue;
        }

        String shifted = name.substring(0, 1).toUpperCase();

        String newName = shifted + name.substring(1);

        fld = null;
        try {
            fld = klass.getDeclaredField(newName);
        } catch (NoSuchFieldException ex) {
        }

        if (fld != null) {
            pd.setName(newName);
        }
    }

    return pds;
}

From source file:fr.opensagres.struts2.views.xdocreport.LazyCommonsBeanUtilsPopulateContext.java

protected Object getSimpleProperty(Object pojo, PropertyDescriptor descriptor) throws Exception {
    return PropertyUtils.getSimpleProperty(pojo, descriptor.getName());
}

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 ww  .  jav a2s  .  c  o m
public void notifyAllPropsChanged(Object vm) {
    PropertyDescriptor[] props = BeanUtils.getPropertyDescriptors(vm.getClass());
    for (PropertyDescriptor prop : props) {
        postNotifyChange(vm, prop.getName());
    }
}

From source file:com.cyclopsgroup.tornado.hibernate.taglib.NewTag.java

/**
 * Overwrite or implement method getAttributeType()
 *
 * @see com.cyclopsgroup.waterview.utils.DynaTagSupport#getAttributeType(java.lang.String)
 */// w  w  w .  j  av a2s .c o  m
public Class getAttributeType(String attributeName) throws JellyTagException {
    if (attributeName.equals("var")) {
        return String.class;
    }
    if (descriptors == null) {
        ClassTag classTag = (ClassTag) requireParent(ClassTag.class);
        descriptors = PropertyUtils.getPropertyDescriptors(classTag.getEntityClass());
    }
    for (int i = 0; i < descriptors.length; i++) {
        PropertyDescriptor descriptor = descriptors[i];
        if (descriptor.getName().equals(attributeName)) {
            return descriptor.getPropertyType();
        }
    }
    throw new JellyTagException("Attribute " + attributeName + " is not supported");
}

From source file:es.caib.zkib.jxpath.util.ValueUtils.java

/**
 * Modifies the value of the bean's property represented by
 * the supplied property descriptor.//from  w w  w  .ja  v a 2s .  com
 * @param bean to read
 * @param propertyDescriptor indicating what to read
 * @param value to set
 */
public static void setValue(Object bean, PropertyDescriptor propertyDescriptor, Object value) {
    try {
        Method method = getAccessibleMethod(propertyDescriptor.getWriteMethod());
        if (method == null) {
            throw new JXPathException("No write method");
        }
        value = convert(value, propertyDescriptor.getPropertyType());
        method.invoke(bean, new Object[] { value });
    } catch (Exception ex) {
        throw new JXPathException("Cannot modify property: "
                + (bean == null ? "null" : bean.getClass().getName()) + "." + propertyDescriptor.getName(), ex);
    }
}

From source file:com.fengduo.bee.commons.core.lang.CollectionUtils.java

public static <M> void merge(M original, M destination, List<String> ignore) throws Exception {
    BeanInfo beanInfo = Introspector.getBeanInfo(original.getClass());
    // Iterate over all the attributes
    for (PropertyDescriptor descriptor : beanInfo.getPropertyDescriptors()) {
        // Only copy writable attributes
        if (descriptor.getWriteMethod() != null) {
            Object originalValue = descriptor.getReadMethod().invoke(original);
            String attributeName = descriptor.getName();
            // ignore this values,do'not merge
            if (ignore != null && !ignore.isEmpty() && ignore.contains(attributeName)) {
                continue;
            }/*from w w  w . j  av  a2 s  .  c  om*/
            Object defaultValue = descriptor.getReadMethod().invoke(destination);
            // Only copy values values where the destination values is null
            if (originalValue == null) {
                descriptor.getWriteMethod().invoke(original, defaultValue);
            }
            if (defaultValue instanceof Number && originalValue instanceof Number) {
                descriptor.getWriteMethod().invoke(original,
                        MathUtils.add((Number) originalValue, (Number) defaultValue));
            }
        }
    }
}