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.ocs.dynamo.importer.impl.BaseImporter.java

/**
 * Processes a single row from the input and turns it into an object
 * /*w  w  w .  j  a v a 2s .  c om*/
 * @param rowNum
 * @param row
 * @param clazz
 * @return
 */
public <T extends AbstractDTO> T processRow(int rowNum, R row, Class<T> clazz) {
    T t = ClassUtils.instantiateClass(clazz);
    t.setRowNum(rowNum);

    PropertyDescriptor[] descriptors = BeanUtils.getPropertyDescriptors(clazz);
    for (PropertyDescriptor d : descriptors) {
        XlsField field = ClassUtils.getAnnotation(clazz, d.getName(), XlsField.class);
        if (field != null) {
            if (isWithinRange(row, field)) {
                U unit = getUnit(row, field);

                Object obj = getFieldValue(d, unit, field);
                if (obj != null) {
                    ClassUtils.setFieldValue(t, d.getName(), obj);
                } else if (field.required()) {
                    // a required value is missing!
                    throw new OCSImportException("Required value for field '" + d.getName() + "' is missing");
                }
            } else {
                throw new OCSImportException("Row doesn't have enough columns");
            }
        }
    }

    return t;
}

From source file:com.qccr.livtrip.web.template.BaseDirective.java

/**
 * ?/*from   w  w w.  j  a v a  2 s.co  m*/
 * 
 * @param params
 *            ?
 * @param type
 *            ?
 * @param ignoreProperties
 *            
 * @return 
 */
protected List<Filter> getFilters(Map<String, TemplateModel> params, Class<?> type, String... ignoreProperties)
        throws TemplateModelException {
    List<Filter> filters = new ArrayList<Filter>();
    PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(type);
    for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
        String propertyName = propertyDescriptor.getName();
        Class<?> propertyType = propertyDescriptor.getPropertyType();
        if (!ArrayUtils.contains(ignoreProperties, propertyName) && params.containsKey(propertyName)) {
            Object value = FreeMarkerUtils.getParameter(propertyName, propertyType, params);
            filters.add(Filter.eq(propertyName, value));
        }
    }
    return filters;
}

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

/**
 * Returns the index'th element of the bean's property represented by
 * the supplied property descriptor./*from w  w w  . ja  va 2s.co m*/
 * @param bean to read
 * @param propertyDescriptor indicating what to read
 * @param index int
 * @return Object
 */
public static Object getValue(Object bean, PropertyDescriptor propertyDescriptor, int index) {
    if (propertyDescriptor instanceof IndexedPropertyDescriptor) {
        try {
            IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) propertyDescriptor;
            Method method = ipd.getIndexedReadMethod();
            if (method != null) {
                return method.invoke(bean, new Object[] { new Integer(index) });
            }
        } catch (InvocationTargetException ex) {
            Throwable t = ex.getTargetException();
            if (t instanceof IndexOutOfBoundsException) {
                return null;
            }
            throw new JXPathException("Cannot access property: " + propertyDescriptor.getName(), t);
        } catch (Throwable ex) {
            throw new JXPathException("Cannot access property: " + propertyDescriptor.getName(), ex);
        }
    }

    // We will fall through if there is no indexed read

    return getValue(getValue(bean, propertyDescriptor), index);
}

From source file:io.milton.property.BeanPropertySource.java

@Override
public List<QName> getAllPropertyNames(Resource r) {
    BeanPropertyResource anno = getAnnotation(r);
    if (anno == null) {
        return null;
    }//from ww w.  j a v a 2 s .  c  o m
    PropertyDescriptor[] pds = PropertyUtils.getPropertyDescriptors(r);
    List<QName> list = new ArrayList<QName>();
    for (PropertyDescriptor pd : pds) {
        if (pd.getReadMethod() != null) {
            list.add(new QName(anno.value(), pd.getName()));
        }
    }
    return list;
}

From source file:com.dp2345.template.directive.BaseDirective.java

/**
 * ?//from w  ww.  j  a  v a 2 s.  com
 * 
 * @param params
 *            ?
 * @param type
 *            ?
 * @param ignoreProperties
 *            
 * @return 
 */
protected List<Filter> getFilters(Map<String, TemplateModel> params, Class<?> type, String... ignoreProperties)
        throws TemplateModelException {
    List<Filter> filters = new ArrayList<Filter>();
    PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(type);
    for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
        String propertyName = propertyDescriptor.getName();
        Class<?> propertyType = propertyDescriptor.getPropertyType();
        if (!ArrayUtils.contains(ignoreProperties, propertyName) && params.containsKey(propertyName)) {
            Object value = FreemarkerUtils.getParameter(propertyName, propertyType, params);
            filters.add(Filter.eq(propertyName, value));
        }
    }
    return filters;
}

From source file:org.neovera.jdiablo.environment.SpringEnvironment.java

private void injectProperties(Object object) {
    Map<String, PropertyPlaceholderProvider> map = _context.getBeansOfType(PropertyPlaceholderProvider.class);
    PropertyPlaceholderProvider ppp = null;
    if (map.size() != 0) {
        ppp = map.values().iterator().next();
    }//from w ww  . j  ava  2 s .  com

    // Analyze members to see if they are annotated.
    Map<String, String> propertyNamesByField = new HashMap<String, String>();
    Class<?> clz = object.getClass();
    while (!clz.equals(Object.class)) {
        for (Field field : clz.getDeclaredFields()) {
            if (field.isAnnotationPresent(PropertyPlaceholder.class)) {
                propertyNamesByField.put(
                        field.getName().startsWith("_") ? field.getName().substring(1) : field.getName(),
                        field.getAnnotation(PropertyPlaceholder.class).value());
            }
        }
        clz = clz.getSuperclass();
    }

    PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(object.getClass());
    for (PropertyDescriptor pd : descriptors) {
        if (propertyNamesByField.keySet().contains(pd.getName())) {
            if (ppp == null) {
                _logger.error(
                        "Field {} is annotated with PropertyPlaceholder but no bean of type "
                                + "PropertyPlaceholderProvider is defined in the Spring application context.",
                        pd.getName());
                break;
            } else {
                setValue(pd, object, ppp.getProperty(propertyNamesByField.get(pd.getName())));
            }
        } else if (pd.getReadMethod() != null
                && pd.getReadMethod().isAnnotationPresent(PropertyPlaceholder.class)) {
            if (ppp == null) {
                _logger.error(
                        "Field {} is annotated with PropertyPlaceholder but no bean of type "
                                + "PropertyPlaceholderProvider is defined in the Spring application context.",
                        pd.getName());
                break;
            } else {
                setValue(pd, object,
                        ppp.getProperty(pd.getReadMethod().getAnnotation(PropertyPlaceholder.class).value()));
            }
        }
    }
}

From source file:com.zuora.api.object.Dynamic.java

/**
 * Answers the name and values of the both static and dynamic properties of this object
 * @return this object's properties, as string-object pairs
 *//* w  ww . j av  a2  s  . c om*/
private Collection<Entry<String, Object>> propertyValues() {
    try {
        return collect(Arrays.asList(Introspector.getBeanInfo(this.getClass()).getPropertyDescriptors()),
                new Transformer() {
                    public Object transform(Object input) {
                        PropertyDescriptor p = (PropertyDescriptor) input;
                        return new DefaultMapEntry(p.getName(), NaiveProperties.get(Dynamic.this, p.getName()));
                    }
                });
    } catch (Exception e) {
        throw MuleSoftException.soften(e);
    }
}

From source file:net.cpollet.jixture.hibernate3.helper.Hibernate3MappingDefinitionHolder.java

private boolean isGetterForField(PropertyDescriptor pd, Field field) {
    return null != pd.getReadMethod() && pd.getName().equals(field.getName());
}

From source file:name.livitski.tools.persista.AbstractDAO.java

protected Map<String, PropertyDescriptor> introspectProperties() {
    if (null == entityProps)
        try {/*from   w ww .j a  v a 2 s  .  co  m*/
            final BeanInfo beanInfo = Introspector.getBeanInfo(entityClass);
            final PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
            entityProps = new HashMap<String, PropertyDescriptor>(propertyDescriptors.length, 1f);
            for (final PropertyDescriptor pd : propertyDescriptors) {
                entityProps.put(pd.getName(), pd);
            }
        } catch (IntrospectionException e) {
            throw new UnsupportedOperationException("Introspection failed for entity " + entityClass, e);
        }
    return entityProps;
}

From source file:com.sf.ddao.crud.param.CRUDBeanPropsParameter.java

public int bindParam(PreparedStatement preparedStatement, int idx, Context ctx) throws SQLException {
    if (descriptors == null) {
        init(ctx);/*  w  ww .j a  v  a2s .  co  m*/
    }
    int c = 0;
    final Object bean = getBean(ctx);
    DirtyPropertyAware dirtyPropertyAware = null;
    if (bean instanceof DirtyPropertyAware) {
        dirtyPropertyAware = (DirtyPropertyAware) bean;
    }
    for (PropertyDescriptor descriptor : descriptors) {
        try {
            if (dirtyPropertyAware != null && !dirtyPropertyAware.isDirty(descriptor.getName())) {
                continue;
            }
            Object v = descriptor.getReadMethod().invoke(bean);
            ParameterHelper.bind(preparedStatement, idx++, v, descriptor.getPropertyType(), ctx);
            c++;
        } catch (Exception e) {
            throw new SQLException(descriptor.getName(), e);
        }
    }
    if (dirtyPropertyAware != null) {
        dirtyPropertyAware.cleanDirtyBean();
    }
    return c;
}