JPOX is developed as a plugin-driven framework and one of the components that is pluggable is the reading
of annotations. JPOX provides a support for JDO2 and
JPA1 annotations, but is structured so that you can easily add your own
annotations and have them usable within your JPOX usage. This is available in JPOX from version 1.1.2
JPOX (from version 1.1.2 onwards) supports Java5 annotations. More than this, it actually provides a
pluggable framework whereby you can plug in your own annotations support.
The Java5 plugin provides plugins for JDO2 and JPA1 annotations. You can extend JPOX's capabilities
using the plugin extension org.jpox.java5.annotations.
| Plugin extension-point | Key | Description | Location |
|---|
| org.jpox.java5.annotations | @PersistenceCapable | JDO2 annotation reader | jpox-java5 |
| org.jpox.java5.annotations | @PersistenceAware | JDO2 annotation reader | jpox-java5 |
| org.jpox.java5.annotations | @Entity | JPA1 annotation reader | jpox-java5 |
| org.jpox.java5.annotations | @MappedSuperclass | JPA1 annotation reader | jpox-java5 |
| org.jpox.java5.annotations | @Embeddable | JPA1 annotation reader | jpox-java5 |
Any annotation reader plugin will need to implement org.jpox.metadata.annotations.AnnotationReader.
So you need to implement the following interface
package org.jpox.metadata.annotations;
import org.jpox.metadata.PackageMetaData;
import org.jpox.metadata.ClassMetaData;
public interface AnnotationReader
{
/**
* Accessor for the annotations packages supported by this reader.
* @return The annotations packages that will be processed.
*/
String[] getSupportedAnnotationPackages();
/**
* Method to get the ClassMetaData for a class from its annotations.
* @param cls The class
* @param pmd MetaData for the owning package (that this will be a child of)
* @return The ClassMetaData (unpopulated and unitialised)
*/
public ClassMetaData getMetaDataForClass(Class cls, PackageMetaData pmd);
}
So we now have our custom "annotation reader" and we just need to make this into a JPOX plugin. To do this
you simply add a file plugin.xml to your JAR at the root. The file
plugin.xml should look like this
<?xml version="1.0"?>
<plugin id="mydomain.annotations" name="JPOX plug-ins" provider-name="JPOX">
<extension point="org.jpox.java5.annotations">
<annotations annotation-class="mydomain.annotations.MyAnnotationType"
reader="mydomain.annotations.MyAnnotationReader"/>
</extension>
</plugin>
So here we have our "annotations reader" class "MyAnnotationReader" which will process any classes
annotated with the annotation "MyAnnotationType".