Coverage Report - org.apache.tapestry.enhance.InjectSpecificationWorker
 
Classes in this File Line Coverage Branch Coverage Complexity
InjectSpecificationWorker
0%
0/15
0%
0/4
1.333
 
 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.spec.IComponentSpecification;
 20  
 
 21  
 /**
 22  
  * Injects the component's specification as the
 23  
  * {@link org.apache.tapestry.IComponent#getSpecification() specification}property.
 24  
  * 
 25  
  * @author Howard M. Lewis Ship
 26  
  * @since 4.0
 27  
  */
 28  0
 public class InjectSpecificationWorker implements EnhancementWorker
 29  
 {
 30  
 
 31  
     public static final String SPECIFICATION_PROPERTY_NAME = "specification";
 32  
 
 33  
     private ErrorLog _errorLog;
 34  
 
 35  
     public void performEnhancement(EnhancementOperation op,
 36  
             IComponentSpecification spec)
 37  
     {
 38  
         try
 39  
         {
 40  0
             injectSpecification(op, spec);
 41  
         }
 42  0
         catch (Exception ex)
 43  
         {
 44  0
             _errorLog.error(EnhanceMessages.errorAddingProperty(
 45  
                     SPECIFICATION_PROPERTY_NAME, op.getBaseClass(), ex), spec
 46  
                     .getLocation(), ex);
 47  0
         }
 48  0
     }
 49  
 
 50  
     public void injectSpecification(EnhancementOperation op,
 51  
             IComponentSpecification spec)
 52  
     {
 53  0
         Defense.notNull(op, "op");
 54  0
         Defense.notNull(spec, "spec");
 55  
         
 56  0
         op.claimReadonlyProperty(SPECIFICATION_PROPERTY_NAME);
 57  
         
 58  0
         String fieldName = op.addInjectedField("_$"
 59  0
                 + SPECIFICATION_PROPERTY_NAME, IComponentSpecification.class,
 60  
                 spec);
 61  
 
 62  0
         EnhanceUtils.createSimpleAccessor(op, fieldName,
 63  
                 SPECIFICATION_PROPERTY_NAME, IComponentSpecification.class,
 64  
                 spec.getLocation());
 65  0
     }
 66  
 
 67  
     public void setErrorLog(ErrorLog errorLog)
 68  
     {
 69  0
         _errorLog = errorLog;
 70  0
     }
 71  
 }