JPOX
JPOX
 Project  |  Ver 1.1  |  Ver 1.2  |  JDO  |  JPA  |  Guides  |  Tools
1.1 | Preparation | O/R Mapping | 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



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 either at the root, or in META-INF/plugins. 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".