Menu

#10 Implement inner classes

closed-out-of-date
nobody
None
5
2010-09-01
2007-04-26
No

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

Discussion

  • Daniel Chang Yan

    Logged In: YES
    user_id=961230
    Originator: YES

    File Added: dozer-3.1-src.zip

     
  • Daniel Chang Yan

    Dozer version 3.1 with inner classes implementation

     
  • Franz Garsombke

    Franz Garsombke - 2007-05-05

    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

     
  • Daniel Chang Yan

    Logged In: YES
    user_id=961230
    Originator: YES

    No, but Monday I can create one and put it in.

     
  • Daniel Chang Yan

    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

     
  • Daniel Chang Yan

    junit test for two inner classes

     
  • Franz Garsombke

    Franz Garsombke - 2007-05-09

    Logged In: YES
    user_id=550744
    Originator: NO

    Thanks. I will let you know when this is implemented.

     
  • Daniel Chang Yan

    LoadClass class with method setNameForInnerClasses()

     
  • Daniel Chang Yan

    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

     
  • - 2008-02-11

    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...?!

     
  • Daniel Chang Yan

    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

     
  • dmitry (lv)

    dmitry (lv) - 2010-09-01
    • status: open --> closed-out-of-date
     
  • dmitry (lv)

    dmitry (lv) - 2010-09-01

    Inner classes are already supported

     

Log in to post a comment.