Coverage Report - org.apache.tapestry.annotations.EventListenerAnnotationWorker
 
Classes in this File Line Coverage Branch Coverage Complexity
EventListenerAnnotationWorker
0%
0/17
0%
0/10
3.5
 
 1  
 // Copyright May 14, 2006 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 package org.apache.tapestry.annotations;
 15  
 
 16  
 import org.apache.hivemind.ApplicationRuntimeException;
 17  
 import org.apache.hivemind.Resource;
 18  
 import org.apache.tapestry.enhance.EnhancementOperation;
 19  
 import org.apache.tapestry.spec.IComponentSpecification;
 20  
 
 21  
 import java.lang.reflect.Method;
 22  
 
 23  
 
 24  
 /**
 25  
  * Performs {@link EventListener} annotation enhancements on components.
 26  
  *
 27  
  * @author jkuhnert
 28  
  */
 29  0
 public class EventListenerAnnotationWorker implements SecondaryAnnotationWorker
 30  
 {
 31  
     /**
 32  
      * {@inheritDoc}
 33  
      */
 34  
     public boolean canEnhance(Method method)
 35  
     {
 36  0
         return method.getAnnotation(EventListener.class) != null;
 37  
     }
 38  
 
 39  
     /**
 40  
      * {@inheritDoc}
 41  
      */
 42  
     public void peformEnhancement(EnhancementOperation op, IComponentSpecification spec, Method method, Resource classResource)
 43  
     {
 44  0
         EventListener listener = method.getAnnotation(EventListener.class);
 45  
 
 46  0
         String[] targets = listener.targets();
 47  0
         String[] elements = listener.elements();
 48  0
         String formId = listener.submitForm();
 49  0
         boolean validateForm = listener.validateForm();
 50  0
         boolean async = listener.async();
 51  0
         boolean focus = listener.focus();
 52  0
         boolean autoSubmit = listener.autoSubmit();
 53  
 
 54  0
         if (targets.length < 1 && elements.length < 1)
 55  0
             throw new ApplicationRuntimeException(AnnotationMessages.targetsNotFound(method));
 56  
 
 57  0
         for (int i=0; i < targets.length; i++)
 58  
         {
 59  0
             spec.addEventListener(targets[i], listener.events(),
 60  
                                   method.getName(), formId, validateForm, async, focus, autoSubmit);
 61  
         }
 62  
 
 63  0
         for (int i=0; i < elements.length; i++)
 64  
         {
 65  0
             spec.addElementEventListener(elements[i], listener.events(),
 66  
                                          method.getName(), formId, validateForm, async, focus);
 67  
         }
 68  0
     }
 69  
 }