1 Reply Latest reply on Mar 23, 2005 10:17 PM by chiba

    inheritance question

    pocket5s

      I have a framework that generates a class implementing a specified interface for populating javabean properties. I have the following code:

      ClassPool pool = ClassPool.getDefault();
      pool.insertClassPath( new ClassClassPath(PropertyPopulator.class) );
      Loader loader = new Loader( PropertyPopulator.class.getClassLoader(), pool );

      CtClass cc = pool.makeClass( "org.aom.chameleon.utils." + mapping.getName().replace( ' ', '_' ) + "Populator" );
      loader.delegateLoadingOf( "org.aom.chameleon.utils.PropertyPopulator" );
      loader.delegateLoadingOf( mapping.getEntityClass() );

      cc.setSuperclass( pool.get( "org.aom.chameleon.utils.PropertyPopulator" ) );

      and all of this compiles and returns the generated class just fine. The problem is that the generated class casts an object supplied to it to a specific class and then invokes the various setXXX() methods on it. The object that is being cast however implements several interfaces and extends a class (it is a JAXB generated class), and the error I'm getting is:

      class com.uuic.ets.common.organization.impl.OrgUnitImpl does not implement interface com.uuic.ets.common.organization.OrgUnitType]: java.lang.IncompatibleClassChangeError: class com.uuic.ets.common.organization.impl.OrgUnitImpl does not implement interface com.uuic.ets.common.organization.OrgUnitType

      The class being cast to is an OrgUnit which extends OrgUnitType (both interfaces) with the implementing class being the OrgUnitImpl. I am running this in WebSphere 5.1, so I am assuming this is some kind of classloading problem with the webcontainer. I have tried casting it directly to the impl class with no success as well as chaning the classloader structure via the websphere admin console.

      I suppose I could overcome this via reflection, but the whole point of it was to get away from the overhead of reflection so I don't want to go that route.

      Any other thoughts here?

      Thanks...

        • 1. Re: inheritance question
          chiba

          It seems that multiple versions of OrgUnitType had been
          loaded. The error message should be interpreted as that
          the super class of OrgUnitImpl is a different version of
          OrgUnitImpl from the version that the cast operator
          (i.e. the class generated by Javassist) expects.

          If my observation is true, this is not a problem of Javassist
          or it cannot be solved with reflection. You should carefully
          redesign the delegation scheme by class loaders.