Reply To: Rewrite Annotations

Splash Forums Rewrite Users Rewrite Annotations Reply To: Rewrite Annotations

#24204

A sample annotation, handler, and registration:

The annotation:

@Inherited
@Documented
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Join
{
   /**
    * The external path to which the resource will be exposed.
    */
   String path();

   /**
    * The internal resource to be exposed.
    */
   String to();
}

The handler:

public class JoinHandler implements AnnotationHandler<Join>
{

   @Override
   public Class<Join> handles()
   {
      return Join.class;
   }

   @Override
   public int priority()
   {
      return HandlerWeights.WEIGHT_TYPE_STRUCTURAL;
   }

   @Override
   public void process(ClassContext context, Join annotation, HandlerChain chain)
   {
      context.setBaseRule(org.ocpsoft.rewrite.servlet.config.rule.Join
               .path(annotation.path())
               .to(annotation.to()));
      chain.proceed();
   }

}

The registration:
META-INF/services/org.ocpsoft.rewrite.annotation.spi.AnnotationHandler

org.ocpsoft.rewrite.annotation.handler.DomainHandler
org.ocpsoft.rewrite.annotation.handler.JoinHandler