Clover coverage report - Code Coverage for tapestry release 4.0.1
Coverage timestamp: Fri Mar 31 2006 09:12:14 EST
file stats: LOC: 93   Methods: 4
NCLOC: 55   Classes: 1
 
 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.Location;
 21    import org.apache.hivemind.Messages;
 22    import org.apache.hivemind.service.BodyBuilder;
 23    import org.apache.hivemind.service.MethodSignature;
 24    import org.apache.hivemind.util.Defense;
 25    import org.apache.tapestry.services.ComponentMessagesSource;
 26    import org.apache.tapestry.spec.IComponentSpecification;
 27   
 28    /**
 29    * Injects the read-only {@link org.apache.tapestry.IComponent#getMessages() messages}property into
 30    * all components.
 31    *
 32    * @author Howard M. Lewis Ship
 33    * @since 4.0
 34    */
 35    public class InjectMessagesWorker implements EnhancementWorker
 36    {
 37    final String MESSAGES_PROPERTY = "messages";
 38   
 39    private ErrorLog _errorLog;
 40   
 41    private ComponentMessagesSource _componentMessagesSource;
 42   
 43    final MethodSignature METHOD_SIGNATURE = new MethodSignature(Messages.class, "getMessages",
 44    null, null);
 45   
 46  818 public void performEnhancement(EnhancementOperation op, IComponentSpecification spec)
 47    {
 48  818 Location location = spec.getLocation();
 49   
 50  818 try
 51    {
 52  818 injectMessages(op, location);
 53    }
 54    catch (Exception ex)
 55    {
 56  2 _errorLog.error(EnhanceMessages.errorAddingProperty(MESSAGES_PROPERTY, op
 57    .getBaseClass(), ex), location, ex);
 58    }
 59    }
 60   
 61  818 public void injectMessages(EnhancementOperation op, Location location)
 62    {
 63  818 Defense.notNull(op, "op");
 64   
 65  818 op.claimReadonlyProperty(MESSAGES_PROPERTY);
 66   
 67  816 String sourceField = op.addInjectedField(
 68    "_$componentMessagesSource",
 69    ComponentMessagesSource.class,
 70    _componentMessagesSource);
 71   
 72  816 op.addField("_$messages", Messages.class);
 73   
 74  816 BodyBuilder builder = new BodyBuilder();
 75  816 builder.begin();
 76  816 builder.addln("if (_$messages == null)");
 77  816 builder.addln(" _$messages = {0}.getMessages(this);", sourceField);
 78  816 builder.addln("return _$messages;");
 79  816 builder.end();
 80   
 81  816 op.addMethod(Modifier.PUBLIC, METHOD_SIGNATURE, builder.toString(), location);
 82    }
 83   
 84  116 public void setComponentMessagesSource(ComponentMessagesSource componentMessagesSource)
 85    {
 86  116 _componentMessagesSource = componentMessagesSource;
 87    }
 88   
 89  80 public void setErrorLog(ErrorLog errorLog)
 90    {
 91  80 _errorLog = errorLog;
 92    }
 93    }