Clover coverage report - Code Coverage for tapestry release 4.0-alpha-3
Coverage timestamp: Mon May 16 2005 09:05:49 EDT
file stats: LOC: 79   Methods: 3
NCLOC: 44   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.BodyBuilder;
 22   
 import org.apache.hivemind.service.MethodSignature;
 23   
 import org.apache.tapestry.services.ComponentMessagesSource;
 24   
 import org.apache.tapestry.spec.IComponentSpecification;
 25   
 
 26   
 /**
 27   
  * Injects the read-only {@link org.apache.tapestry.IComponent#getMessages() messages}property into
 28   
  * all components.
 29   
  * 
 30   
  * @author Howard M. Lewis Ship
 31   
  * @since 4.0
 32   
  */
 33   
 public class InjectMessagesWorker implements EnhancementWorker
 34   
 {
 35   
     final String MESSAGES_PROPERTY = "messages";
 36   
 
 37   
     private ErrorLog _errorLog;
 38   
 
 39   
     private ComponentMessagesSource _componentMessagesSource;
 40   
 
 41   
     final MethodSignature METHOD_SIGNATURE = new MethodSignature(Messages.class, "getMessages",
 42   
             null, null);
 43   
 
 44  480
     public void performEnhancement(EnhancementOperation op, IComponentSpecification spec)
 45   
     {
 46  480
         try
 47   
         {
 48  480
             op.claimProperty(MESSAGES_PROPERTY);
 49   
 
 50  479
             String sourceField = op.addInjectedField("_$componentMessagesSource", _componentMessagesSource);
 51   
 
 52  479
             op.addField("_$messages", Messages.class);
 53   
 
 54  479
             BodyBuilder builder = new BodyBuilder();
 55  479
             builder.begin();
 56  479
             builder.addln("if (_$messages == null)");
 57  479
             builder.addln("  _$messages = {0}.getMessages(this);", sourceField);
 58  479
             builder.addln("return _$messages;");
 59  479
             builder.end();
 60   
 
 61  479
             op.addMethod(Modifier.PUBLIC, METHOD_SIGNATURE, builder.toString());
 62   
         }
 63   
         catch (Exception ex)
 64   
         {
 65  1
             _errorLog.error(EnhanceMessages.errorAddingProperty(MESSAGES_PROPERTY, op
 66   
                     .getBaseClass(), ex), null, ex);
 67   
         }
 68   
     }
 69   
 
 70  62
     public void setComponentMessagesSource(ComponentMessagesSource componentMessagesSource)
 71   
     {
 72  62
         _componentMessagesSource = componentMessagesSource;
 73   
     }
 74   
 
 75  46
     public void setErrorLog(ErrorLog errorLog)
 76   
     {
 77  46
         _errorLog = errorLog;
 78   
     }
 79   
 }