日期:2014-05-20 浏览次数:20999 次
public void copy(Object from, Object to, Map<String, Object> context, Collection<String> exclusions, Collection<String> inclusions) {
if (from == null || to == null) {
LOG.warn("Attempting to copy from or to a null source. This is illegal and is bein skipped. This may be due to an error in an OGNL expression, action chaining, or some other event.");
return;
}
TypeConverter conv = getTypeConverterFromContext(context);
Map contextFrom = Ognl.createDefaultContext(from);
Ognl.setTypeConverter(contextFrom, conv);
Map contextTo = Ognl.createDefaultContext(to);
Ognl.setTypeConverter(contextTo, conv);
PropertyDescriptor[] fromPds;
PropertyDescriptor[] toPds;
try {
fromPds = getPropertyDescriptors(from);
toPds = getPropertyDescriptors(to);
} catch (IntrospectionException e) {
LOG.error("An error occured", e);
return;
}
Map<String, PropertyDescriptor> toPdHash = new HashMap<String, PropertyDescriptor>();
for (PropertyDescriptor toPd : toPds) {
toPdHash.put(toPd.getName(), toPd);
}
for (PropertyDescriptor fromPd : fromPds) {
//修改部分 begin
if("targetSource".equals(fromPd.getName()) || "callback".equals(fromPd.getName())
|| "callbacks".equals(fromPd.getName())){
continue;
}
//修改部分 end
if (fromPd.getReadMethod() != null) {
boolean copy = true;
if (exclusions != null && exclusions.contains(fromPd.getName())) {
copy = false;
} else if (inclusions != null && !inclusions.contains(fromPd.getName())) {
copy = false;
}
if (copy == true) {
PropertyDescriptor toPd = toPdHash.get(fromPd.getName());
if ((toPd != null) && (toPd.getWriteMethod() != null)) {
try {
Object expr = compile(fromPd.getName());
Object value = Ognl.getValue(expr, contextFrom, from);
Ognl.setValue(expr, contextTo, to, value);
} catch (OgnlException e) {
// ignore, this is OK
}
}
}
}
}
}