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


Java PropertyUtilsBean.getProperty方法代码示例

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


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

示例1: fillBeanDefaults

import org.apache.commons.beanutils.PropertyUtilsBean; //导入方法依赖的package包/类
/**
     * Fills the bean with the default values, by calling all the getters and setting the returned value.
     * @param bean
     * @return
     * @throws IllegalAccessException
     * @throws NoSuchMethodException
     * @throws InvocationTargetException
     */
    public static DiffableBean fillBeanDefaults(DiffableBean bean) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        BeanMap map = new BeanMap(bean);
        PropertyUtilsBean propUtils = new PropertyUtilsBean();

        for (Object propNameObject : map.keySet()) {
            String propertyName = (String) propNameObject;
            Object property1 = propUtils.getProperty(bean, propertyName);
            if(property1 == null || !DiffableBean.class.isAssignableFrom(property1.getClass())) {
                if(property1 != null) {
//					System.out.println(propertyName + ": " + property1.toString());
                    org.apache.commons.beanutils.BeanUtils.setProperty(bean, propertyName, property1);
                }
            } else {
//				System.out.println("RECURSIVE: " + propertyName);
                property1 = fillBeanDefaults((DiffableBean) property1);
                org.apache.commons.beanutils.BeanUtils.setProperty(bean, propertyName, property1);
            }
        }
        return bean;
    }
 
开发者ID:miguel-porto,项目名称:flora-on-server,代码行数:29,代码来源:BeanUtils.java

示例2: updateBean

import org.apache.commons.beanutils.PropertyUtilsBean; //导入方法依赖的package包/类
/**
 * Updates a oldBean with all non-null values in the newBean.
 * @param cls
 * @param ignoreProperties
 * @param oldBean
 * @param newBean
 * @param <T>
 * @return
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 * @throws NoSuchMethodException
 * @throws FloraOnException
 * @throws InstantiationException
 */
public static <T extends DiffableBean> T updateBean(Class<T> cls, Collection<String> ignoreProperties, T oldBean, T newBean) throws IllegalAccessException
        , InvocationTargetException, NoSuchMethodException, FloraOnException, InstantiationException {
    BeanMap propertyMap = new BeanMap(oldBean);    // we assume beans are the same class! so we take the first as a model
    PropertyUtilsBean propUtils = new PropertyUtilsBean();
    BeanUtilsBean bub = createBeanUtilsNull();

    T out = cls.newInstance();

    for (Object propNameObject : propertyMap.keySet()) {
        String propertyName = (String) propNameObject;
        if(ignoreProperties != null && ignoreProperties.contains(propertyName)) continue;
        System.out.println("PROP: " + propertyName);
        Object newProperty;

        newProperty = propUtils.getProperty(newBean, propertyName);

        if(newProperty == null)
            bub.setProperty(out, propertyName, propUtils.getProperty(oldBean, propertyName));
        else
            bub.setProperty(out, propertyName, newProperty);
        // TODO: nested beans
    }
    return out;
}
 
开发者ID:miguel-porto,项目名称:flora-on-server,代码行数:39,代码来源:BeanUtils.java

示例3: getValueOfProperty

import org.apache.commons.beanutils.PropertyUtilsBean; //导入方法依赖的package包/类
private Color getValueOfProperty() {
	try {
		PropertyUtilsBean p = new PropertyUtilsBean();
		return (Color) p.getProperty(bean, property);
	} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:Transkribus,项目名称:TranskribusSwtGui,代码行数:9,代码来源:BindColorToButtonListener.java

示例4: citationVisitor

import org.apache.commons.beanutils.PropertyUtilsBean; //导入方法依赖的package包/类
/**
     * A nested citation visitor that does the given action on each visited citation.
     * @param bean The root document
     * @param processor The action to perform
     */
    private void citationVisitor(Object bean, CitationProcessor processor) {
        PropertyUtilsBean propUtils = new PropertyUtilsBean();
        BeanMap propertyMap = new BeanMap(bean);    // beans are all same class! so we take the first as a model
        for (Object propNameObject : propertyMap.keySet()) {
            String propertyName = (String) propNameObject;
            Object property;
            try {
                property = propUtils.getProperty(bean, propertyName);
//                    System.out.println(propertyName+": "+property);
            } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
                e.printStackTrace();
                return;
            }
            if(property == null) continue;

            if(DiffableBean.class.isAssignableFrom(property.getClass()))
                citationVisitor(property, processor);
            else if(this.collectFrom.isAssignableFrom(property.getClass())) {
//                System.out.println("Collecting from " + propertyName + " - "+property.getClass());
                Document d = Jsoup.parse(property.toString());
                Elements citations = d.select("span.reference");
                for(Element el : citations)
                    processor.process(bean, propertyName, d, el);
            }
        }
    }
 
开发者ID:miguel-porto,项目名称:flora-on-server,代码行数:32,代码来源:BibliographyCompiler.java

示例5: diffBeans

import org.apache.commons.beanutils.PropertyUtilsBean; //导入方法依赖的package包/类
/**
     * Compares a new version of a java bean with an old version. <b>Null fields in the new version are excluded from the comparison</b>.
     * This function assumes that the two beans are of the <b>same class</b>.
     * @param oldObject
     * @param newObject
     * @return a map with the names of the fields that are different, and their new values.
     * @throws IllegalAccessException
     * @throws InvocationTargetException
     * @throws NoSuchMethodException
     */
    public static Map<String, Object> diffBeans(DiffableBean oldObject, DiffableBean newObject) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
        BeanMap map = new BeanMap(oldObject);
        Map<String, Object> out = new HashMap<>();

        PropertyUtilsBean propUtils = new PropertyUtilsBean();

        for (Object propNameObject : map.keySet()) {
            String propertyName = (String) propNameObject;
            Object property1 = propUtils.getProperty(oldObject, propertyName);
            Object property2 = propUtils.getProperty(newObject, propertyName);
            if(property2 == null) continue;
            if(property2.getClass().isArray() && ((Object[]) property2).length == 0) continue;
            if(List.class.isAssignableFrom(property2.getClass()) && ((List) property2).size() == 0) continue;
            if(property1 != null && DiffableBean.class.isAssignableFrom(property1.getClass())
                    && DiffableBean.class.isAssignableFrom(property2.getClass())) {
                //out.put(propertyName, ((DiffableBean) property1).compareToBean(property2));
                Map<String, Object> tmp = diffBeans((DiffableBean) property1, (DiffableBean) property2);
                if(tmp.size() > 0) out.put(propertyName, tmp);
            } else if (property1 == null || !property1.equals(property2)) {
                if(property1 != null && property1.getClass().isArray() && property2.getClass().isArray()) {
                    if(!Arrays.equals((Object[]) property1, (Object[]) property2)) {
                        out.put(propertyName, property2);
//						System.out.println("> ARRAY: " + propertyName + " is different (oldValue=\"" + property1 + "\", newValue=\"" + property2 + "\")");
                    }
                } else {
                    out.put(propertyName, property2);
//					System.out.println("> " + propertyName + " is different (oldValue=\"" + property1 + "\", newValue=\"" + property2 + "\")");
                }
            }
        }
        return out;
    }
 
开发者ID:miguel-porto,项目名称:flora-on-server,代码行数:43,代码来源:BeanUtils.java


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