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.sunsprinter.diffunit.core.translators.AbstractPropertyDrivenTranslator.java

protected Collection<PropertyDescriptor> determinePropertiesEligibleForTranslation(final T object)
        throws TranslationException {
    // We don't have a map of property names to properties.  We create one now.  We use a linked hash map to
    // preserve the order of the properties.  After all, we've gone to a lot of bother to order our properties
    // so the look nice in our test output.
    final Map<String, PropertyDescriptor> allPropertiesMap = buildAllPropertiesMap(object);

    final Collection<PropertyDescriptor> properties;
    if (getPropertiesToTranslate().isEmpty()) {
        // The client hasn't specified the properties to translate so we do all of them.
        properties = allPropertiesMap.values();
    } else {/*from  w ww .ja v  a  2  s . c  o  m*/
        properties = new LinkedList<PropertyDescriptor>();

        // The client has specified the properties we have to translate.
        for (final String propertyName : getPropertiesToTranslate()) {
            final PropertyDescriptor propertyDescriptor = allPropertiesMap.get(propertyName);
            if (propertyDescriptor == null) {
                // Oops.  The client specified a property that doesn't exist.
                throw new TranslationException(object,
                        String.format(
                                "Property '%s' does not exist on object '%s'.  "
                                        + "Available properties are '%s'.",
                                propertyName, getInstanceTracker().getObjectId(object),
                                StringUtils.join(allPropertiesMap.keySet(), "', '")));
            }

            // Skip write-only properties.  Seriously, who does write-only properties?  You'd be surprised.
            if (propertyDescriptor.getReadMethod() != null) {
                properties.add(propertyDescriptor);
            }
        }
    }

    // Now build up our eligible properties collection by adding everything except the things we've been told to skip.
    final Collection<PropertyDescriptor> eligibleProperties = createEligiblePropertiesCollection();
    for (final PropertyDescriptor propertyDescriptor : properties) {
        if (!getPropertiesToSkip().contains(propertyDescriptor.getName())) {
            eligibleProperties.add(propertyDescriptor);
        }
    }

    return eligibleProperties;
}

From source file:com.bstek.dorado.idesupport.initializer.CommonRuleTemplateInitializer.java

protected Collection<AutoPropertyTemplate> getProperties(Class<?> type, XmlNodeInfo xmlNodeInfo,
        InitializerContext initializerContext) throws Exception {
    HashMap<String, AutoPropertyTemplate> properties = new LinkedHashMap<String, AutoPropertyTemplate>();
    RuleTemplateManager ruleTemplateManager = initializerContext.getRuleTemplateManager();

    if (xmlNodeInfo != null) {
        if (xmlNodeInfo.isInheritable()) {
            AutoPropertyTemplate propertyTemplate = new AutoPropertyTemplate("impl");
            propertyTemplate.setPrimitive(true);
            properties.put(propertyTemplate.getName(), propertyTemplate);

            propertyTemplate = new AutoPropertyTemplate("parent");
            propertyTemplate.setPrimitive(true);
            properties.put(propertyTemplate.getName(), propertyTemplate);
        }/*from w  w w  .j  a  v  a2  s .co m*/

        if (xmlNodeInfo.isScopable()) {
            AutoPropertyTemplate propertyTemplate = new AutoPropertyTemplate("scope");
            propertyTemplate.setPrimitive(true);

            Object[] ecs = Scope.class.getEnumConstants();
            String[] enumValues = new String[ecs.length];
            for (int i = 0; i < ecs.length; i++) {
                enumValues[i] = ecs[i].toString();
            }
            propertyTemplate.setEnumValues(enumValues);

            properties.put(propertyTemplate.getName(), propertyTemplate);
        }

        if (StringUtils.isNotEmpty(xmlNodeInfo.getDefinitionType())) {
            Class<?> definitionType = ClassUtils.forName(xmlNodeInfo.getDefinitionType());
            if (ListenableObjectDefinition.class.isAssignableFrom(definitionType)) {
                AutoPropertyTemplate propertyTemplate = new AutoPropertyTemplate("listener");
                propertyTemplate.setPrimitive(true);
                properties.put(propertyTemplate.getName(), propertyTemplate);
            }

            if (InterceptableDefinition.class.isAssignableFrom(definitionType)) {
                AutoPropertyTemplate propertyTemplate = new AutoPropertyTemplate("interceptor");
                propertyTemplate.setPrimitive(true);
                properties.put(propertyTemplate.getName(), propertyTemplate);
            }
        }

        for (Map.Entry<String, String> entry : xmlNodeInfo.getFixedProperties().entrySet()) {
            String propertyName = entry.getKey();
            String value = entry.getValue();

            AutoPropertyTemplate propertyTemplate = new AutoPropertyTemplate(propertyName);
            propertyTemplate.setDefaultValue(value);
            propertyTemplate.setPrimitive(true);
            propertyTemplate.setFixed(true);
            propertyTemplate.setVisible(false);
            properties.put(propertyName, propertyTemplate);
        }

        for (Map.Entry<String, XmlProperty> entry : xmlNodeInfo.getProperties().entrySet()) {
            String propertyName = entry.getKey();
            XmlProperty xmlProperty = entry.getValue();
            TypeInfo propertyTypeInfo = TypeInfo.parse(xmlProperty.propertyType());
            Class<?> propertyType = null;
            if (propertyTypeInfo != null) {
                propertyType = propertyTypeInfo.getType();
            }

            AutoPropertyTemplate propertyTemplate = new AutoPropertyTemplate(propertyName, xmlProperty);
            propertyTemplate.setPrimitive(xmlProperty.attributeOnly());
            if (propertyType != null && !propertyType.equals(String.class)) {
                propertyTemplate.setType(propertyType.getName());
            }

            if (xmlProperty.composite()) {
                initCompositeProperty(propertyTemplate, propertyType, initializerContext);
            }
            propertyTemplate.setDeprecated(xmlProperty.deprecated());

            properties.put(propertyName, propertyTemplate);
        }
    }

    PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(type);
    for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
        Method readMethod = propertyDescriptor.getReadMethod();
        if (readMethod != null && propertyDescriptor.getWriteMethod() != null) {
            if (readMethod.getDeclaringClass() != type) {
                try {
                    readMethod = type.getDeclaredMethod(readMethod.getName(), readMethod.getParameterTypes());
                } catch (NoSuchMethodException e) {
                    continue;
                }
            }

            String propertyName = propertyDescriptor.getName();

            XmlSubNode xmlSubNode = readMethod.getAnnotation(XmlSubNode.class);
            if (xmlSubNode != null) {
                continue;
            }

            TypeInfo propertyTypeInfo;
            Class<?> propertyType = propertyDescriptor.getPropertyType();
            if (Collection.class.isAssignableFrom(propertyType)) {
                propertyTypeInfo = TypeInfo.parse((ParameterizedType) readMethod.getGenericReturnType(), true);
                propertyType = propertyTypeInfo.getType();
            } else {
                propertyTypeInfo = new TypeInfo(propertyType, false);
            }

            AutoPropertyTemplate propertyTemplate = null;
            XmlProperty xmlProperty = readMethod.getAnnotation(XmlProperty.class);
            if (xmlProperty != null) {
                if (xmlProperty.unsupported()) {
                    continue;
                }

                propertyTemplate = properties.get(propertyName);
                if (propertyTemplate == null) {
                    propertyTemplate = new AutoPropertyTemplate(propertyName, readMethod, xmlProperty);
                    propertyTemplate.setPrimitive(xmlProperty.attributeOnly());
                }

                if (("dataSet".equals(propertyName) || "dataPath".equals(propertyName)
                        || "property".equals(propertyName)) && DataControl.class.isAssignableFrom(type)) {
                    propertyTemplate.setHighlight(1);
                }

                if (xmlProperty.composite()) {
                    initCompositeProperty(propertyTemplate, propertyType, initializerContext);
                }

                int clientTypes = ClientType.parseClientTypes(xmlProperty.clientTypes());
                if (clientTypes > 0) {
                    propertyTemplate.setClientTypes(clientTypes);
                }
                propertyTemplate.setDeprecated(xmlProperty.deprecated());
            } else if (EntityUtils.isSimpleType(propertyType) || propertyType.equals(Class.class)
                    || propertyType.isArray() && propertyType.getComponentType().equals(String.class)) {
                propertyTemplate = new AutoPropertyTemplate(propertyName, readMethod, xmlProperty);
            }

            if (propertyTemplate != null) {
                propertyTemplate.setType(propertyDescriptor.getPropertyType().getName());

                if (propertyType.isEnum()) {
                    Object[] ecs = propertyType.getEnumConstants();
                    String[] enumValues = new String[ecs.length];
                    for (int i = 0; i < ecs.length; i++) {
                        enumValues[i] = ecs[i].toString();
                    }
                    propertyTemplate.setEnumValues(enumValues);
                }

                ComponentReference componentReference = readMethod.getAnnotation(ComponentReference.class);
                if (componentReference != null) {
                    ReferenceTemplate referenceTemplate = new LazyReferenceTemplate(ruleTemplateManager,
                            componentReference.value(), "id");
                    propertyTemplate.setReference(referenceTemplate);
                }

                IdeProperty ideProperty = readMethod.getAnnotation(IdeProperty.class);
                if (ideProperty != null) {
                    propertyTemplate.setVisible(ideProperty.visible());
                    propertyTemplate.setEditor(ideProperty.editor());
                    propertyTemplate.setHighlight(ideProperty.highlight());
                    if (StringUtils.isNotEmpty(ideProperty.enumValues())) {
                        propertyTemplate.setEnumValues(StringUtils.split(ideProperty.enumValues(), ",;"));
                    }
                }

                ClientProperty clientProperty = readMethod.getAnnotation(ClientProperty.class);
                if (clientProperty != null) {
                    propertyTemplate.setDefaultValue(clientProperty.escapeValue());
                }

                properties.put(propertyName, propertyTemplate);
            }
        }
    }
    return properties.values();
}

From source file:com.ocs.dynamo.domain.model.impl.EntityModelFactoryImpl.java

/**
 * Constructs an attribute model for a property
 * //w  ww . ja  v a2  s  . com
 * @param descriptor
 *            the property descriptor
 * @param entityModel
 *            the entity model
 * @param parentClass
 *            the type of the direct parent of the attribute (relevant in case of embedded
 *            attributes)
 * @param nested
 *            whether this is a nested attribute
 * @param prefix
 *            the prefix to apply to the attribute name
 * @return
 */
private <T> List<AttributeModel> constructAttributeModel(PropertyDescriptor descriptor,
        EntityModelImpl<T> entityModel, Class<?> parentClass, boolean nested, String prefix) {
    List<AttributeModel> result = new ArrayList<AttributeModel>();

    // validation methods annotated with @AssertTrue or @AssertFalse have to
    // be ignored
    String fieldName = descriptor.getName();
    AssertTrue assertTrue = ClassUtils.getAnnotation(entityModel.getEntityClass(), fieldName, AssertTrue.class);
    AssertFalse assertFalse = ClassUtils.getAnnotation(entityModel.getEntityClass(), fieldName,
            AssertFalse.class);

    if (assertTrue == null && assertFalse == null) {

        AttributeModelImpl model = new AttributeModelImpl();
        model.setEntityModel(entityModel);

        String displayName = DefaultFieldFactory.createCaptionByPropertyId(fieldName);

        // first, set the defaults
        model.setDisplayName(displayName);
        model.setDescription(displayName);
        model.setPrompt(displayName);
        model.setMainAttribute(descriptor.isPreferred());
        model.setSearchable(descriptor.isPreferred());
        model.setName((prefix == null ? "" : (prefix + ".")) + fieldName);
        model.setImage(false);

        model.setReadOnly(descriptor.isHidden());
        model.setSortable(true);
        model.setComplexEditable(false);
        model.setPrecision(SystemPropertyUtils.getDefaultDecimalPrecision());
        model.setSearchCaseSensitive(false);
        model.setSearchPrefixOnly(false);
        model.setUrl(false);
        model.setUseThousandsGrouping(true);

        Id idAttr = ClassUtils.getAnnotation(entityModel.getEntityClass(), fieldName, Id.class);
        if (idAttr != null) {
            entityModel.setIdAttributeModel(model);
            // the ID column is hidden. details collections are also hidden
            // by default
            model.setVisible(false);
        } else {
            model.setVisible(true);
        }
        model.setType(descriptor.getPropertyType());

        // determine the possible date type
        model.setDateType(determineDateType(model.getType(), entityModel.getEntityClass(), fieldName));

        // determine default display format
        model.setDisplayFormat(determineDefaultDisplayFormat(model.getType(), entityModel.getEntityClass(),
                fieldName, model.getDateType()));

        // determine if the attribute is required based on the @NotNull
        // annotation
        NotNull notNull = ClassUtils.getAnnotation(entityModel.getEntityClass(), fieldName, NotNull.class);
        model.setRequired(notNull != null);

        model.setAttributeType(determineAttributeType(parentClass, model));

        // minimum and maximum length based on the @Size annotation
        Size size = ClassUtils.getAnnotation(entityModel.getEntityClass(), fieldName, Size.class);
        if (AttributeType.BASIC.equals(model.getAttributeType()) && size != null) {
            model.setMaxLength(size.max());
            model.setMinLength(size.min());
        }

        setNestedEntityModel(model);

        // only basic attributes are shown in the table by default
        model.setVisibleInTable(
                !nested && model.isVisible() && (AttributeType.BASIC.equals(model.getAttributeType())));

        if (getMessageService() != null) {
            model.setTrueRepresentation(getMessageService().getMessage("ocs.true"));
            model.setFalseRepresentation(getMessageService().getMessage("ocs.false"));
        }

        // by default, use a combo box to look up
        model.setSelectMode(AttributeSelectMode.COMBO);
        model.setTextFieldMode(AttributeTextFieldMode.TEXTFIELD);
        model.setSearchSelectMode(AttributeSelectMode.COMBO);

        // is the field an email field?
        Email email = ClassUtils.getAnnotation(entityModel.getEntityClass(), fieldName, Email.class);
        model.setEmail(email != null);

        // override the defaults with annotation values
        setAnnotationOverrides(parentClass, model, descriptor, nested);

        // override any earlier version with message bundle contents
        setMessageBundleOverrides(entityModel, model);

        if (!model.isEmbedded()) {
            result.add(model);
        } else {
            // an embedded object is not directly added. Instead, its child
            // properties are added as attributes
            if (model.getType().equals(entityModel.getEntityClass())) {
                throw new IllegalStateException("Embedding a class in itself is not allowed");
            }
            PropertyDescriptor[] embeddedDescriptors = BeanUtils.getPropertyDescriptors(model.getType());
            for (PropertyDescriptor embeddedDescriptor : embeddedDescriptors) {
                String name = embeddedDescriptor.getName();
                if (!skipAttribute(name)) {
                    List<AttributeModel> embeddedModels = constructAttributeModel(embeddedDescriptor,
                            entityModel, model.getType(), nested, model.getName());
                    result.addAll(embeddedModels);
                }
            }
        }
    }
    return result;
}

From source file:com.ebay.jetstream.management.HtmlResourceFormatter.java

protected void formatProperty(Object bean, PropertyDescriptor pd) throws Exception {
    PrintWriter pw = getWriter();
    Method getter = pd.getReadMethod();
    Class<?> pclass = pd.getPropertyType();
    ManagedAttribute attr = getter.getAnnotation(ManagedAttribute.class);
    String text = attr != null ? attr.description() : null;
    if (CommonUtils.isEmptyTrimmed(text)) {
        text = pd.getDisplayName();/*  w  w w  . jav a  2  s .  c  om*/
    } else {
        text = pd.getDisplayName() + " (" + text + ")";
    }
    pw.print(text + ": " + pclass.getName() + " = ");
    getter.setAccessible(true);
    Object value = getter.invoke(bean);
    Method setter = pd.getWriteMethod();
    attr = setter == null ? null : setter.getAnnotation(ManagedAttribute.class);
    boolean isComplex = !(String.class.isAssignableFrom(pclass) || ClassUtils.isPrimitiveOrWrapper(pclass));
    if (isComplex) {
        value = StringEscapeUtils.escapeXml(getSerializer().getXMLStringRepresentation(value));
    }
    if (attr == null) {
        if (isComplex) {
            pushElement("code", null);
        }
        pw.println(value);
        if (isComplex) {
            popElement();
        }
    } else {
        pw.println(attr.description());
        pushElement("form",
                "action=" + makePath(getPrefix(), getPath(), isComplex ? "?form" : "?" + pd.getName())
                        + " method=" + (isComplex ? "POST" : "GET"));
        if (isComplex) {
            pw.print("<TEXTAREA name=" + pd.getName() + " rows=4 cols=32>" + value + "</TEXTAREA>");
        } else {
            pw.print("<input type=text name=" + pd.getName() + " value=\"" + value + "\"/>");
        }
        pw.println("<input type=submit Value=\"Go\"/>");
        popElement();
    }
    pw.println("<P/>");
}

From source file:com.gdcn.modules.db.jdbc.processor.CamelBeanProcessor.java

/**
 * Calls the setter method on the target object for the given property.
 * If no setter method exists for the property, this method does nothing.
 * @param target The object to set the property on.
 * @param prop The property to set./*from  w ww .  j a  va  2s .  co m*/
 * @param value The value to pass into the setter.
 * @throws SQLException if an error occurs setting the property.
 */
private void callSetter(Object target, PropertyDescriptor prop, Object value) throws SQLException {

    Method setter = prop.getWriteMethod();

    if (setter == null) {
        return;
    }

    Class<?>[] params = setter.getParameterTypes();
    try {
        // convert types for some popular ones
        if (value instanceof java.util.Date) {
            final String targetType = params[0].getName();
            if ("java.sql.Date".equals(targetType)) {
                value = new java.sql.Date(((java.util.Date) value).getTime());
            } else if ("java.sql.Time".equals(targetType)) {
                value = new java.sql.Time(((java.util.Date) value).getTime());
            } else if ("java.sql.Timestamp".equals(targetType)) {
                value = new java.sql.Timestamp(((java.util.Date) value).getTime());
            }
        }

        // Don't call setter if the value object isn't the right type
        if (this.isCompatibleType(value, params[0])) {
            setter.invoke(target, new Object[] { value });
        } else {
            throw new SQLException("Cannot set " + prop.getName() + ": incompatible types, cannot convert "
                    + value.getClass().getName() + " to " + params[0].getName());
            // value cannot be null here because isCompatibleType allows null
        }

    } catch (IllegalArgumentException e) {
        throw new SQLException("Cannot set " + prop.getName() + ": " + e.getMessage());

    } catch (IllegalAccessException e) {
        throw new SQLException("Cannot set " + prop.getName() + ": " + e.getMessage());

    } catch (InvocationTargetException e) {
        throw new SQLException("Cannot set " + prop.getName() + ": " + e.getMessage());
    }
}

From source file:com.icsshs.datatransfer.database.impl.QueryBeanProcessor.java

/**
 * Calls the setter method on the target object for the given property.
 * If no setter method exists for the property, this method does nothing.
 * @param target The object to set the property on.
 * @param prop The property to set./*from ww w. j  a  v a 2 s  .co  m*/
 * @param value The value to pass into the setter.
 * @throws SQLException if an error occurs setting the property.
 */
private void callSetter(Object target, PropertyDescriptor prop, Object value) throws SQLException {

    Method setter = prop.getWriteMethod();

    if (setter == null) {
        return;
    }

    Class<?>[] params = setter.getParameterTypes();
    try {
        // convert types for some popular ones
        if (value != null) {
            if (value instanceof java.util.Date) {
                if (params[0].getName().equals("java.sql.Date")) {
                    value = new java.sql.Date(((java.util.Date) value).getTime());
                } else if (params[0].getName().equals("java.sql.Time")) {
                    value = new java.sql.Time(((java.util.Date) value).getTime());
                } else if (params[0].getName().equals("java.sql.Timestamp")) {
                    value = new java.sql.Timestamp(((java.util.Date) value).getTime());
                }
            }
        }

        // Don't call setter if the value object isn't the right type
        if (this.isCompatibleType(value, params[0])) {
            setter.invoke(target, new Object[] { value });
        } else {
            throw new SQLException("Cannot set " + prop.getName() + ": incompatible types.");
        }

    } catch (IllegalArgumentException e) {
        throw new SQLException("Cannot set " + prop.getName() + ": " + e.getMessage());

    } catch (IllegalAccessException e) {
        throw new SQLException("Cannot set " + prop.getName() + ": " + e.getMessage());

    } catch (InvocationTargetException e) {
        throw new SQLException("Cannot set " + prop.getName() + ": " + e.getMessage());
    }
}

From source file:com.gmail.sretof.db.jdbc.processor.CamelBeanProcessor.java

/**
 * Calls the setter method on the target object for the given property. If
 * no setter method exists for the property, this method does nothing.
 * /*from ww w .java 2s  . c  o  m*/
 * @param target
 *            The object to set the property on.
 * @param prop
 *            The property to set.
 * @param value
 *            The value to pass into the setter.
 * @throws SQLException
 *             if an error occurs setting the property.
 */
private void callSetter(Object target, PropertyDescriptor prop, Object value) throws SQLException {

    Method setter = prop.getWriteMethod();

    if (setter == null) {
        return;
    }

    Class<?>[] params = setter.getParameterTypes();
    try {
        // convert types for some popular ones
        if (value instanceof java.util.Date) {
            final String targetType = params[0].getName();
            if ("java.sql.Date".equals(targetType)) {
                value = new java.sql.Date(((java.util.Date) value).getTime());
            } else if ("java.sql.Time".equals(targetType)) {
                value = new java.sql.Time(((java.util.Date) value).getTime());
            } else if ("java.sql.Timestamp".equals(targetType)) {
                value = new java.sql.Timestamp(((java.util.Date) value).getTime());
            }
        }

        // Don't call setter if the value object isn't the right type
        if (this.isCompatibleType(value, params[0])) {
            setter.invoke(target, new Object[] { value });
        } else {
            throw new SQLException("Cannot set " + prop.getName() + ": incompatible types, cannot convert "
                    + value.getClass().getName() + " to " + params[0].getName());
            // value cannot be null here because isCompatibleType allows
            // null
        }

    } catch (IllegalArgumentException e) {
        throw new SQLException("Cannot set " + prop.getName() + ": " + e.getMessage());

    } catch (IllegalAccessException e) {
        throw new SQLException("Cannot set " + prop.getName() + ": " + e.getMessage());

    } catch (InvocationTargetException e) {
        throw new SQLException("Cannot set " + prop.getName() + ": " + e.getMessage());
    }
}

From source file:ca.sqlpower.architect.swingui.TestPlayPen.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.
  * //from   w ww .ja  va  2 s  .c om
  * @param property The property that should be checked for mutability.
  */
private boolean isPropertyInstanceMutable(PropertyDescriptor property) {
    if (property.getPropertyType() == String.class) {
        return false;
    } else if (Enum.class.isAssignableFrom(property.getPropertyType())) {
        return false;
    } else if (property.getPropertyType() == Boolean.class || property.getPropertyType() == Boolean.TYPE) {
        return false;
    } else if (property.getPropertyType() == Double.class || property.getPropertyType() == Double.TYPE) {
        return false;
    } else if (property.getPropertyType() == Integer.class || property.getPropertyType() == Integer.TYPE) {
        return false;
    } else if (property.getPropertyType() == Color.class) {
        return false;
    } else if (property.getPropertyType() == Font.class) {
        return false;
    } else if (property.getPropertyType() == Set.class) {
        return true;
    } else if (property.getPropertyType() == List.class) {
        return true;
    } else if (property.getPropertyType() == Point.class) {
        return true;
    } else {
        throw new RuntimeException("This test case lacks a value for " + property.getName() + " (type "
                + property.getPropertyType().getName() + ") in isPropertyInstanceMutable()");
    }
}

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.
 * //from www . j ava2  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:com.ocs.dynamo.importer.impl.BaseImporter.java

@SuppressWarnings("unchecked")
private Object getFieldValue(PropertyDescriptor d, U unit, XlsField field) {
    Object obj = null;/*from www  . j  a  v  a2 s  . co m*/
    if (String.class.equals(d.getPropertyType())) {
        String value = getStringValueWithDefault(unit, field);
        if (value != null) {
            value = value.trim();
        }
        obj = StringUtils.isEmpty(value) ? null : value;
    } else if (d.getPropertyType().isEnum()) {
        String value = getStringValueWithDefault(unit, field);
        if (value != null) {
            value = value.trim();
            try {
                obj = Enum.valueOf(d.getPropertyType().asSubclass(Enum.class), value.toUpperCase());
            } catch (IllegalArgumentException ex) {
                throw new OCSImportException(
                        "Value " + value + " cannot be translated to a valid enumeration value", ex);
            }
        }

    } else if (Number.class.isAssignableFrom(d.getPropertyType())) {
        // numeric field

        Double value = getNumericValueWithDefault(unit, field);
        if (value != null) {

            // if the field represents a percentage but it is
            // received as a
            // fraction, we multiply it by 100
            if (field.percentage()) {
                if (isPercentageCorrectionSupported()) {
                    value = PERCENTAGE_FACTOR * value;
                }
            }

            // illegal negative value
            if (field.cannotBeNegative() && value < 0.0) {
                throw new OCSImportException(
                        "Negative value " + value + " found for field '" + d.getName() + "'");
            }

            if (Integer.class.equals(d.getPropertyType())) {
                obj = new Integer(value.intValue());
            } else if (BigDecimal.class.equals(d.getPropertyType())) {
                obj = BigDecimal.valueOf(value.doubleValue());
            } else {
                // by default, use a double
                obj = value;
            }
        }
    } else if (Boolean.class.isAssignableFrom(d.getPropertyType())) {
        return getBooleanValueWithDefault(unit, field);
    }
    return obj;
}