Coverage Report - org.apache.tapestry5.internal.services.BeanBlockOverrideSourceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
BeanBlockOverrideSourceImpl
100%
15/15
100%
6/6
0
 
 1  
 // Copyright 2008 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.Block;
 18  
 import org.apache.tapestry5.internal.structure.Page;
 19  
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
 20  
 import org.apache.tapestry5.services.BeanBlockContribution;
 21  
 import org.apache.tapestry5.services.BeanBlockOverrideSource;
 22  
 
 23  
 import java.util.Collection;
 24  
 import java.util.Map;
 25  
 
 26  
 public class BeanBlockOverrideSourceImpl implements BeanBlockOverrideSource
 27  
 {
 28  
     private final RequestPageCache pageCache;
 29  
 
 30  32
     private final Map<String, BeanBlockContribution> display = CollectionFactory.newCaseInsensitiveMap();
 31  
 
 32  32
     private final Map<String, BeanBlockContribution> edit = CollectionFactory.newCaseInsensitiveMap();
 33  
 
 34  
     public BeanBlockOverrideSourceImpl(RequestPageCache pageCache,
 35  
                                        Collection<BeanBlockContribution> configuration)
 36  32
     {
 37  32
         this.pageCache = pageCache;
 38  
 
 39  32
         for (BeanBlockContribution contribution : configuration)
 40  
         {
 41  72
             Map<String, BeanBlockContribution> map = contribution.isEdit() ? edit : display;
 42  
 
 43  72
             map.put(contribution.getDataType(), contribution);
 44  72
         }
 45  32
     }
 46  
 
 47  
     public boolean hasDisplayBlock(String datatype)
 48  
     {
 49  14764
         return display.containsKey(datatype);
 50  
     }
 51  
 
 52  
     public Block getDisplayBlock(String datatype)
 53  
     {
 54  624
         return toBlock(display.get(datatype));
 55  
     }
 56  
 
 57  
     private Block toBlock(BeanBlockContribution contribution)
 58  
     {
 59  1156
         if (contribution == null) return null;
 60  
 
 61  576
         Page page = pageCache.get(contribution.getPageName());
 62  
 
 63  576
         return page.getRootElement().getBlock(contribution.getBlockId());
 64  
     }
 65  
 
 66  
     public Block getEditBlock(String datatype)
 67  
     {
 68  532
         return toBlock(edit.get(datatype));
 69  
     }
 70  
 
 71  
 }