当前位置: 首页>>代码示例>>Java>>正文


Java DynaClass类代码示例

本文整理汇总了Java中org.apache.commons.beanutils.DynaClass的典型用法代码示例。如果您正苦于以下问题:Java DynaClass类的具体用法?Java DynaClass怎么用?Java DynaClass使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DynaClass类属于org.apache.commons.beanutils包,在下文中一共展示了DynaClass类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toString

import org.apache.commons.beanutils.DynaClass; //导入依赖的package包/类
/**
 * {@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();
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:24,代码来源:SqlDynaBean.java

示例2: buildPropertyMap

import org.apache.commons.beanutils.DynaClass; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:VU-libtech,项目名称:OLE-INST,代码行数:31,代码来源:ObjectUtil.java

示例3: hasNullValueField

import org.apache.commons.beanutils.DynaClass; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:VU-libtech,项目名称:OLE-INST,代码行数:28,代码来源:ObjectUtil.java

示例4: buildPropertyMap

import org.apache.commons.beanutils.DynaClass; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:VU-libtech,项目名称:OLE-INST,代码行数:26,代码来源:OJBUtility.java

示例5: testDynaBean

import org.apache.commons.beanutils.DynaClass; //导入依赖的package包/类
public void testDynaBean() throws Exception
{
    checkBoundaryConditions(PersistentFieldDynaBeanImpl.class, false);

    DynaClass dynaClass = createDynaClass();
    DynaBean bean = dynaClass.newInstance();
    bean.set("name", "testDynaBean");

    PersistentField pf = new PersistentFieldDynaBeanImpl(String.class, "name");
    String result = (String) pf.get(bean);
    assertNotNull(result);
    assertEquals("testDynaBean", result);

    pf.set(bean, "XXXX");
    result = (String) pf.get(bean);
    assertNotNull(result);
    assertEquals("XXXX", result);
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:19,代码来源:PersistentFieldTest.java

示例6: testAutoProxyWithDyna

import org.apache.commons.beanutils.DynaClass; //导入依赖的package包/类
public void testAutoProxyWithDyna() throws Exception
{
    DynaClass dynaClass = createDynaClass();
    DynaBean bean = dynaClass.newInstance();
    bean.set("name", "testDynaBean");

    PersistentField pf = new PersistentFieldAutoProxyImpl(String.class, "name");
    String result = (String) pf.get(bean);
    assertNotNull(result);
    assertEquals("testDynaBean", result);

    pf.set(bean, "XXXX");
    result = (String) pf.get(bean);
    assertNotNull(result);
    assertEquals("XXXX", result);
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:17,代码来源:PersistentFieldTest.java

示例7: buildPropertyMap

import org.apache.commons.beanutils.DynaClass; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:kuali,项目名称:kfs,代码行数:26,代码来源:OJBUtility.java

示例8: toString

import org.apache.commons.beanutils.DynaClass; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
public String toString()
{
    StringBuffer   result = new StringBuffer();
    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();
}
 
开发者ID:flex-rental-solutions,项目名称:apache-ddlutils,代码行数:24,代码来源:SqlDynaBean.java

示例9: definePropertyType

import org.apache.commons.beanutils.DynaClass; //导入依赖的package包/类
/**
 * Calculate the property type.
 *
 * @param target The bean
 * @param name The property name
 * @param propName The Simple name of target property
 * @return The property's type
 *
 * @throws IllegalAccessException if the caller does not have
 *  access to the property accessor method
 * @throws InvocationTargetException if the property accessor method
 *  throws an exception
 */
protected Class<?> definePropertyType(final Object target, final String name, final String propName)
        throws IllegalAccessException, InvocationTargetException {

    Class<?> type = null;               // Java type of target property

    if (target instanceof DynaBean) {
        final DynaClass dynaClass = ((DynaBean) target).getDynaClass();
        final DynaProperty dynaProperty = dynaClass.getDynaProperty(propName);
        if (dynaProperty == null) {
            return null; // Skip this property setter
        }
        type = dynaProperty.getType();
    }
    else {
        PropertyDescriptor descriptor = null;
        try {
            descriptor =
                    getPropertyUtils().getPropertyDescriptor(target, name);
            if (descriptor == null) {
                return null; // Skip this property setter
            }
        }
        catch (final NoSuchMethodException e) {
            return null; // Skip this property setter
        }
        if (descriptor instanceof MappedPropertyDescriptor) {
            type = ((MappedPropertyDescriptor) descriptor).
                    getMappedPropertyType();
        }
        else if (descriptor instanceof IndexedPropertyDescriptor) {
            type = ((IndexedPropertyDescriptor) descriptor).
                    getIndexedPropertyType();
        }
        else {
            type = descriptor.getPropertyType();
        }
    }
    return type;
}
 
开发者ID:yippeesoft,项目名称:NotifyTools,代码行数:53,代码来源:LocaleBeanUtilsBean.java

示例10: getDynaClass

import org.apache.commons.beanutils.DynaClass; //导入依赖的package包/类
/**
 * Returns the {@link SqlDynaClass} for the given bean.
 * 
 * @param dynaBean The bean
 * @return The dyna bean class
 */
public SqlDynaClass getDynaClass(DynaBean dynaBean) throws SqlDynaException
{
    DynaClass dynaClass = dynaBean.getDynaClass();

    if (dynaClass instanceof SqlDynaClass)
    {
        return (SqlDynaClass)dynaClass;
    }
    else
    {
        // TODO: we could autogenerate an SqlDynaClass here ?
        throw new SqlDynaException("The dyna bean is not an instance of a SqlDynaClass");
    }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:21,代码来源:DynaClassCache.java

示例11: equals

import org.apache.commons.beanutils.DynaClass; //导入依赖的package包/类
/**
 * {@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;
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:37,代码来源:SqlDynaBean.java

示例12: getDynaClass

import org.apache.commons.beanutils.DynaClass; //导入依赖的package包/类
public DynaClass getDynaClass() {
    final LazyDynaClass dynaClass = new LazyDynaClass();
    for (final Map.Entry<String, Class<?>> entry : propertyTypes.entrySet()) {
        dynaClass.add(entry.getKey(), entry.getValue());
    }
    return dynaClass;
}
 
开发者ID:mateli,项目名称:OpenCyclos,代码行数:8,代码来源:MapBean.java

示例13: getFieldType

import org.apache.commons.beanutils.DynaClass; //导入依赖的package包/类
public Class<?> getFieldType(Object obj, String name) {
    DynaClass dynaClass = ((DynaBean) obj).getDynaClass();
    DynaProperty dynaProperty = dynaClass.getDynaProperty(name);
    if (dynaProperty == null) {
        throw new FieldnameNotFoundException("DynaBean: Could not find this fieldName ("+name+") on the target object: " + obj, name, null);
    }
    return dynaProperty.getType();
}
 
开发者ID:azeckoski,项目名称:reflectutils,代码行数:9,代码来源:DynaBeanAdapter.java

示例14: getDynaClass

import org.apache.commons.beanutils.DynaClass; //导入依赖的package包/类
@Override
public DynaClass getDynaClass() {
    if (dynaClass == null) {
        dynaClass = new JSDynaClass(delegate, REPORT_DYNA_CLASS_PREFIX + IdGenerator.genStringId());
    }
    return dynaClass;
}
 
开发者ID:marat-gainullin,项目名称:platypus-js,代码行数:8,代码来源:JSDynaBean.java

示例15: buildObject

import org.apache.commons.beanutils.DynaClass; //导入依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:VU-libtech,项目名称:OLE-INST,代码行数:15,代码来源:ObjectUtil.java


注:本文中的org.apache.commons.beanutils.DynaClass类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。