-
1. Re: Processing custom annotations with a CDI extension and Javassist
evantill May 31, 2012 3:59 AM (in response to oscarcs)Try adding this line :
ClassPool cp = ClassPool.getDefault(); pool.insertClassPath(new ClassClassPath(this.getClass()));
Have a look on this page http://www.csg.is.titech.ac.jp/~chiba/javassist/tutorial/tutorial.html
-
2. Re: Processing custom annotations with a CDI extension and Javassist
oscarcs May 31, 2012 1:38 PM (in response to evantill)You were correct. It works. Thanks a lot!.
But I have discovered that the CDI approach is not valid for me because i am trying to process some JPA entities that seem to be loaded before by JPA/Hibernate so when i try to modify them it's to late: they are present on the classloader.
So i have taken the other way: i have written a JBoss extension with a DeploymentUnitProcessor and it seems to work fine, except that again i have no idea of how to get the classpath from the DeploymentPhaseContext. I can get the classloader like this:
phaseContext.getDeploymentUnit().getAttachment(Attachments.MODULE).getClassLoader()
but i don't know what's the next step.
Finally, i have some doubts about how it will perform taking in account that hibernate is also doing some "magic" on this clases.
-
3. Re: Processing custom annotations with a CDI extension and Javassist
evantill Jun 1, 2012 6:45 AM (in response to oscarcs)Depending on what goal you are trying to achieve (could you explain a bit more ?) :
I would try to forget the byte code manipulation and go ahead with interceptors (in your CDI extension)
Or continue in bytecode manipulation direction and wrap the annotation type to return the modified bytecode.
To do so, overrid the getJavaClass() method (see Wrapping an AnnotatedType in http://docs.jboss.org/weld/reference/latest/en-US/html/extend.html#d0e5057)