Example usage for java.beans PropertyDescriptor getPropertyType

List of usage examples for java.beans PropertyDescriptor getPropertyType

Introduction

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

Prototype

public synchronized Class<?> getPropertyType() 

Source Link

Document

Returns the Java type info for the property.

Usage

From source file:org.eclipse.wb.internal.rcp.databinding.model.beans.observables.properties.BeanPropertiesCodeSupport.java

public final void setBeanType(Class<?> beanType) throws Exception {
    m_parserBeanType = beanType;//from   w  w w . j a  v  a 2  s. c  om
    if (m_parserBeanType != null && m_parserPropertyReference != null && m_parserPropertyType == null) {
        String propertyName = StringUtils.remove(m_parserPropertyReference, "\"");
        for (PropertyDescriptor descriptor : BeanSupport.getPropertyDescriptors(m_parserBeanType)) {
            if (propertyName.equals(descriptor.getName())) {
                m_parserPropertyType = descriptor.getPropertyType();
                break;
            }
        }
    }
}

From source file:org.jage.platform.component.pico.injector.PropertiesInjector.java

@Override
protected void doVerify(final PicoContainer container) {
    for (final String propertyName : parameters.keySet()) {
        PropertyDescriptor descriptor = descriptors.get(propertyName);
        if (descriptor == null) {
            throw new PicoCompositionException(format("no property named '%1$s'", propertyName));
        }/*from   w ww  .j  av a  2  s. c om*/
        Class<?> propertyType = descriptor.getPropertyType();

        Parameter parameter = parameters.get(propertyName);
        try {
            parameter.verify(container, this, propertyType, null, false, null);
        } catch (PicoCompositionException e) {
            throw new PicoCompositionException(format("property '%1$s': %2$s", propertyName, e.getMessage()),
                    e);
        }
    }
}

From source file:gov.nih.nci.cabig.caaers.domain.expeditedfields.ExpeditedReportTreeTest.java

/**
 * Figures out the next domain object type down from the descriptor given.
 *///from  ww  w.j  a  v a2s  .  c  o  m
private Class<?> getPropertyType(PropertyDescriptor descriptor) {
    if (Map.class.isAssignableFrom(descriptor.getPropertyType())) {
        Type returnType = descriptor.getReadMethod().getGenericReturnType();
        if (returnType instanceof ParameterizedType) {
            return (Class<?>) ((ParameterizedType) returnType).getActualTypeArguments()[1];
        } else {
            fail("Could not extract type of value for map property " + descriptor.getName());
        }
    } else if (List.class.isAssignableFrom(descriptor.getPropertyType())) {
        Type returnType = descriptor.getReadMethod().getGenericReturnType();
        if (returnType instanceof ParameterizedType) {
            return (Class<?>) ((ParameterizedType) returnType).getActualTypeArguments()[0];
        } else {
            fail("Could not extract type of value for list property " + descriptor.getName());
        }
    } else {
        return descriptor.getPropertyType();
    }
    throw new CaaersError("That's unpossible");
}

From source file:org.apache.hadoop.gateway.filter.rewrite.impl.xml.XmlUrlRewriteRulesExporter.java

private Element createElement(Document document, String name, Object bean) throws IntrospectionException,
        InvocationTargetException, NoSuchMethodException, IllegalAccessException {
    Element element = document.createElement(name);
    BeanInfo beanInfo = Introspector.getBeanInfo(bean.getClass(), Object.class);
    for (PropertyDescriptor propInfo : beanInfo.getPropertyDescriptors()) {
        String propName = propInfo.getName();
        if (propInfo.getReadMethod() != null && String.class.isAssignableFrom(propInfo.getPropertyType())) {
            String propValue = BeanUtils.getProperty(bean, propName);
            if (propValue != null && !propValue.isEmpty()) {
                // Doing it the hard way to avoid having the &'s in the query string escaped at &amp;
                Attr attr = document.createAttribute(propName);
                attr.setValue(propValue);
                element.setAttributeNode(attr);
                //element.setAttribute( propName, propValue );
            }//from   w  w w  .  ja  va 2s. com
        }
    }
    return element;
}

From source file:com.dexcoder.dal.spring.mapper.JdbcRowMapper.java

/**
 * Retrieve a JDBC object value for the specified column.
 * <p>The default implementation calls
 * {@link JdbcUtils#getResultSetValue(java.sql.ResultSet, int, Class)}.
 * Subclasses may override this to check specific value types upfront,
 * or to post-process values return from {@code getResultSetValue}.
 * @param rs is the ResultSet holding the data
 * @param index is the column index//www . j a v a  2s.com
 * @param pd the bean property that each result object is expected to match
 * (or {@code null} if none specified)
 * @return the Object value
 * @throws SQLException in case of extraction failure
 * @see org.springframework.jdbc.support.JdbcUtils#getResultSetValue(java.sql.ResultSet, int, Class)
 */
protected Object getColumnValue(ResultSet rs, int index, PropertyDescriptor pd) throws SQLException {
    return JdbcUtils.getResultSetValue(rs, index, pd.getPropertyType());
}

From source file:ca.sqlpower.architect.swingui.TestPlayPenComponent.java

/**
 * Returns true if an instance of the given property type is of a mutable class.
 * Throws an exception if it lacks a case for the given type.
 * /*w w w  .j a  v  a2  s  . c o  m*/
 * @param property The property that should be checked for mutability.
 */
private boolean isPropertyInstanceMutable(PropertyDescriptor property) {
    if (property.getPropertyType() == String.class) {
        return false;
    } else if (property.getPropertyType().isAssignableFrom(Enum.class)) {
        return false;
    } else if (property.getPropertyType() == Boolean.class || property.getPropertyType() == Boolean.TYPE) {
        return false;
    } else if (property.getPropertyType() == Integer.class || property.getPropertyType() == Integer.TYPE) {
        return false;
    } else if (property.getPropertyType() == Double.class || property.getPropertyType() == Double.TYPE) {
        return false;
    } else if (property.getPropertyType() == Color.class) {
        return false;
    } else if (property.getPropertyType() == Font.class) {
        return false;
    } else if (property.getPropertyType() == Point.class) {
        return true;
    } else if (property.getPropertyType() == Dimension.class) {
        return true;
    } else if (property.getPropertyType() == Insets.class) {
        return true;
    } else if (property.getPropertyType() == Set.class) {
        return true;
    } else if (property.getPropertyType() == List.class) {
        return true;
    } else if (property.getPropertyType() == TablePane.class) {
        return true;
    } else if (property.getPropertyType() == SQLTable.class) {
        return true;
    } else if (property.getPropertyType() == JPopupMenu.class) {
        return true;
    }
    if (property.getName().equals("model")) {
        return true;
    }
    throw new RuntimeException("This test case lacks a value for " + property.getName() + " (type "
            + property.getPropertyType().getName() + ") in isPropertyInstanceMutable()");
}

From source file:org.mule.module.netsuite.api.model.expression.filter.FilterExpressionBuilder.java

private SearchRecord createOrGetAttributeGroup(String joinName) throws Exception {
    PropertyDescriptor d = newDescriptor(joinName + "Join", target);
    SearchRecord attributeGroup = (SearchRecord) d.getReadMethod().invoke(target);
    if (attributeGroup == null) {
        attributeGroup = (SearchRecord) d.getPropertyType().newInstance();
        d.getWriteMethod().invoke(target, attributeGroup);
    }//from   w  ww .  ja  va  2s. c  o m
    return attributeGroup;
}

From source file:at.molindo.notify.model.BeanParams.java

private void setProperty(Param<?> param, Object value) {
    PropertyDescriptor pd = getDescriptor(param.getName());
    if (pd == null) {
        // TODO simply ignore?
        return;//from   ww  w .  j  a  v a  2  s .  com
    }

    Object converted;
    if (value == null || pd.getPropertyType().isAssignableFrom(value.getClass())) {
        converted = value;
    } else {
        converted = Param.p(pd.getPropertyType(), pd.getName()).toObject(param.toString(value));
    }

    try {
        PropertyUtils.setProperty(_bean, param.getName(), converted);
    } catch (NoSuchMethodException e) {
        throw new NotifyRuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new NotifyRuntimeException(e);
    } catch (InvocationTargetException e) {
        throw new NotifyRuntimeException(e);
    }
}

From source file:org.grails.datastore.mapping.model.config.DefaultMappingConfigurationStrategy.java

/**
 * @see #getPersistentProperties(Class, org.grails.datastore.mapping.model.MappingContext, org.grails.datastore.mapping.model.ClassMapping)
 */// w ww  . ja  v  a 2 s.  c o  m
public List<PersistentProperty> getPersistentProperties(PersistentEntity entity, MappingContext context,
        ClassMapping classMapping) {
    ClassPropertyFetcher cpf = ClassPropertyFetcher.forClass(entity.getJavaClass());
    PropertyDescriptor[] descriptors = cpf.getPropertyDescriptors();
    final ArrayList<PersistentProperty> persistentProperties = new ArrayList<PersistentProperty>();

    for (PropertyDescriptor descriptor : descriptors) {
        final String propertyName = descriptor.getName();
        if (isExcludedProperty(propertyName, classMapping, Collections.emptyList()))
            continue;
        Class<?> propertyType = descriptor.getPropertyType();
        if (propertyFactory.isSimpleType(propertyType)) {
            persistentProperties.add(propertyFactory.createSimple(entity, context, descriptor));
        } else if (MappingFactory.isCustomType(propertyType)) {
            persistentProperties.add(propertyFactory.createCustom(entity, context, descriptor));
        }
    }
    return persistentProperties;
}

From source file:things.thing.ThingUtils.java

public Map<String, Map<String, String>> getRegisteredTypeProperties() {

    if (typePropertiesMap == null) {
        Map<String, Map<String, String>> temp = Maps.newTreeMap();
        for (String type : tr.getAllTypes()) {
            Class typeClass = tr.getTypeClass(type);
            BeanInfo info = null;
            try {
                info = Introspector.getBeanInfo(typeClass);
            } catch (IntrospectionException e) {
                throw new TypeRuntimeException("Can't generate info for type: " + type, type, e);
            }/*  ww  w . j ava 2  s . c o  m*/

            Map<String, String> properties = Maps.newTreeMap();

            for (PropertyDescriptor desc : info.getPropertyDescriptors()) {
                String name = desc.getName();
                if ("class".equals(name) || "id".equals(name)) {
                    continue;
                }
                Class propClass = desc.getPropertyType();
                properties.put(name, propClass.getSimpleName());
            }
            temp.put(type, properties);
        }
        typePropertiesMap = ImmutableMap.copyOf(temp);
    }
    return typePropertiesMap;

}