Coverage Report - org.apache.tapestry5.services.AliasContribution
 
Classes in this File Line Coverage Branch Coverage Complexity
AliasContribution
100%
18/18
100%
2/2
0
 
 1  
 // Copyright 2006, 2007 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.tapestry5.services;
 16  
 
 17  
 import static org.apache.tapestry5.ioc.internal.util.Defense.notNull;
 18  
 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
 19  
 
 20  
 import java.util.Formatter;
 21  
 
 22  
 /**
 23  
  * A contribution into the {@link Alias} or AliasOverride service configuration.
 24  
  */
 25  
 public final class AliasContribution<T>
 26  
 {
 27  
     private final Class<T> contributionType;
 28  
 
 29  
     private final String mode;
 30  
 
 31  
     private final T object;
 32  
 
 33  
     /**
 34  
      * Simplifies the creation of an AliasContribution around a known type and instance of that type.
 35  
      */
 36  
     public static <X> AliasContribution<X> create(Class<X> contributionType, X object)
 37  
     {
 38  24
         return new AliasContribution<X>(contributionType, object);
 39  
     }
 40  
 
 41  
     /**
 42  
      * Simplifies the creation of an AliasContribution around a known type, mode, and an instance of that type.
 43  
      */
 44  
     public static <X> AliasContribution<X> create(Class<X> contributionType, String mode, X object)
 45  
     {
 46  188
         return new AliasContribution<X>(contributionType, mode, object);
 47  
     }
 48  
 
 49  
     /**
 50  
      * Conntributes the object with a blank mode.
 51  
      */
 52  
     public AliasContribution(Class<T> contributionType, T object)
 53  
     {
 54  24
         this(contributionType, "", object);
 55  24
     }
 56  
 
 57  
     public AliasContribution(Class<T> contributionType, String mode, T object)
 58  216
     {
 59  216
         this.contributionType = notNull(contributionType, "contributionClass");
 60  216
         this.mode = notNull(mode, "mode");
 61  216
         this.object = notNull(object, "object");
 62  216
     }
 63  
 
 64  
     /**
 65  
      * Returns the mode of operation for this instance of Tapestry. Most of the time, this will be the empty string,
 66  
      * meaning that the contribution applies to Tapestry is any mode. In other cases, the mode will be "servlet" but may
 67  
      * be other modes via add on modules, such as "portlet" or "offline".
 68  
      */
 69  
     public String getMode()
 70  
     {
 71  420
         return mode;
 72  
     }
 73  
 
 74  
     public Class<T> getContributionType()
 75  
     {
 76  210
         return contributionType;
 77  
     }
 78  
 
 79  
     /**
 80  
      * The contributed object, which will be made available.
 81  
      */
 82  
     public T getObject()
 83  
     {
 84  210
         return object;
 85  
     }
 86  
 
 87  
     @Override
 88  
     public String toString()
 89  
     {
 90  4
         StringBuilder builder = new StringBuilder();
 91  4
         Formatter formatter = new Formatter(builder);
 92  
 
 93  4
         formatter.format("<AliasContribution: %s", contributionType.getName());
 94  
 
 95  4
         if (InternalUtils.isNonBlank(mode)) formatter.format(" mode:%s", mode);
 96  
 
 97  4
         formatter.format(" %s>", object);
 98  
 
 99  4
         return builder.toString();
 100  
     }
 101  
 
 102  
 }