4 Replies Latest reply on Dec 3, 2006 8:28 AM by flavia.rainone.old

    Pls help with a simple Mixin problem

    guava

      Hi,

      I'm started to use the Introduction feature of JBossAOP and can not seem to get the Mixin working. Any help will be appreciated. I have one Pojo, one Aspect, one Mixin, and an interface the mixin implements. I'm running these in the same directory as the examples provided by JbossAOP. Following are the classes:

      //------ MyPojo
      public class MyPojo {
      }

      //------ MyInf
      public interface MyInf {
      String hello(String h);
      }

      //-----MyMixin
      public class MyMixin implements MyInf {
      public String hello(String h) {
      return "Hello " + h;
      }
      }

      //---- MyAspect
      import org.jboss.aop.Aspect;
      import org.jboss.aop.Mixin;
      import org.jboss.aop.Introduction;

      @Aspect
      public class MyAspect
      {
      @Mixin (target=MyPojo.class, interfaces={MyInf.class})
      public static MyMixin createMyMixin() {
      return new MyMixin();
      }
      }

      I'm getting a javassist.NotFoundException: LMyMixin when I run aop compiler.

      Following are the build file and the stack trace:



      //--------- stack trace
      [aopc] [debug] Passed in instrumentor: null
      [aopc] [debug] Defaulting instrumentor to: org.jboss.aop.instrument.Classic
      Instrumentor
      [aopc] [debug] jboss.aop.class.path: C:\tools\jboss-aop_1.5.2.GA\docs\aspec
      t-framework\examples\temp1
      [aopc] [debug] Looking for aspects in: MyAspect
      [aopc] [debug] Found @Aspect in: MyAspect
      [aopc] [debug] Looking for aspects in: MyInf
      [aopc] [debug] Looking for aspects in: MyMixin
      [aopc] [debug] Looking for aspects in: MyPojo
      [aopc] [debug] jboss.aop.search.classpath: 'null' true
      [aopc] [debug] jboss.aop.path: null
      [aopc] [trying to transform] MyMixin
      [aopc] [debug] There are no caller pointcuts!
      [aopc] [debug] javassist.CtMethod@ca717109[public hello (Ljava/lang/String;
      )Ljava/lang/String;] matches no pointcuts
      [aopc] [debug] javassist.CtConstructor@fec107[public MyMixin ()V] matches n
      o pointcuts
      [aopc] [debug] was MyMixin converted: false
      [aopc] [no comp needed] C:\tools\jboss-aop_1.5.2.GA\docs\aspect-framework\e
      xamples\temp1\MyMixin.class
      [aopc] [cannot compile] isInterface: MyInf
      [aopc] [no comp needed] C:\tools\jboss-aop_1.5.2.GA\docs\aspect-framework\e
      xamples\temp1\MyInf.class
      [aopc] [trying to transform] MyAspect
      [aopc] [debug] There are no caller pointcuts!
      [aopc] [debug] javassist.CtMethod@8676605a[public static createMyMixin ()LM
      yMixin;] matches no pointcuts
      [aopc] [debug] javassist.CtConstructor@64f6cd[public MyAspect ()V] matches
      no pointcuts
      [aopc] [debug] was MyAspect converted: false
      [aopc] [no comp needed] C:\tools\jboss-aop_1.5.2.GA\docs\aspect-framework\e
      xamples\temp1\MyAspect.class
      [aopc] [trying to transform] MyPojo
      [aopc] [debug] There are no caller pointcuts!
      [aopc] [debug] javassist.CtConstructor@5e5a50[public MyPojo ()V] matches no
      pointcuts
      [aopc] javassist.NotFoundException: LMyMixin
      [aopc] at javassist.ClassPool.get(ClassPool.java:416)
      [aopc] at org.jboss.aop.instrument.Instrumentor.addMixin(Instrumentor.j
      ava:250)
      [aopc] at org.jboss.aop.instrument.Instrumentor.instrumentIntroductions
      (Instrumentor.java:336)
      [aopc] at org.jboss.aop.instrument.Instrumentor.transform(Instrumentor.
      java:672)
      [aopc] at org.jboss.aop.AspectManager.translate(AspectManager.java:908)

      [aopc] at org.jboss.aop.AspectManager.transform(AspectManager.java:820)

      [aopc] at org.jboss.aop.standalone.Compiler.compileFile(Compiler.java:3
      45)
      [aopc] at org.jboss.aop.standalone.Compiler.compile(Compiler.java:234)
      [aopc] at org.jboss.aop.standalone.Compiler.main(Compiler.java:90)
      [aopc] java.lang.RuntimeException: failed to transform: MyPojo
      [aopc] at org.jboss.aop.instrument.Instrumentor.transform(Instrumentor.
      java:732)
      [aopc] at org.jboss.aop.AspectManager.translate(AspectManager.java:908)

      [aopc] at org.jboss.aop.AspectManager.transform(AspectManager.java:820)

      [aopc] at org.jboss.aop.standalone.Compiler.compileFile(Compiler.java:3
      45)
      [aopc] at org.jboss.aop.standalone.Compiler.compile(Compiler.java:234)
      [aopc] at org.jboss.aop.standalone.Compiler.main(Compiler.java:90)
      [aopc] Caused by: javassist.NotFoundException: LMyMixin
      [aopc] at javassist.ClassPool.get(ClassPool.java:416)
      [aopc] at org.jboss.aop.instrument.Instrumentor.addMixin(Instrumentor.j
      ava:250)
      [aopc] at org.jboss.aop.instrument.Instrumentor.instrumentIntroductions
      (Instrumentor.java:336)
      [aopc] at org.jboss.aop.instrument.Instrumentor.transform(Instrumentor.
      java:672)
      [aopc] ... 5 more
      [aopc] Exception in thread "main" java.lang.RuntimeException: failed to tra
      nsform: MyPojo
      [aopc] at org.jboss.aop.instrument.Instrumentor.transform(Instrumentor.
      java:732)
      [aopc] at org.jboss.aop.AspectManager.translate(AspectManager.java:908)

      [aopc] at org.jboss.aop.AspectManager.transform(AspectManager.java:820)

      [aopc] at org.jboss.aop.standalone.Compiler.compileFile(Compiler.java:3
      45)
      [aopc] at org.jboss.aop.standalone.Compiler.compile(Compiler.java:234)
      [aopc] at org.jboss.aop.standalone.Compiler.main(Compiler.java:90)
      [aopc] Caused by: javassist.NotFoundException: LMyMixin
      [aopc] at javassist.ClassPool.get(ClassPool.java:416)
      [aopc] at org.jboss.aop.instrument.Instrumentor.addMixin(Instrumentor.j
      ava:250)
      [aopc] at org.jboss.aop.instrument.Instrumentor.instrumentIntroductions
      (Instrumentor.java:336)
      [aopc] at org.jboss.aop.instrument.Instrumentor.transform(Instrumentor.
      java:672)
      [aopc] ... 5 more

      BUILD FAILED
      C:\tools\jboss-aop_1.5.2.GA\docs\aspect-framework\examples\temp1\build.xml:33: J
      ava returned: 1

      //----- build.xml (identical to JBossAOP example jboss-aop_1.5.2.GA\docs\aspect-framework\examples\annotated-introduction)
      <?xml version="1.0" encoding="UTF-8"?>







































        • 1. Re: Pls help with a simple Mixin problem
          fabiocsilva

          You can remove the archives .class before compiling the sources. I use a modified version of build file. Try:

          <?xml version="1.0" encoding="UTF-8"?>
          
          <project default="run" name="JBossAOP">
           <property name="jboss.aop.root" value="/opt/project/library/jboss-aop"/>
           <property name="jboss.aop.lib50" value="${jboss.aop.root}/lib-50"/>
           <property name="buildpath" value="${basedir}/bin"/>
           <property name="class.main" value="Driver"/>
          
           <target name="prepare">
          
           <path id="jboss.aop.classpath50">
           <fileset dir="${jboss.aop.lib50}">
           <include name="*.jar"/>
           </fileset>
           </path>
          
           <path id="classpath">
           <path refid="jboss.aop.classpath50"/>
           <pathelement path="."/>
           </path>
          
           <property name="aop50jar" value="${jboss.aop.lib50}/jboss-aop-jdk50.jar"/>
          
           <path id="classpath50">
           <path refid="jboss.aop.classpath50"/>
           <pathelement path="."/>
           </path>
          
           <taskdef name="aopc" classname="org.jboss.aop.ant.AopC" classpathref="jboss.aop.classpath50"/>
           </target>
          
           <target name="clean">
           <delete dir="${buildpath}" />
           <mkdir dir="${buildpath}" />
           </target>
          
           <target name="compile" depends="prepare">
           <javac srcdir="."
           destdir="${buildpath}"
           debug="on"
           deprecation="on"
           optimize="off"
           includes="**">
           <classpath refid="classpath"/>
           </javac>
           <aopc compilerclasspathref="classpath" classpathref="classpath" verbose="true">
           <classpath path="${buildpath}"/>
           <src path="."/>
           <aopclasspath path="."/>
           </aopc>
           </target>
          
           <target name="run" depends="clean,compile">
           <java fork="yes" failOnError="true" className="${class.main}">
           <sysproperty key="jboss.aop.class.path" value="."/>
           <classpath refid="classpath"/>
           <classpath path="${buildpath}"/>
           </java>
           </target>
          
           <target name="compile50standalone" depends="prepare">
           <javac srcdir="."
           destdir="."
           debug="on"
           deprecation="on"
           optimize="off"
           includes="**">
           <classpath refid="classpath50"/>
           </javac>
           </target>
          
           <target name="run.50.instrumented" depends="compile50standalone">
           <java fork="yes" failOnError="true" className="${class.main}">
           <sysproperty key="jboss.aop.class.path" value="."/>
           <jvmarg value="-javaagent:${aop50jar}"/>
           <classpath path="${buildpath}"/>
           <classpath refid="classpath50"/>
           </java>
           </target>
          
          </project>
          
          



          • 2. Re: Pls help with a simple Mixin problem
            flavia.rainone.old

            The problem is in your aspect code:

            @Aspect
            public class MyAspect
            {
            @Mixin (target=MyPojo.class, interfaces={MyInf.class})
            public static MyMixin createMyMixin() {
            return new MyMixin();
            }
            }
            


            The createMyMixin method must receive the pojo as an argument. Just replace your aspect by this new one.

            @Aspect
            public class MyAspect
            {
            @Mixin (target=MyPojo.class, interfaces={MyInf.class})
            public static MyMixin createMyMixin(MyPojo pojo) {
            return new MyMixin();
            }
            }
            


            • 3. Re: Pls help with a simple Mixin problem
              guava

              Thanks so much.

              Indeed it worked after I changed the Mixin method to take MyPojo as an input argument.

              I was wonder why this has to be the case though.

              I can not see from the AOP document that the mixin creation method has to take the opriginal pojo as the argument.

              From Section 5.6 @Mixin the document only specifies 4 requirements:

              * be public
              * be static
              * contain the logic to create the mixin class
              * return an instance of the mixin class

              Perhaps they should add one more requirement or someone can explain why this is the case?

              Thanks.

              • 4. Re: Pls help with a simple Mixin problem
                flavia.rainone.old

                Indeed, we forgot to add this requirement to the documentation.
                It will be fixed on the next release.