All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ocpsoft.rewrite.annotation.HandlerChainImpl Maven / Gradle / Ivy

package org.ocpsoft.rewrite.annotation;

import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.ocpsoft.common.util.Assert;
import org.ocpsoft.rewrite.annotation.api.ClassContext;
import org.ocpsoft.rewrite.annotation.api.HandlerChain;
import org.ocpsoft.rewrite.annotation.spi.AnnotationHandler;

public class HandlerChainImpl implements HandlerChain
{

   private final ClassContext context;

   private AnnotatedElement element;

   private final List> handlers;

   private int pos = 0;

   @SuppressWarnings("unchecked")
   public HandlerChainImpl(ClassContext context, AnnotatedElement element, List> handlers)
   {
      this.context = context;
      this.element = element;
      this.handlers = new ArrayList>();
      this.handlers.addAll((Collection>) handlers);
   }

   @Override
   public void proceed()
   {
      if (pos < handlers.size()) {
         AnnotationHandler handler = handlers.get(pos++);
         Annotation annotation = element.getAnnotation(handler.handles());
         Assert.notNull(annotation, "Could not find annotation [" + handler.handles().getName() + "] on: " + element);
         handler.process(context, annotation, this);
      }

   }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy