Java Code Examples for org.apache.commons.beanutils.DynaClass#getDynaProperties()

The following examples show how to use org.apache.commons.beanutils.DynaClass#getDynaProperties() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SqlDynaBean.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public String toString()
{
    StringBuilder   result = new StringBuilder();
    DynaClass      type   = getDynaClass();
    DynaProperty[] props  = type.getDynaProperties();

    result.append(type.getName());
    result.append(": ");
    for (int idx = 0; idx < props.length; idx++)
    {
        if (idx > 0)
        {
            result.append(", ");
        }
        result.append(props[idx].getName());
        result.append(" = ");
        result.append(get(props[idx].getName()));
    }
    return result.toString();
}
 
Example 2
Source File: SqlDynaBean.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public String toString()
{
    StringBuilder   result = new StringBuilder();
    DynaClass      type   = getDynaClass();
    DynaProperty[] props  = type.getDynaProperties();

    result.append(type.getName());
    result.append(": ");
    for (int idx = 0; idx < props.length; idx++)
    {
        if (idx > 0)
        {
            result.append(", ");
        }
        result.append(props[idx].getName());
        result.append(" = ");
        result.append(get(props[idx].getName()));
    }
    return result.toString();
}
 
Example 3
Source File: ObjectUtil.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * build a map of business object with its specified property names and corresponding values
 * 
 * @param businessObject the given business object
 * @param the specified fields that need to be included in the return map
 * @return the map of business object with its property names and values
 */
public static Map<String, Object> buildPropertyMap(Object object, List<String> keyFields) {
    DynaClass dynaClass = WrapDynaClass.createDynaClass(object.getClass());
    DynaProperty[] properties = dynaClass.getDynaProperties();
    Map<String, Object> propertyMap = new LinkedHashMap<String, Object>();

    for (DynaProperty property : properties) {
        String propertyName = property.getName();

        if (PropertyUtils.isReadable(object, propertyName) && keyFields.contains(propertyName)) {
            try {
                Object propertyValue = PropertyUtils.getProperty(object, propertyName);

                if (propertyValue != null && !StringUtils.isEmpty(propertyValue.toString())) {
                    propertyMap.put(propertyName, propertyValue);
                }
            }
            catch (Exception e) {
                LOG.info(e);
            }
        }
    }
    return propertyMap;
}
 
Example 4
Source File: ObjectUtil.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * determine if the source object has a field with null as its value
 * 
 * @param sourceObject the source object
 */
public static boolean hasNullValueField(Object sourceObject) {
    DynaClass dynaClass = WrapDynaClass.createDynaClass(sourceObject.getClass());
    DynaProperty[] properties = dynaClass.getDynaProperties();

    for (DynaProperty property : properties) {
        String propertyName = property.getName();

        if (PropertyUtils.isReadable(sourceObject, propertyName)) {
            try {
                Object propertyValue = PropertyUtils.getProperty(sourceObject, propertyName);
                if (propertyValue == null) {
                    return true;
                }
            }
            catch (Exception e) {
                LOG.info(e);
                return false;
            }
        }
    }
    return false;
}
 
Example 5
Source File: OJBUtility.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * This method builds a map of business object with its property names and values
 * 
 * @param businessObject the given business object
 * @return the map of business object with its property names and values
 */
public static LinkedHashMap buildPropertyMap(Object businessObject) {
    DynaClass dynaClass = WrapDynaClass.createDynaClass(businessObject.getClass());
    DynaProperty[] properties = dynaClass.getDynaProperties();
    LinkedHashMap propertyMap = new LinkedHashMap();

    try {
        for (int numOfProperty = 0; numOfProperty < properties.length; numOfProperty++) {
            String propertyName = properties[numOfProperty].getName();
            if (PropertyUtils.isWriteable(businessObject, propertyName)) {
                Object propertyValue = PropertyUtils.getProperty(businessObject, propertyName);
                propertyMap.put(propertyName, propertyValue);
            }
        }
    }
    catch (Exception e) {
        LOG.error("OJBUtility.buildPropertyMap()" + e);
    }
    return propertyMap;
}
 
Example 6
Source File: MultiWrapDynaBean.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new instance of {@code MultiWrapDynaBean} and initializes it
 * with the given collections of beans to be wrapped.
 *
 * @param beans the wrapped beans
 */
public MultiWrapDynaBean(final Collection<?> beans)
{
    propsToBeans = new HashMap<>();
    final Collection<DynaClass> beanClasses =
            new ArrayList<>(beans.size());

    for (final Object bean : beans)
    {
        final DynaBean dynaBean = createDynaBean(bean);
        final DynaClass beanClass = dynaBean.getDynaClass();
        for (final DynaProperty prop : beanClass.getDynaProperties())
        {
            // ensure an order of properties
            if (!propsToBeans.containsKey(prop.getName()))
            {
                propsToBeans.put(prop.getName(), dynaBean);
            }
        }
        beanClasses.add(beanClass);
    }

    dynaClass = new MultiWrapDynaClass(beanClasses);
}
 
Example 7
Source File: DynaBeanPropertyPointer.java    From commons-jxpath with Apache License 2.0 6 votes vote down vote up
public String[] getPropertyNames() {
    /* @todo do something about the sorting - LIKE WHAT? - MJB */
    if (names == null) {
        DynaClass dynaClass = dynaBean.getDynaClass();
        DynaProperty[] dynaProperties = dynaClass.getDynaProperties();
        ArrayList properties = new ArrayList(dynaProperties.length);
        for (int i = 0; i < dynaProperties.length; i++) {
            String name = dynaProperties[i].getName();
            if (!CLASS.equals(name)) {
                properties.add(name);
            }
        }
        names = (String[]) properties.toArray(new String[properties.size()]);
        Arrays.sort(names);
    }
    return names;
}
 
Example 8
Source File: SqlDynaBean.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean equals(Object obj)
{
    if (obj instanceof SqlDynaBean)
    {
        SqlDynaBean other     = (SqlDynaBean)obj;
        DynaClass   dynaClass = getDynaClass();

        if (dynaClass.equals(other.getDynaClass()))
        {
            DynaProperty[] props = dynaClass.getDynaProperties();

            for (int idx = 0; idx < props.length; idx++)
            {
                Object value      = get(props[idx].getName());
                Object otherValue = other.get(props[idx].getName());

                if (value == null)
                {
                    if (otherValue != null)
                    {
                        return false;
                    }
                }
                else
                {
                    return value.equals(otherValue);
                }
            }
            return true;
        }
    }
    return false;
}
 
Example 9
Source File: SqlDynaBean.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean equals(Object obj)
{
    if (obj instanceof SqlDynaBean)
    {
        SqlDynaBean other     = (SqlDynaBean)obj;
        DynaClass   dynaClass = getDynaClass();

        if (dynaClass.equals(other.getDynaClass()))
        {
            DynaProperty[] props = dynaClass.getDynaProperties();

            for (int idx = 0; idx < props.length; idx++)
            {
                Object value      = get(props[idx].getName());
                Object otherValue = other.get(props[idx].getName());

                if (value == null)
                {
                    if (otherValue != null)
                    {
                        return false;
                    }
                }
                else
                {
                    return value.equals(otherValue);
                }
            }
            return true;
        }
    }
    return false;
}
 
Example 10
Source File: ObjectUtil.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Populate the target object with the source object
 * 
 * @param targetObject the target object
 * @param sourceObject the source object
 */
public static void buildObject(Object targetObject, Object sourceObject) {
    DynaClass dynaClass = WrapDynaClass.createDynaClass(targetObject.getClass());
    DynaProperty[] properties = dynaClass.getDynaProperties();

    for (DynaProperty property : properties) {
        ObjectUtil.setProperty(targetObject, sourceObject, property, false);
    }
}
 
Example 11
Source File: ObjectUtil.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Populate the target object with the source object
 * 
 * @param targetObject the target object
 * @param sourceObject the source object
 */
public static void buildObjectWithoutReferenceFields(Object targetObject, Object sourceObject) {
    DynaClass dynaClass = WrapDynaClass.createDynaClass(targetObject.getClass());
    DynaProperty[] properties = dynaClass.getDynaProperties();

    for (DynaProperty property : properties) {
        ObjectUtil.setProperty(targetObject, sourceObject, property, true);
    }
}
 
Example 12
Source File: MultiWrapDynaClass.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes the members related to the properties of the wrapped classes.
 *
 * @param wrappedCls the collection with the wrapped classes
 */
private void initProperties(final Collection<? extends DynaClass> wrappedCls)
{
    for (final DynaClass cls : wrappedCls)
    {
        final DynaProperty[] props = cls.getDynaProperties();
        for (final DynaProperty p : props)
        {
            properties.add(p);
            namedProperties.put(p.getName(), p);
        }
    }
}