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
Extensions
Plugins : Annotations

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-pointKeyDescriptionLocation
org.jpox.java5.annotations@PersistenceCapableJDO2 annotation readerjpox-java5
org.jpox.java5.annotations@PersistenceAwareJDO2 annotation readerjpox-java5
org.jpox.java5.annotations@EntityJPA1 annotation readerjpox-java5
org.jpox.java5.annotations@MappedSuperclassJPA1 annotation readerjpox-java5
org.jpox.java5.annotations@EmbeddableJPA1 annotation readerjpox-java5




Interface

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);
}


Plugin Specification

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".