My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
AnnomarkExample  
Example project to demonstrate annomark
Updated May 28, 2009 by roman.stumm

Using the annomark-example project

This is a project that demonstrates the features of "annomark". It creates some classes and xml files based on various annotations.

Some of the features demonstrated by the example project:

  • launch annomark with groovy (!JAMLauncher.groovy)
  • process own annotations (DTO, DTOs)
  • use all templates provided with annomark (POJO, Dozer-mapping, xml-metadata)
  • generate different objects for same class with relationships between them

For SVN and maven2 users

1. Checkout the annomark-example from Source with SVN.

2. Build the project

mvn clean package

3. Look into the target/generated/src/main directory

For maven2 users that cannot checkout from SVN

1. Download annomark-example-project.zip and extract

2. Build the project

mvn clean package

3. Look into the target/generated/src/main directory

Annomark explained

1. The pom launches a groovy script that contains all instructions and configurations

pom.xml:

 <java classname="org.codehaus.gram.Gram" fork="true"
       failonerror="true">
   <classpath refid="maven.test.classpath"/>
   <arg value="${basedir}/src/main/java/com/agimatec"/>
   <arg value="src/main/groovy/JAMLauncher.groovy"/>
 </java>
  • the first parameter is the source directory to parse
  • the second parameter is the groovy script to launch

2. The groovy script configures annomark:

JAMLancher.groovy

import java.util.*;
import com.agimatec.annotations.jam.*;
import com.agimatec.annotations.*;

def dtoClasses = new HashSet();
dtoClasses.addAll(classes.findAll { it.getAnnotation(DTO.class) != null });
dtoClasses.addAll(classes.findAll { it.getAnnotation(DTOs.class) != null });

generator = new JAMDtoGenerator();
generator.setTemplateDir("../annomark/templates");

generator.addInstruction("java-pojo", "target/generated/src/main/java", null)
    .setUsageQualifier("Edit")
    .setPrefix("Transfer")
    .setSuffix(".java")
    .setDefaultPackage("com.agimatec.annomark.example.transfer");

// ... more instructions here ...    

generator.generate(dtoClasses);
  • getAnnotation filters classes by annotations (here: DTO and DTOs). You can use own annotations as well.
  • JAMDtoGenerator assists in invoking freemarker to generate DataTransferObjects
  • refer to documentation of JAMGenInstruction

3. Study the example

  • Take a look at the the annotated model classes and experiment with the @DTO, @DTOAttribute annotations if you need TransferObjects
  • Create own annotations or own templates to generate the artifacts you need


Sign in to add a comment
Powered by Google Project Hosting