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


Java DynaProperty.getType方法代码示例

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


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

示例1: set

import org.apache.commons.beanutils.DynaProperty; //导入方法依赖的package包/类
/**
 * <p>Set the value of a simple property with the specified name.</p>
 *
 * @param name Name of the property whose value is to be set
 * @param value Value to which this property is to be set
 *
 * @exception ConversionException if the specified value cannot be
 *  converted to the type required for this property
 * @exception IllegalArgumentException if there is no property
 *  of the specified name
 * @exception NullPointerException if the type specified for the
 *  property is invalid
 * @exception NullPointerException if an attempt is made to set a
 *  primitive property to null
 */
public void set(String name, Object value) {

    DynaProperty descriptor = getDynaProperty(name);
    if (descriptor.getType() == null) {
        throw new NullPointerException
            ("The type for property " + name + " is invalid");
    }
    if (value == null) {
        if (descriptor.getType().isPrimitive()) {
            throw new NullPointerException
                ("Primitive value for '" + name + "'");
        }
    } else if (!isDynaAssignable(descriptor.getType(), value.getClass())) {
        throw new ConversionException
            ("Cannot assign value of type '" +
             value.getClass().getName() +
             "' to property '" + name + "' of type '" +
             descriptor.getType().getName() + "'");
    }
    dynaValues.put(name, value);

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:38,代码来源:DynaActionForm.java

示例2: set

import org.apache.commons.beanutils.DynaProperty; //导入方法依赖的package包/类
/**
 * <p>Set the value of a simple property with the specified name.</p>
 *
 * @param name  Name of the property whose value is to be set
 * @param value Value to which this property is to be set
 * @throws ConversionException      if the specified value cannot be
 *                                  converted to the type required for
 *                                  this property
 * @throws IllegalArgumentException if there is no property of the
 *                                  specified name
 * @throws NullPointerException     if the type specified for the property
 *                                  is invalid
 * @throws NullPointerException     if an attempt is made to set a
 *                                  primitive property to null
 */
public void set(String name, Object value) {
    DynaProperty descriptor = getDynaProperty(name);

    if (descriptor.getType() == null) {
        throw new NullPointerException("The type for property " + name
            + " is invalid");
    }

    if (value == null) {
        if (descriptor.getType().isPrimitive()) {
            throw new NullPointerException("Primitive value for '" + name
                + "'");
        }
    } else if (!isDynaAssignable(descriptor.getType(), value.getClass())) {
        throw new ConversionException("Cannot assign value of type '"
            + value.getClass().getName() + "' to property '" + name
            + "' of type '" + descriptor.getType().getName() + "'");
    }

    dynaValues.put(name, value);
}
 
开发者ID:SonarSource,项目名称:sonar-scanner-maven,代码行数:37,代码来源:DynaActionForm.java

示例3: get

import org.apache.commons.beanutils.DynaProperty; //导入方法依赖的package包/类
public Object get(String name, int index) {
    DynaProperty dynaProperty = getDynaProperty(name);

    Class type = dynaProperty.getType();
    if (!type.isArray() && !List.class.isAssignableFrom(type)) {
        throw new MorphException("Non-Indexed property name: " + name + " index: " + index);
    }

    Object value = dynaValues.get(name);

    if (value.getClass()
        .isArray()) {
        value = Array.get(value, index);
    } else if (value instanceof List) {
        value = ((List) value).get(index);
    }

    return value;
}
 
开发者ID:aalmiray,项目名称:ezmorph,代码行数:20,代码来源:MorphDynaBean.java

示例4: getPropType

import org.apache.commons.beanutils.DynaProperty; //导入方法依赖的package包/类
public Class getPropType(final String propertyName) {
    final String propName = propertyName.toString();
    final DynaProperty dynaProperty = getDynaClass().getDynaProperty(propName);
    final Class<?> type;
    if (dynaProperty != null)
        type = dynaProperty.getType();
    else if (nestedProps.contains(propName))
        type = getNestedPropType(propName);
    else
        throw new IllegalArgumentException("Wrong propertyId");

    if (type.isPrimitive()) {
        // Vaadin can't handle primitive types in _all_ places, so use
        // wrappers instead. FieldGroup works, but e.g. Table in _editable_
        // mode fails for some reason
        return ClassUtils.primitiveToWrapper(type);
    }
    return type;

}
 
开发者ID:ExtaSoft,项目名称:extacrm,代码行数:21,代码来源:JpaPropertyProvider.java

示例5: getPropertyIds

import org.apache.commons.beanutils.DynaProperty; //导入方法依赖的package包/类
public Collection<String> getPropertyIds() {
    final ArrayList<String> properties = new ArrayList<String>();
    if (getDynaClass() != null) {
        for (final DynaProperty db : getDynaClass().getDynaProperties()) {
            if (db.getType() != null) {
                properties.add(db.getName());
            } else {
                // type may be null in some cases
                Logger.getLogger(JpaPropertyProvider.class.getName()).log(
                        Level.FINE, "Type not detected for property {0}",
                        db.getName());
            }
        }
        properties.remove("class");
        properties.addAll(nestedProps);
    }
    return properties;

}
 
开发者ID:ExtaSoft,项目名称:extacrm,代码行数:20,代码来源:JpaPropertyProvider.java

示例6: definePropertyType

import org.apache.commons.beanutils.DynaProperty; //导入方法依赖的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

示例7: getFieldType

import org.apache.commons.beanutils.DynaProperty; //导入方法依赖的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

示例8: contains

import org.apache.commons.beanutils.DynaProperty; //导入方法依赖的package包/类
public boolean contains(String name, String key) {
    DynaProperty dynaProperty = getDynaProperty(name);

    Class type = dynaProperty.getType();
    if (!Map.class.isAssignableFrom(type)) {
        throw new MorphException("Non-Mapped property name: " + name + " key: " + key);
    }

    Object value = dynaValues.get(name);
    if (value == null) {
        value = new HashMap();
        dynaValues.put(name, value);
    }
    return ((Map) value).containsKey(key);
}
 
开发者ID:aalmiray,项目名称:ezmorph,代码行数:16,代码来源:MorphDynaBean.java

示例9: remove

import org.apache.commons.beanutils.DynaProperty; //导入方法依赖的package包/类
public void remove(String name, String key) {
    DynaProperty dynaProperty = getDynaProperty(name);

    Class type = dynaProperty.getType();
    if (!Map.class.isAssignableFrom(type)) {
        throw new MorphException("Non-Mapped property name: " + name + " key: " + key);
    }

    Object value = dynaValues.get(name);
    if (value == null) {
        value = new HashMap();
        dynaValues.put(name, value);
    }
    ((Map) value).remove(key);
}
 
开发者ID:aalmiray,项目名称:ezmorph,代码行数:16,代码来源:MorphDynaBean.java

示例10: set

import org.apache.commons.beanutils.DynaProperty; //导入方法依赖的package包/类
public void set(String name, int index, Object value) {
    DynaProperty dynaProperty = getDynaProperty(name);

    Class type = dynaProperty.getType();
    if (!type.isArray() && !List.class.isAssignableFrom(type)) {
        throw new MorphException("Non-Indexed property name: " + name + " index: " + index);
    }

    Object prop = dynaValues.get(name);
    if (prop == null) {
        if (List.class.isAssignableFrom(type)) {
            prop = new ArrayList();
        } else {
            prop = Array.newInstance(type.getComponentType(), index + 1);
        }
        dynaValues.put(name, prop);
    }

    if (prop.getClass()
        .isArray()) {
        if (index >= Array.getLength(prop)) {
            Object tmp = Array.newInstance(type.getComponentType(), index + 1);
            System.arraycopy(prop, 0, tmp, 0, Array.getLength(prop));
            prop = tmp;
            dynaValues.put(name, tmp);
        }
        Array.set(prop, index, value);
    } else if (prop instanceof List) {
        List l = (List) prop;
        if (index >= l.size()) {
            for (int i = l.size(); i <= index + 1; i++) {
                l.add(null);
            }
        }
        ((List) prop).set(index, value);
    }
}
 
开发者ID:aalmiray,项目名称:ezmorph,代码行数:38,代码来源:MorphDynaBean.java

示例11: morph

import org.apache.commons.beanutils.DynaProperty; //导入方法依赖的package包/类
public Object morph(Object sourceBean) {
    if (sourceBean == null) {
        return null;
    }
    if (!supports(sourceBean.getClass())) {
        throw new MorphException("unsupported class: " + sourceBean.getClass()
            .getName());
    }

    Object targetBean = null;

    try {
        targetBean = beanClass.newInstance();
        PropertyDescriptor[] targetPds = PropertyUtils.getPropertyDescriptors(beanClass);
        for (int i = 0; i < targetPds.length; i++) {
            PropertyDescriptor targetPd = targetPds[i];
            String name = targetPd.getName();
            if (targetPd.getWriteMethod() == null) {
                log.info("Property '" + beanClass.getName() + "." + name
                    + "' has no write method. SKIPPED.");
                continue;
            }

            Class sourceType = null;
            if (sourceBean instanceof DynaBean) {
                DynaBean dynaBean = (DynaBean) sourceBean;
                DynaProperty dynaProperty = dynaBean.getDynaClass()
                    .getDynaProperty(name);
                if (dynaProperty == null) {
                    log.warn("DynaProperty '" + name + "' does not exist. SKIPPED.");
                    continue;
                }
                sourceType = dynaProperty.getType();
            } else {
                PropertyDescriptor sourcePd = PropertyUtils.getPropertyDescriptor(sourceBean, name);
                if (sourcePd == null) {
                    log.warn("Property '" + sourceBean.getClass()
                        .getName() + "." + name + "' does not exist. SKIPPED.");
                    continue;
                } else if (sourcePd.getReadMethod() == null) {
                    log.warn("Property '" + sourceBean.getClass()
                        .getName() + "." + name + "' has no read method. SKIPPED.");
                    continue;
                }
                sourceType = sourcePd.getPropertyType();
            }

            Class targetType = targetPd.getPropertyType();
            Object value = PropertyUtils.getProperty(sourceBean, name);
            setProperty(targetBean, name, sourceType, targetType, value);
        }
    } catch (MorphException me) {
        throw me;
    } catch (Exception e) {
        throw new MorphException(e);
    }

    return targetBean;
}
 
开发者ID:aalmiray,项目名称:ezmorph,代码行数:60,代码来源:BeanMorpher.java


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