This attach source is based in Dozer 3.1
The alterations are made so that dozer can use inner classes.
Added:
package net.sf.dozer.util.mapping.classLoader
with class: LoadClass.java
This class has a method setNameForInnerClasses() that is a substitute for the code:
Thread.currentThread().getContextClassLoader().loadClass( "some string name")
that search in the string for the correct class.
This substitution has been made at the following files:
net.sf.dozer.util.mapping.fieldmap.DozerClass.java
net.sf.dozer.util.mapping.fieldmap.Hint.java
net.sf.dozer.util.mapping.util.MappingUtils.java
net.sf.dozer.util.mapping.util.XMLParser.java
net.sf.dozer.util.mapping.MappingProcessor.java
This method has been made by my boss calmeida [calmeida@indra.pt]
And adapted for all dozer by me, dnlcy [dchang@indra.pt]
Another modification as been made in class JAXBBeanFactory.java to get the correct method
Logged In: YES
user_id=961230
Originator: YES
File Added: dozer-3.1-src.zip
Dozer version 3.1 with inner classes implementation
Logged In: YES
user_id=550744
Originator: NO
Is there a unit test attached with this? I need that so I can implement the patch.
Thanks,
Franz
Logged In: YES
user_id=961230
Originator: YES
No, but Monday I can create one and put it in.
Logged In: YES
user_id=961230
Originator: YES
Try to use this simple junit test
Tell me if this is what you need.
File Added: junit-test.zip
junit test for two inner classes
Logged In: YES
user_id=550744
Originator: NO
Thanks. I will let you know when this is implemented.
LoadClass class with method setNameForInnerClasses()
Logged In: YES
user_id=961230
Originator: YES
Franz,
I notice that you did not implemented this feature yet.
I upgrade my application to 4.1, and in this new version the changes are less since you guys concentrate the call of Thread.currentThread().getContextClassLoader().loadClass(String) in one place.
So what it's needed to change to use inner classes is just switch
Your method loadClass() in MappingUtils for this method:
public static Class loadClass(String name) throws ClassNotFoundException {
Class clazz = null;
String[] names = name.split("\\.");
StringBuffer className = new StringBuffer();
Class[] classes = null;
for(String sname : names) {
if(sname.substring(0,1).matches("[A-Z]")) {
if(clazz == null) {
className.append(sname);
clazz = Thread.currentThread()
.getContextClassLoader().loadClass(className.toString());
} else {
classes = clazz.getClasses();
for(Class innerClass : classes) {
if(innerClass.getName().endsWith(sname)) {
clazz = innerClass;
}
}
}
} else {
className.append(sname);
}
className.append(".");
}
return clazz;
}
or instead used my class LoadClass.java that renames the referred method to setNameForInnerClasses() and change your method loadClass() for:
public static Class loadClass(String name) {
Class result = null;
try {
result = LoadClass.setNameForInnerClasses(name);
} catch (ClassNotFoundException e) {
MappingUtils.throwMappingException(e);
}
return result;
}
I'm apply this last solution
One last thought about JAXBBeanFactory. This doesn't have to do with inner classes and I still don't know if it is a feature of my application but the change in JAXBBeanFactory.java is this:
- switch:
try {
method = ReflectionUtils.getMethod(objectFactory, "create" + beanId.substring(beanId.lastIndexOf(".") + 1), new Class[] {});
} catch (NoSuchMethodException e) {
MappingUtils.throwMappingException(e);
}
- for:
for(Method methodz : objectFactory.getMethods()) {
if(methodz.getReturnType().equals(srcObjClass)) {
method = methodz;
}
}
File Added: LoadClass.java
Logged In: YES
user_id=731522
Originator: NO
I found out that using something like
com.yourcompany.some.package.MainClass$InnerClass
works while
com.yourcompany.some.package.MainClass.InnerClass
does not.
Do you think your patch is gonna fix this...?!
Logged In: YES
user_id=961230
Originator: YES
maxxyme,
This patch will work for your case.
See may previous comment and use the file LoadClass.java. That's everything you need.
cumps
DnlCY
Inner classes are already supported