I'm trying to implement the type conversion field message reporting, but
I'm having an issue with the code. Here's the main method from Xwork
Converter:
public Object convertValue(Map context, Object object, Member
member, String property, Object value, Class toClass) {
if (value == null) {
return null;
}
//
// Process the conversion using the default mappings, if one
exists
//
TypeConverter tc = null;
// allow this method to be called without any context
// i.e. it can be called with as little as "Object value" and
"Class toClass"
if ((context != null) && (object != null)) {
Class clazz = null;
OgnlContext ognlContext = (OgnlContext) context;
Evaluation eval = ognlContext.getCurrentEvaluation();
if (eval == null) {
eval = ognlContext.getLastEvaluation();
// since the upgrade to ognl-2.6.3.jar, eval is null
here
// and this null check was being caoucht by an outer
try/catch which ignored it !
if (eval != null) {
clazz = eval.getResult().getClass();
property = (String) eval.getLastChild().getResult();
}
} else {
clazz = eval.getLastChild().getSource().getClass();
property = (String) eval.getFirstChild().getResult();
}
//
//
// I refactored this bit, as when runtime exceptions were
occuring within a custom TypeConverter
// the clazz was being added to noMappings.
//
if (!noMapping.contains(clazz)) {
try {
Map mapping = (Map) mappings.get(clazz);
if (mapping == null) {
mapping = new HashMap();
mappings.put(clazz, mapping);
------- clazz is null here
------------------------------------------------------------------------
--------------------
String className = clazz.getName();
String resource = className.replace('.', '/') +
"-conversion.properties";
InputStream is =
Thread.currentThread().getContextClassLoader().getResourceAsStream(resou
rce);
Properties props = new Properties();
props.load(is);
mapping.putAll(props);
for (Iterator iterator =
mapping.entrySet().iterator();
iterator.hasNext();) {
Map.Entry entry = (Map.Entry)
iterator.next();
entry.setValue(createTypeConverter((String)
entry.getValue()));
}
}
tc = (TypeConverter) mapping.get(property);
} catch (Throwable t) {
noMapping.add(clazz);
}
}
}
if (tc == null) {
if (toClass.equals(String.class) &&
!(value.getClass().equals(String.class) ||
value.getClass().equals(String[].class))) {
// when converting to a string, use the source object's
class's converter
if
(defaultMappings.containsKey(value.getClass().getName())) {
tc = (TypeConverter)
defaultMappings.get(value.getClass().getName());
}
} else {
// when converting from a string, use the toClass's
converter
if (defaultMappings.containsKey(toClass.getName())) {
// converting from String
tc = (TypeConverter)
defaultMappings.get(toClass.getName());
}
}
}
if (tc != null) {
try {
return tc.convertValue(context, object, member,
property, value, toClass);
} catch (Exception e) {
handleConversionException(property, value, object);
return null;
}
}
if (defaultTypeConverter != null) {
try {
return defaultTypeConverter.convertValue(context,
object, member, property, value, toClass);
} catch (Exception e) {
handleConversionException(property, value, object);
return null;
}
} else {
try {
return super.convertValue(context, object, member,
property, value, toClass);
} catch (Exception e) {
handleConversionException(property, value, object);
return null;
}
}
}
As you can see above where I added the line, clazz is null, and the next
line throws a NPE... I'm not sure why this is happening, or what it's
supposed to be doing there, so I was hoping someone (Well, Patrick
really) could take a look. BTW, this is my modified version which tries
to catch exceptions when the type conversion fails...
Jason
--
Jason Carreira
Technical Architect, Notiva Corp.
phone: 585.240.2793
fax: 585.272.8118
email: [EMAIL PROTECTED]
---
Notiva - optimizing trade relationships (tm)
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Opensymphony-webwork mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/opensymphony-webwork