當前位置: 首頁>>代碼示例>>Java>>正文


Java PropertyUtils.getPropertyType方法代碼示例

本文整理匯總了Java中org.apache.commons.beanutils.PropertyUtils.getPropertyType方法的典型用法代碼示例。如果您正苦於以下問題:Java PropertyUtils.getPropertyType方法的具體用法?Java PropertyUtils.getPropertyType怎麽用?Java PropertyUtils.getPropertyType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.beanutils.PropertyUtils的用法示例。


在下文中一共展示了PropertyUtils.getPropertyType方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getAttributeType

import org.apache.commons.beanutils.PropertyUtils; //導入方法依賴的package包/類
public Class<?> getAttributeType(String name) {
	if (!hasAttribute(name))
		return null;

	if (isPredefinedAttribute(name)) { // get type via reflection for
										// predefined attributes
		try {
			return PropertyUtils.getPropertyType(this, name);
		} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
			logger.error(e.getMessage(), e);
			return null;
		}
	} else {
		CustomTagAttribute att = getAttribute(name);
		return att.getType();
	}
}
 
開發者ID:Transkribus,項目名稱:TranskribusCore,代碼行數:18,代碼來源:CustomTag.java

示例2: read

import org.apache.commons.beanutils.PropertyUtils; //導入方法依賴的package包/類
/**
 * Reads a single object from a SCV line
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public List<E> read(final BufferedReader in) throws CSVParseException {
    int linesIndex = 0;
    final List<E> list = new LinkedList<E>();
    try {

        List<String> values;
        while ((values = readLine(in)) != null) {
            linesIndex++;
            // Ignore the header lines
            if (headerLines >= linesIndex) {
                continue;
            }
            final E object = elementClass.newInstance();
            final int size = Math.min(columns.size(), values.size());
            for (int i = 0; i < size; i++) {
                final Column column = columns.get(i);
                final String property = column.getProperty();
                if (property == null) {
                    continue;
                }
                final Class type = PropertyUtils.getPropertyType(object, property);
                final String stringValue = values.get(i);
                final Object objectValue = PropertyHelper.getAsObject(type, stringValue, column.getConverter());
                PropertyHelper.set(object, property, objectValue);
            }
            list.add(object);
        }
        return list;
    } catch (final Exception e) {
        throw new CSVParseException(linesIndex);
    }
}
 
開發者ID:mateli,項目名稱:OpenCyclos,代碼行數:37,代碼來源:CSVReader.java

示例3: populate

import org.apache.commons.beanutils.PropertyUtils; //導入方法依賴的package包/類
/**
 * Populate a settings object, using a Map of converters, and a Map of values. Only 2 levels of beans are supported, ie, xxxSettings.x.y. If there
 * were a nested bean on x, making it be xxxSettings.x.y.z, z would be ignored
 */
private void populate(final Object settings, final Map<String, String> values) {
    for (final Map.Entry<String, Converter<?>> entry : converters.entrySet()) {
        final String name = entry.getKey();
        final Converter<?> converter = entry.getValue();
        if (values.containsKey(name)) {
            final String value = values.get(name);
            final Object realValue = converter.valueOf(value);
            // Check if there is a nested object
            if (name.contains(".")) {
                final String first = PropertyHelper.firstProperty(name);
                // No bean: instantiate it
                if (PropertyHelper.get(settings, first) == null) {
                    try {
                        final Class<?> type = PropertyUtils.getPropertyType(settings, first);
                        final Object bean = type.newInstance();
                        PropertyHelper.set(settings, first, bean);
                    } catch (final Exception e) {
                        LOGGER.warn("Error while setting nested settings bean", e);
                        throw new IllegalStateException();
                    }
                }
            }
            PropertyHelper.set(settings, name, realValue);
        }
    }
}
 
開發者ID:mateli,項目名稱:OpenCyclos,代碼行數:31,代碼來源:BaseSettingsHandler.java

示例4: setProperty

import org.apache.commons.beanutils.PropertyUtils; //導入方法依賴的package包/類
public static void setProperty(Object bean, Object name, Object value) {
	try {
		if (bean instanceof Class) {
			Field f = ((Class<?>) bean).getDeclaredField(name.toString());
			f.set(null, value);
		}else if(bean instanceof Map ){
			((Map<Object,Object>)bean).put(name, value);
	    } else {
	    	Class<?> filedClass = PropertyUtils.getPropertyType(bean, name.toString());
			PropertyUtils.setProperty(bean, name.toString(),ExpressUtil.castObject(value, filedClass, false));
		}
	} catch (Exception e) {
		throw new RuntimeException("不能訪問" + bean + "的property:" + name,e);
	}
}
 
開發者ID:alibaba,項目名稱:QLExpress,代碼行數:16,代碼來源:ExpressUtil.java

示例5: copyProperties

import org.apache.commons.beanutils.PropertyUtils; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public void copyProperties(Object dest, Object orig) throws IllegalAccessException, InvocationTargetException {
    PropertyDescriptor[] origDescriptors =
            PropertyUtils.getPropertyDescriptors(orig);
    for (PropertyDescriptor origDescriptor : origDescriptors) {
        String name = origDescriptor.getName();
        if ("class".equals(name)) {
            continue; // No point in trying to set an object's class
        }
        if (PropertyUtils.isReadable(orig, name) &&
                PropertyUtils.isWriteable(dest, name)) {


            try {
                Class origPropClass = PropertyUtils.getPropertyType(orig, name);
                Class destPropClass = PropertyUtils.getPropertyType(dest, name);

                if (destPropClass.isAssignableFrom(origPropClass)) {
                    Object value =
                            PropertyUtils.getSimpleProperty(orig, name);
                    BeanUtils.copyProperty(dest, name, value);
                }
            } catch (NoSuchMethodException e) {
                // Should not happen
            }
        }
    }
}
 
開發者ID:nfl,項目名稱:audible,代碼行數:29,代碼來源:TypeSafeCopy.java

示例6: getMappedValues

import org.apache.commons.beanutils.PropertyUtils; //導入方法依賴的package包/類
public static MultivaluedMap<String, String> getMappedValues(Object object) {
	MultivaluedMap<String, String> parameters = new MultivaluedMapImpl();

	for (Method method : object.getClass().getMethods()) {
		if (method.getName().indexOf("set") > -1) {
			String propertyName = method.getName().replace("set", "").toLowerCase();
			try {
				Object value = PropertyUtils.getProperty(object, propertyName);
				if (value != null) {
					Class<?> pt = PropertyUtils.getPropertyType(object, propertyName);
					if (java.util.Date.class.equals(pt)) {
						Date dt = (Date) value;
						DateFormat df = new SimpleDateFormat(TIMESTAMP_DATE_PATTERN);
						String dateAsString = df.format(dt);
						parameters.add(propertyName, dateAsString);
					} else if (pt.isArray()) {
						List<Object> objectList = Arrays.asList((Object[]) value);
						String csvString = Joiner.on(',').join(objectList);
						parameters.add(propertyName, csvString);
					} else {
						parameters.add(propertyName, value.toString());
					}
				}
			} catch (Exception e) {
				log.error(e.toString());
			}
		}
	}
	return parameters;
}
 
開發者ID:mrisney,項目名稱:twitter-java-ads-sdk,代碼行數:31,代碼來源:ParameterUtils.java

示例7: getUpdateValues

import org.apache.commons.beanutils.PropertyUtils; //導入方法依賴的package包/類
public static MultivaluedMap<String, String> getUpdateValues(Object object) {

		MultivaluedMap<String, String> parameters = new MultivaluedMapImpl();

		for (Field field : object.getClass().getDeclaredFields()) {
			if (field.isAnnotationPresent(com.steelhouse.twitter.ads.annotations.Updatable.class)) {

				try {
					String propertyName = field.getName().charAt(0) + field.getName().substring(1);
					Object value = PropertyUtils.getProperty(object, propertyName);

					if (value != null) {
						Class<?> pt = PropertyUtils.getPropertyType(object, propertyName);
						if (java.util.Date.class.equals(pt)) {
							Date dt = (Date) value;
							DateFormat df = new SimpleDateFormat(TIMESTAMP_DATE_PATTERN);
							String dateAsString = df.format(dt);
							parameters.add(propertyName, dateAsString);
						} else if (pt.isArray()) {
							List<Object> objectList = Arrays.asList((Object[]) value);
							String csvString = Joiner.on(',').join(objectList);
							parameters.add(propertyName, csvString);
						} else {
							String propertyString = URLEncoder.encode(value.toString(), "UTF-8").replaceAll("\\+","%20");
							parameters.add(propertyName, propertyString);
						}
					}
				} catch (Exception e) {
					log.error(e.toString());
				}
			}
		}
		return parameters;
	}
 
開發者ID:mrisney,項目名稱:twitter-java-ads-sdk,代碼行數:35,代碼來源:ParameterUtils.java

示例8: copyMap2Bean

import org.apache.commons.beanutils.PropertyUtils; //導入方法依賴的package包/類
/**
 * Map內的key與Bean中屬性相同的內容複製到BEAN中
 * 對於存在空值的取默認值
 * @param bean Object
 * @param properties Map
 * @param defaultValue String
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 */
public static void copyMap2Bean(Object bean, Map properties, String defaultValue) throws
    IllegalAccessException, InvocationTargetException {
    // Do nothing unless both arguments have been specified
    if ( (bean == null) || (properties == null)) {
        return;
    }
    // Loop through the property name/value pairs to be set
    Iterator names = properties.keySet().iterator();
    while (names.hasNext()) {
        String name = (String) names.next();
        // Identify the property name and value(s) to be assigned
        if (name == null) {
            continue;
        }
        Object value = properties.get(name);
        try {
            Class clazz = PropertyUtils.getPropertyType(bean, name);
            if (null == clazz) {
                continue;
            }
            String className = clazz.getName();
            if (className.equalsIgnoreCase("java.sql.Timestamp")) {
                if (value == null || value.equals("")) {
                    continue;
                }
            }
            if (className.equalsIgnoreCase("java.lang.String")) {
                if (value == null) {
                    value = defaultValue;
                }
            }
            getInstance().setSimpleProperty(bean, name, value);
        }
        catch (NoSuchMethodException e) {
            continue;
        }
    }
}
 
開發者ID:tzou24,項目名稱:abina-common-util,代碼行數:48,代碼來源:ParamsUtils.java


注:本文中的org.apache.commons.beanutils.PropertyUtils.getPropertyType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。