Example usage for java.beans PropertyDescriptor getReadMethod

List of usage examples for java.beans PropertyDescriptor getReadMethod

Introduction

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

Prototype

public synchronized Method getReadMethod() 

Source Link

Document

Gets the method that should be used to read the property value.

Usage

From source file:com.github.erchu.beancp.PropertyBindingSide.java

/**
 *
 * Creates binding to property from property information.
 *
 * @param propertyDescriptor property information used to create binding
 *///from  www .  ja v  a 2s  .  c o m
public PropertyBindingSide(final PropertyDescriptor propertyDescriptor) {
    this._valueClass = propertyDescriptor.getPropertyType();
    this._readMethod = propertyDescriptor.getReadMethod();
    this._writeMethod = propertyDescriptor.getWriteMethod();
    this._name = propertyDescriptor.getName();
}

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

/**
 * {@inheritDoc}/*ww w. j a  va 2s.  co  m*/
 */
public Map<String, Object> getParameterMap() {
    PropertyDescriptor[] pds = BeanUtils.getPropertyDescriptors(getClass());

    Map<String, Object> map = new HashMap<String, Object>();

    for (PropertyDescriptor pd : pds) {
        if (!ignoredProperties.contains(pd.getName()))
            try {
                map.put(pd.getName(), pd.getReadMethod().invoke(this, (Object[]) null));
            } catch (Exception e) {
                log.error(e);
            }
    }
    return map;
}

From source file:com.hengyi.japp.sap.convert.impl.SapConverts.java

private String getSapFieldName(PropertyDescriptor descriptor) {
    Method readMethod = descriptor.getReadMethod();
    SapConvertField scf = readMethod.getAnnotation(SapConvertField.class);
    if (scf != null) {
        return StringUtils.upperCase(scf.value());
    }/*  w ww . ja v a 2 s  .co m*/
    if (readMethod.getAnnotation(SapTransient.class) != null) {
        return null;
    }

    String beanPropertyName = descriptor.getName();
    for (Field field : beanClass.getDeclaredFields()) {
        if (!field.getName().equals(beanPropertyName)) {
            continue;
        }

        if (field.getAnnotation(SapTransient.class) != null) {
            return null;
        }
        scf = field.getAnnotation(SapConvertField.class);
        if (scf != null) {
            return StringUtils.upperCase(scf.value());
        }
    }
    return StringUtils.upperCase(beanPropertyName);
}

From source file:com.erinors.hpb.server.handler.HibernateEmbeddedObjectHandler.java

@Override
public Object merge(MergingContext context, Object object) {
    if (object == null || !object.getClass().isAnnotationPresent(Embeddable.class)) {
        return null;
    }/* ww w  .j a  v  a2s  .co  m*/

    boolean empty = true;
    try {
        for (PropertyDescriptor pd : PropertyUtils.getPropertyDescriptors(object)) {
            String propertyName = pd.getName();

            if (!"class".equals(propertyName) && !pd.getReadMethod().isAnnotationPresent(Transient.class)) {
                if (PropertyUtils.getSimpleProperty(object, propertyName) != null) {
                    empty = false;
                    break;
                }
            }
        }
    } catch (Exception e) {
        throw new RuntimeException("Error while checking embedded object: " + object, e);
    }

    if (empty) {
        context.addProcessedObject(object, null);
        return ProcessedToNull;
    } else {
        return null;
    }
}

From source file:no.sesat.search.datamodel.DataModelTest.java

private void handleProperty(final Collection<Method> propertyMethods, final PropertyDescriptor property)
        throws IntrospectionException {

    if (null != property.getReadMethod()) {
        propertyMethods.add(property.getReadMethod());
        // recurse down the datamodel heirarchy
        if (null != property.getPropertyType().getAnnotation(DataObject.class)) {
            ensureJavaBeanAPI(property.getPropertyType());
        }// w  ww . j a v a  2s . c  om
    }
    if (null != property.getWriteMethod()) {
        propertyMethods.add(property.getWriteMethod());
    }
}

From source file:com.ettrema.httpclient.calsync.parse.BeanPropertyMapper.java

/**
 * Find a property with the given annotation and return its value
 *
 * @param bean//from  w w w.j a  v a2 s . c  o m
 * @param annotationClass
 * @return
 */
public <T> T getProperty(Object bean, Class annotationClass, Class<T> valueClass) {
    PropertyDescriptor[] pds = PropertyUtils.getPropertyDescriptors(bean);
    for (PropertyDescriptor pd : pds) {
        if (pd.getReadMethod() != null && pd.getWriteMethod() != null) {
            Method read = pd.getReadMethod();
            Annotation[] annotations = read.getAnnotations();
            for (Annotation anno : annotations) {
                if (anno.annotationType() == annotationClass) {
                    return propertyAccessor.get(bean, read, valueClass);
                }
            }
        }
    }
    return null;
}

From source file:com.hengyi.japp.sap.convert.impl.FieldCopyBase.java

protected void initBeanPropertyReadMethod(Object bean, JCoRecord record) throws Exception {
    PropertyDescriptor descriptor = PropertyUtils.getPropertyDescriptor(bean, beanPropertyName);
    beanPropertyReadMethod = descriptor.getReadMethod();
}

From source file:com.nortal.petit.beanmapper.BeanMappingFactoryImpl.java

private boolean isPropertyReadableAndWritable(PropertyDescriptor pd) {
    if (pd == null || pd.getReadMethod() == null || pd.getWriteMethod() == null) {
        return false;
    }/* www  . j av a 2s .  co m*/

    return true;
}

From source file:org.apache.struts2.views.xslt.BeanAdapter.java

protected List<Node> buildChildAdapters() {
    log.debug("BeanAdapter building children.  PropName = " + getPropertyName());
    List<Node> newAdapters = new ArrayList<Node>();
    Class type = getPropertyValue().getClass();
    PropertyDescriptor[] props = getPropertyDescriptors(getPropertyValue());

    if (props.length > 0) {
        for (PropertyDescriptor prop : props) {
            Method m = prop.getReadMethod();

            if (m == null) {
                //FIXME: write only property or indexed access
                continue;
            }/*from  ww  w.j  av a2s .com*/
            log.debug("Bean reading property method: " + m.getName());

            String propertyName = prop.getName();
            Object propertyValue;

            /*
            Unwrap any invocation target exceptions and log them.
            We really need a way to control which properties are accessed.
            Perhaps with annotations in Java5?
            */
            try {
                propertyValue = m.invoke(getPropertyValue(), NULLPARAMS);
            } catch (Exception e) {
                if (e instanceof InvocationTargetException)
                    e = (Exception) ((InvocationTargetException) e).getTargetException();
                log.error(e);
                continue;
            }

            Node childAdapter;

            if (propertyValue == null) {
                childAdapter = getAdapterFactory().adaptNullValue(this, propertyName);
            } else {
                childAdapter = getAdapterFactory().adaptNode(this, propertyName, propertyValue);
            }

            if (childAdapter != null)
                newAdapters.add(childAdapter);

            if (log.isDebugEnabled()) {
                log.debug(this + " adding adapter: " + childAdapter);
            }
        }
    } else {
        // No properties found
        log.info("Class " + type.getName() + " has no readable properties, " + " trying to adapt "
                + getPropertyName() + " with StringAdapter...");
    }

    return newAdapters;
}

From source file:jp.co.opentone.bsol.framework.test.dataset.bean.BeanTable.java

private boolean isIgnoreProperty(PropertyDescriptor desc) {
    final Set<String> ignoreNames = new HashSet<String>();
    ignoreNames.add("class");

    return desc.getReadMethod() == null || ignoreNames.contains(desc.getName());
}