Coverage Report - org.apache.tapestry.enhance.InjectEventInvokerWorker
 
Classes in this File Line Coverage Branch Coverage Complexity
InjectEventInvokerWorker
100% 
100% 
1.25
 
 1  
 // Copyright 2005 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  
 
 15  
 package org.apache.tapestry.enhance;
 16  
 
 17  
 import org.apache.hivemind.ErrorLog;
 18  
 import org.apache.hivemind.util.Defense;
 19  
 import org.apache.tapestry.internal.event.IComponentEventInvoker;
 20  
 import org.apache.tapestry.spec.IComponentSpecification;
 21  
 
 22  
 /**
 23  
  * Injects the component's event invoker as the
 24  
  * {@link org.apache.tapestry.IComponent#getEventInvoker() eventInvoker}property.
 25  
  * 
 26  
  * @author jkuhnert
 27  
  * @since 4.1
 28  
  */
 29  2
 public class InjectEventInvokerWorker implements EnhancementWorker
 30  
 {
 31  
 
 32  
     public static final String PROPERTY_NAME = "eventInvoker";
 33  
 
 34  
     private ErrorLog _errorLog;
 35  
 
 36  
     private IComponentEventInvoker _invoker;
 37  
     
 38  
     public void performEnhancement(EnhancementOperation op, IComponentSpecification spec)
 39  
     {
 40  
         try
 41  
         {
 42  2
             injectEventInvoker(op, spec);
 43  
         }
 44  1
         catch (Exception ex)
 45  
         {
 46  1
             _errorLog.error(EnhanceMessages.errorAddingProperty(
 47  
                     PROPERTY_NAME, op.getBaseClass(), ex), spec
 48  
                     .getLocation(), ex);
 49  1
         }
 50  2
     }
 51  
 
 52  
     public void injectEventInvoker(EnhancementOperation op, IComponentSpecification spec)
 53  
     {
 54  2
         Defense.notNull(op, "op");
 55  2
         Defense.notNull(spec, "spec");
 56  
         
 57  2
         op.claimReadonlyProperty(PROPERTY_NAME);
 58  
         
 59  1
         String fieldName = op.addInjectedField("_$"
 60  1
                 + PROPERTY_NAME, IComponentEventInvoker.class,
 61  
                 _invoker);
 62  
         
 63  1
         EnhanceUtils.createSimpleAccessor(op, fieldName,
 64  
                 PROPERTY_NAME, IComponentEventInvoker.class,
 65  
                 spec.getLocation());
 66  1
     }
 67  
 
 68  
     public void setErrorLog(ErrorLog errorLog)
 69  
     {
 70  1
         _errorLog = errorLog;
 71  1
     }
 72  
     
 73  
     public void setComponentEventInvoker(IComponentEventInvoker invoker)
 74  
     {
 75  2
         _invoker = invoker;
 76  2
     }
 77  
 }