0 Replies Latest reply on Aug 21, 2004 7:37 PM by jlukiano

    Primitive types transparency (response)

    jlukiano Newbie

      The original post became unavailable after a reply with code:


      Hi,

      I'm pleased to join you here.

      I have a problem with the annotation Java 1.4 together with a Class[] parameter. My annotation is related to a refactoring initiative
      to avoid repeating all the lookup/narrow stuff when using EJB. The annotation tag is:

      @@annot.ejblookup (invocarConstrutorParmsArray={br.com.ilheus.hotels.HotelManagerHome,java.lang.String,float,
      net.sourceforge.junitejb.EJBTestCase,br.com.ilheus.hotels.ReservationLocalHome,int})

      Thus the annotation class is:

      package annot;
      public interface ejblookup {
      Class[] invocarConstrutorParmsArray();
      }

      The problem is:

      20:01:23,686 INFO [HomeLookupTest] Starting: testLookup
      20:01:23,702 INFO [STDOUT] java.lang.RuntimeException: java.lang.RuntimeExcepti
      on: java.lang.ClassNotFoundException: No ClassLoaders found for: float
      20:01:23,702 INFO [STDOUT] at org.jboss.aop.annotation.AnnotationElement.ge
      tVisibleAnnotation(AnnotationElement.java:92)
      20:01:23,702 INFO [STDOUT] at org.jboss.aop.annotation.AnnotationElement.ge
      tAnyAnnotation(AnnotationElement.java:107)
      20:01:23,702 INFO [STDOUT] at br.com.ilheus.hotels.aspects.EjbHomeLookupInt
      erceptor.invoke(EjbHomeLookupInterceptor.java:41)

      The AnnotationElement class don't deal correctly with primitive classes. The Class[] has the constructor parameters that should be
      invoked instead of the constructor annotated. The parameters should also be delegated and I don't want to refactor the primitive types to their
      wrapper classes. Moreover, the EJB dependencies would be provided in a IoC fashion.

      Maybe, it is a conceptual issue related to the reflection and the javassist API. Any clarification?



      Bill Burke had replied that this is a bug on the framework.

      As a workaround: I used a comma-separated list as String:
      package annot;
      public interface ejblookup {
      String invocarConstrutorParmsArray();
      }
      
      @@annot.ejblookup (invocarConstrutorParmsArray="br.com.ilheus.hotels.HotelManagerHome,java.lang.String,float,
      net.sourceforge.junitejb.EJBTestCase,br.com.ilheus.hotels.ReservationLocalHome,int")
      
      String [] parms = annotejb.invocarConstrutorParms().split(",");
      Class [] parmsClassArray = new Class[parms.length];
      for (int cont = 0; cont < parms.length; cont++) {
       if (parms[cont].equals("char")) parmsClassArray[cont] = Character.TYPE;
       else if (parms[cont].equals("byte")) parmsClassArray[cont]= Byte.TYPE;
       else if (parms[cont].equals("short")) parmsClassArray[cont] = Short.TYPE;
       else if (parms[cont].equals("int")) parmsClassArray[cont] = Integer.TYPE;
       else if (parms[cont].equals("long")) parmsClassArray[cont] = Long.TYPE;
       else if (parms[cont].equals("float")) parmsClassArray[cont] = Float.TYPE;
       else if (parms[cont].equals("double")) parmsClassArray[cont] = Double.TYPE;
       else parmsClassArray[cont] = Class.forName(parms[cont]);
      }