當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。