JPOX
JPOX
 Project  |  Ver 1.1  |  Ver 1.2  |  JDO  |  JPA  |  Guides  |  Tools
1.2 | Persistence | JDO ORM | JPA ORM | Runtime | JDO Runtime | JPA Runtime | Extensions | Developer
Development
Testing
JPOX Design : Enhancer

JPOX relies on classes implementing PersistenceCapable, and Detachable. Users could clearly do this manually but we provide the byte-code enhancement option. The JPOX Enhancer is structured to firstly determine from the input which classes are required to be enhanced, and secondly to enhance each class using the selected ClassEnhancer. JPOX 1.1 only has the BCELClassEnhancer. JPOX 1.2 (or soon after) will also have the ASMClassEnhancer

BCELClassEnhancer

BCEL is one of the oldest Java bytecode tools and provides much flexibility in how to modify the class bytecode, but it isnt the fastest nor the smallest. If you want to see the BCEL code to generate a particular class you should use the "BCELifier" utility that comes with it. BCEL doesn't have perfect support for Java5 or later.

ASMClassEnhancer

ASM operates in a very similar way to BCEL, however is much more lightweight and operates using the same pattern as a SAX Parser and much faster. It uses a Visitor pattern. First the class is visited, then fields and methods, and finally an "end" point where you can add on any new fields/methods etc. The ASMClassEnhancer uses the JdoClassVisitor to obtain information about a class to be enhanced and adds on all required fields/methods.

A very useful utility when developing with ASM is its "Bytecode Outline" Eclipse plugin. To install it simply add an "Eclipse Update site" to your Eclipse config as "http://download.forge.objectweb.org/eclipse-update/" and the name "ObjectWeb". You then install the "Bytecode Outline" plugin. Once you have it installed select "Window" -> "Show View" -> "Other" -> "Java : Bytecode". This provides a window showing the Java bytecode for the class being edited. If you click on the "ASM" button on this window it shows you the ASM commands you would need to create the class, or a particular method/field!. This makes developing new ASMClassMethod implementations a doddle - just create a class with the method you want generating and then cut and paste the ASM code in.

Decompiling Classes

If you ever need to check the byte-code enhanced class for correctness you can always decompile it back to the Java file. This can be done with a bytecode decompiler such as JODE. Unpack the JODE download so that you have the following

  • jode.jar
  • lib/ containing jdo.jar, jpox-core.jar, log4j.jar
  • classes.jar - your classes to be decompiled

and invoke the following command

java -cp classes.jar:jode.jar:lib/jpox-core.jar:lib/jdo.jar:lib/log4j.jar jode.decompiler.Main --dest source classes.jar
                

and it creates your classes under source/