Clover coverage report - Code Coverage for tapestry release 4.0-alpha-2
Coverage timestamp: Thu May 5 2005 09:57:44 EDT
file stats: LOC: 77   Methods: 3
NCLOC: 43   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
InjectMessagesWorker.java - 100% 100% 100%
coverage
 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 java.lang.reflect.Modifier;
 18   
 
 19   
 import org.apache.hivemind.ErrorLog;
 20   
 import org.apache.hivemind.Messages;
 21   
 import org.apache.hivemind.service.MethodSignature;
 22   
 import org.apache.tapestry.services.ComponentMessagesSource;
 23   
 import org.apache.tapestry.spec.IComponentSpecification;
 24   
 
 25   
 /**
 26   
  * Injects the read-only {@link org.apache.tapestry.IComponent#getMessages() messages}property into
 27   
  * all components.
 28   
  * 
 29   
  * @author Howard M. Lewis Ship
 30   
  * @since 4.0
 31   
  */
 32   
 public class InjectMessagesWorker implements EnhancementWorker
 33   
 {
 34   
     final String MESSAGES_PROPERTY = "messages";
 35   
 
 36   
     private ErrorLog _errorLog;
 37   
 
 38   
     private ComponentMessagesSource _componentMessagesSource;
 39   
 
 40   
     final String METHOD_CODE = "{\nif (_$messages == null)\n"
 41   
             + "  _$messages = _$componentMessagesSource.getMessages(this);\n"
 42   
             + "return _$messages;\n}\n";
 43   
 
 44   
     final MethodSignature METHOD_SIGNATURE = new MethodSignature(Messages.class, "getMessages",
 45   
             null, null);
 46   
 
 47  482
     public void performEnhancement(EnhancementOperation op, IComponentSpecification spec)
 48   
     {
 49  482
         try
 50   
         {
 51  482
             op.claimProperty(MESSAGES_PROPERTY);
 52   
 
 53  481
             op.addField(
 54   
                     "_$componentMessagesSource",
 55   
                     ComponentMessagesSource.class,
 56   
                     _componentMessagesSource);
 57  481
             op.addField("_$messages", Messages.class);
 58   
 
 59  481
             op.addMethod(Modifier.PUBLIC, METHOD_SIGNATURE, METHOD_CODE);
 60   
         }
 61   
         catch (Exception ex)
 62   
         {
 63  3
             _errorLog.error(EnhanceMessages.errorAddingProperty(MESSAGES_PROPERTY, op
 64   
                     .getBaseClass(), ex), null, ex);
 65   
         }
 66   
     }
 67   
 
 68  46
     public void setComponentMessagesSource(ComponentMessagesSource componentMessagesSource)
 69   
     {
 70  46
         _componentMessagesSource = componentMessagesSource;
 71   
     }
 72   
 
 73  46
     public void setErrorLog(ErrorLog errorLog)
 74   
     {
 75  46
         _errorLog = errorLog;
 76   
     }
 77   
 }