Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Suppose that we have a simple JSR175 annotation type called DeploymentInfo which specifies a 'cacheSize' attribute for some kind of deployment unit:

Code Block
borderStylesolid
titleDeploymentInfo.java
borderStylesolid
@AnnogenInfo(
  annoBeanClass = "org.codehaus.annogen.examples.stored_override.DeploymentInfoAnnoBean"
)
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)

public @interface DeploymentInfo {
  public int cacheSize();

}

Suppose that we also have an deployment unit called TinyCacheEJB which has a DeploymentInfo annotation:

Code Block
borderStylesolid
titleTinyCacheEJB.java
borderStylesolid
@DeploymentInfo(cacheSize = 3)
public class TinyCacheEJB {
  //...
}

...

The first thing we have to do is generate an AnnoBean that will act as a proxy to instances of DeploymentInfo. To do this, we simply run Annogen's compilation task on DeploymentInfo:

Code Block
borderStylesolid
titlebuild.xml
borderStylesolid
<annogen outputdir='${codegen_dir}'
         classpathref='classpath'
         srcdir='src'
         includes='org/codehaus/annogen/examples/stored_override/DeploymentInfo.java'
         implementAnnotationTypes='true'/>

...

This generates a DeploymentInfoAnnoBean that implements DeploymentInfo:

Code Block
borderStylesolid
titleDeploymentInfoAnnoBean.java
borderStylesolid
public class DeploymentInfoAnnoBean extends AnnoBeanBase implements DeploymentInfo {

  private int cacheSize;

  public int cacheSize() {
    return this.cacheSize;
  }

  public void set_cacheSize(int in) {
    this.cacheSize = in;
  }
}

...

Notice that the generated DeploymentInfoAnnoBean class has a setter for cacheSize. We're now going to create an

Wiki Markup
{link:AnnoOverrider|http://annogen.codehaus.org/annogen-api/org/codehaus/annogen/override/AnnoOverrider.html}{link}
which uses that setter to effectively change the size of the cache on TinyCacheEJB. We create an instance of
Wiki Markup
{link:StoredAnnoOverrider|http://annogen.codehaus.org/annogen-api/org/codehaus/annogen/override/StoredAnnoOverrider.html}{link}
, which is a helper class Annogen provides for building simple AnnoOverriders.

Code Block
borderStylesolid
titleUser.java
borderStylesolid
StoredAnnoOverrider storedOverrides = StoredAnnoOverrider.Factory.create();

...

Compared to the Override phase, the View phase is very simple. All we have to do is create a

Wiki Markup
{link:ReflectAnnoViewer|http://annogen.codehaus.org/annogen-api/org/codehaus/annogen/view/ReflectAnnoViewer.html}{link}
which knows about the AnnoOverrider we created above:

Code Block
borderStylesolid
titleDeployerTool.java
borderStylesolid
annoViewer = ReflectAnnoViewer.Factory.create(myAnnoOverrider);

...