本文整理汇总了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;
}
示例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;
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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++;
}
}