Coverage Report - org.apache.tapestry5.internal.services.AliasManagerImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
AliasManagerImpl
100%
19/19
100%
6/6
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.internal.services;
 16  
 
 17  
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
 18  
 import org.apache.tapestry5.services.AliasContribution;
 19  
 import org.apache.tapestry5.services.AliasManager;
 20  
 import org.slf4j.Logger;
 21  
 
 22  
 import java.util.Collection;
 23  
 import java.util.Map;
 24  
 
 25  
 public class AliasManagerImpl implements AliasManager
 26  
 {
 27  
     private final Logger logger;
 28  
 
 29  
     private final Collection<AliasContribution> contributions;
 30  
 
 31  
     public AliasManagerImpl(Logger logger, Collection<AliasContribution> contributions)
 32  128
     {
 33  128
         this.logger = logger;
 34  128
         this.contributions = contributions;
 35  128
     }
 36  
 
 37  
     public Map<Class, Object> getAliasesForMode(String mode)
 38  
     {
 39  128
         Map<Class, Object> general = buildMapForMode("");
 40  128
         Map<Class, Object> specific = buildMapForMode(mode);
 41  
 
 42  
         // Anything in specific overrides anything in general
 43  
 
 44  128
         general.putAll(specific);
 45  
 
 46  128
         return general;
 47  
     }
 48  
 
 49  
     private Map<Class, Object> buildMapForMode(String mode)
 50  
     {
 51  256
         Map<Class, Object> result = CollectionFactory.newMap();
 52  
 
 53  256
         for (AliasContribution ic : contributions)
 54  
         {
 55  416
             if (!ic.getMode().equalsIgnoreCase(mode)) continue;
 56  
 
 57  206
             Class contributionType = ic.getContributionType();
 58  
 
 59  206
             Object existing = result.get(contributionType);
 60  
 
 61  206
             if (existing != null)
 62  
             {
 63  2
                 logger.error(ServicesMessages.duplicateContribution(
 64  
                         ic.getObject(),
 65  
                         contributionType,
 66  
                         existing));
 67  2
                 continue;
 68  
             }
 69  
 
 70  204
             result.put(contributionType, ic.getObject());
 71  204
         }
 72  
 
 73  256
         return result;
 74  
     }
 75  
 
 76  
 }