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


Java ConvertUtils.lookup方法代碼示例

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


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

示例1: convertToString

import org.apache.commons.beanutils.ConvertUtils; //導入方法依賴的package包/類
public String[] convertToString(Object[] objects) {
    String[] strings = new String[objects.length];

    int i = 0;
    for (Object object : objects) {
        if (object != null) {
            Converter converter = ConvertUtils.lookup(object.getClass());
            if (converter != null) {
                strings[i++] = converter.convert(object.getClass(), object).toString();
            } else {
                strings[i++] = object.toString();
            }
        } else {
            strings[i++] = "";
        }
    }

    return strings;
}
 
開發者ID:maxdelo77,項目名稱:replyit-master-3.2-final,代碼行數:20,代碼來源:CsvExporter.java

示例2: convert

import org.apache.commons.beanutils.ConvertUtils; //導入方法依賴的package包/類
/**
 * Convert the given object to be castable to the given <code>goal</code> type.
 * 
 * @param obj
 *            the object to convert
 * @param goal
 *            the goal type
 * 
 * @return the converted object
 */
public static Object convert(Object obj, Class<?> goal) {
    if (null == obj) {
        return obj;
    } else {
        if (goal.isInstance(obj)) {
            return obj;
        } else if (asPrimitive(goal).equals(asPrimitive(obj.getClass()))) {
            return obj;
        } else {
            Converter converter = ConvertUtils.lookup(goal);
            return (null != converter) ? converter.convert(goal, obj) : obj;
        }
    }
}
 
開發者ID:Comcast,項目名稱:cereal,代碼行數:25,代碼來源:ReflectionHelper.java

示例3: convert

import org.apache.commons.beanutils.ConvertUtils; //導入方法依賴的package包/類
@Override
public Object convert(Object tagValue, MethodParam methodParam) throws ViewBlockRequiredParameter {
	Converter converter = ConvertUtils.lookup(methodParam.getTypeClass());
	if (converter != null) {
		if (tagValue != null) {
			return convertUtilsBean1.convert(tagValue, methodParam.getTypeClass());
		} else if (methodParam.getDefValue() != null) {
			return methodParam.getDefValue();
		}
		return convertUtilsBean2.convert("", methodParam.getTypeClass());
	}
	return tagValue;
}
 
開發者ID:liyiorg,項目名稱:viewblock,代碼行數:14,代碼來源:OtherRequestConvert.java

示例4: convertOmit

import org.apache.commons.beanutils.ConvertUtils; //導入方法依賴的package包/類
public Object convertOmit(Object dest, Object src, String[] omit)
        throws IllegalAccessException, InvocationTargetException {

    // Validate existence of the specified beans
    if (dest == null) {
        throw new IllegalArgumentException("No destination bean specified");
    }
    if (src == null) {
        throw new IllegalArgumentException("No origin bean specified");
    }
    if (log.isDebugEnabled()) {
        log.debug("BeanUtils.copyProperties(" + dest + ", " + src + ")");
    }
    org.apache.commons.beanutils.Converter converter= ConvertUtils.lookup(java.util.Date.class);
    System.out.println("ConvertUtils.lookup( java.util.Date.class): "+ converter);
    
    org.apache.commons.beanutils.Converter converter2= ConvertUtils.lookup(java.lang.String.class);
    System.out.println("ConvertUtils.lookup( java.lang.String.class): "+ converter2);
    // Copy the properties, converting as necessary
    if (src instanceof DynaBean) {
        copyDynaBean(dest, src);
    } else if (src instanceof Map) {
        copyMap(dest, src);
    } else /* if (src is a standard JavaBean) */{
        copyJavaBean(dest, src, omit);
    }
    return dest;
}
 
開發者ID:jbosschina,項目名稱:jcommerce,代碼行數:29,代碼來源:BeanUtilsProxy.java

示例5: convert

import org.apache.commons.beanutils.ConvertUtils; //導入方法依賴的package包/類
/**
 * オブジェクトを指定したクラスのインスタンスに変換して返します。
 * 変換の必要が無い場合はそのまま返します。
 *
 * @param expectedClass 戻り型として期待するクラス
 * @param value 変換する値
 * @return 変換後の値 (expectedClassのインスタンス)
 */
public static Object convert(Class expectedClass, Object value) {
    if (Object.class.equals(expectedClass) ||
            (value != null && expectedClass.isAssignableFrom(value.getClass()))) {
        return value;
    }
    if (String.class.equals(expectedClass)) {
        return (value != null) ? value.toString() : null;
    }
    if (Boolean.class.equals(expectedClass) || Boolean.TYPE.equals(expectedClass)) {
        if (value instanceof Boolean) {
            return value;
        }
        return Boolean.valueOf(ObjectUtil.booleanValue(value, false));
    }
    Converter converter = ConvertUtils.lookup(expectedClass);
    if (converter != null) {
    	if (value != null) {
    		return converter.convert(expectedClass, value);
    	}
    	if (expectedClass.isPrimitive() || Number.class.isAssignableFrom(expectedClass)) {
    		if (BigInteger.class.isAssignableFrom(expectedClass)) {
    			return BigInteger.ZERO;
    		} else if (BigDecimal.class.isAssignableFrom(expectedClass)) {
    			return BigDecimal.valueOf(0);
    		}
    		return converter.convert(expectedClass, value);
    	}
    }
    return value;
}
 
開發者ID:seasarorg,項目名稱:mayaa,代碼行數:39,代碼來源:ObjectUtil.java

示例6: initialMethod

import org.apache.commons.beanutils.ConvertUtils; //導入方法依賴的package包/類
/**
 * 初始化 方法參數定義
 */
private void initialMethod() {
	isvoid = method.getReturnType().getName().equals("void");
	if (method.getParameterTypes().length == 0) {
		return;
	}
	methodParamMap = new LinkedHashMap<String, MethodParam>();
	methodParamList = new ArrayList<MethodParam>();
	Paranamer paranamer = new BytecodeReadingParanamer();
	String[] parameterNames = paranamer.lookupParameterNames(method);
	Annotation[][] pas = method.getParameterAnnotations();
	int i = 0;
	for (Class<?> typeClass : method.getParameterTypes()) {
		MethodParam mp = new MethodParam();
		String name = parameterNames[i];

		Convert convert = CONVERT_MAP.get(typeClass);
		if (typeClass.equals(BModelMap.class)) {
			if (modelMapParamIndex != null) {
				logger.error("view block only set one BModelMap");
			}
			modelMapParamIndex = i;
		} else if (convert == null) {
			convert = CONVERT_MAP.get(BRequestParam.class);
			for (Annotation a : pas[i]) {
				if (a.annotationType().equals(BRequestParam.class)) {
					BRequestParam p = (BRequestParam) a;
					boolean required = false;
					Object defValue = null;
					// RequestParam 注解
					if (p != null) {
						if (!"".equals(p.value())) {
							name = p.value();
						}
						if (!p.defaultValue().equals(ValueConstants.DEFAULT_NONE)) {
							if (ConvertUtils.lookup(typeClass) != null) {
								defValue = ConvertUtils.convert(p.defaultValue(), typeClass);
							}
						}
						required = p.required();
					}

					// others param
					mp.setRequired(required);
					mp.setDefValue(defValue);
					break;
				} else if (a.annotationType().equals(BModelAttribute.class)) {
					mp.setModelAttribute(true);
					break;
				}
			}
		}
		mp.setName(name);
		mp.setIndex(i);
		mp.setConvert(convert);
		mp.setTypeClass(typeClass);
		methodParamMap.put(mp.getName(), mp);
		methodParamList.add(mp);
		i++;
	}
}
 
開發者ID:liyiorg,項目名稱:viewblock,代碼行數:64,代碼來源:ViewblockObject.java


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