Coverage Report - org.apache.tapestry.services.impl.BindingSourceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
BindingSourceImpl
0%
0/29
0%
0/14
2.4
 
 1  
 // Copyright 2004, 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.services.impl;
 16  
 
 17  
 import org.apache.hivemind.Location;
 18  
 import org.apache.tapestry.IBinding;
 19  
 import org.apache.tapestry.IComponent;
 20  
 import org.apache.tapestry.binding.BindingFactory;
 21  
 import org.apache.tapestry.binding.BindingSource;
 22  
 import org.apache.tapestry.spec.IParameterSpecification;
 23  
 
 24  
 import java.util.HashMap;
 25  
 import java.util.Iterator;
 26  
 import java.util.List;
 27  
 import java.util.Map;
 28  
 
 29  
 /**
 30  
  * Implementation of the {@link BindingSource} service.
 31  
  * 
 32  
  * @author Howard Lewis Ship
 33  
  * @since 4.0
 34  
  */
 35  0
 public class BindingSourceImpl implements BindingSource
 36  
 {
 37  
     private List _contributions;
 38  
 
 39  
     private Map _propertyMap;
 40  
 
 41  
     /**
 42  
      * Keyed on prefix, value is {@link BindingFactory}.
 43  
      */
 44  0
     private Map _factoryMap = new HashMap();
 45  
 
 46  
     public void initializeService()
 47  
     {
 48  0
         Iterator i = _contributions.iterator();
 49  
 
 50  0
         while (i.hasNext())
 51  
         {
 52  0
             BindingPrefixContribution c = (BindingPrefixContribution) i.next();
 53  
 
 54  0
             _factoryMap.put(c.getPrefix(), c.getFactory());
 55  0
         }
 56  0
     }
 57  
 
 58  
     public IBinding createBinding(IComponent component, String description,
 59  
             String reference, String defaultBindingType, Location location)
 60  
     {
 61  0
         return createBinding(component, null, description, reference, defaultBindingType, location);
 62  
     }
 63  
 
 64  
     public IBinding createBinding(IComponent component, IParameterSpecification parameter, String description,
 65  
                                   String reference, String defaultBindingType, Location location)
 66  
     {
 67  0
         String prefix = null;
 68  0
         String path = reference;
 69  0
         BindingFactory factory = null;
 70  
 
 71  0
         int colonx = reference.indexOf(':');
 72  
 
 73  0
         if (colonx > -1)
 74  
         {
 75  0
             String pathPrefix = reference.substring(0, colonx);
 76  
 
 77  0
             if (_factoryMap.containsKey(pathPrefix))
 78  
             {
 79  0
                 prefix = pathPrefix;
 80  
 
 81  0
                 path = reference.substring(colonx + 1);
 82  
             }
 83  0
         } else if (parameter != null && _propertyMap.containsKey(parameter.getParameterName()))
 84  
         {
 85  
             
 86  0
             factory = (BindingFactory) _propertyMap.get(parameter.getParameterName());
 87  
         }
 88  
 
 89  0
         if (prefix == null)
 90  
         {
 91  0
             prefix = defaultBindingType;
 92  
         }
 93  
 
 94  0
         if (factory == null)
 95  
         {
 96  0
             factory = (BindingFactory) _factoryMap.get(prefix);
 97  
         }
 98  
         
 99  0
         return factory.createBinding(component, description, path, location);
 100  
     }
 101  
 
 102  
     public void setContributions(List contributions)
 103  
     {
 104  0
         _contributions = contributions;
 105  0
     }
 106  
 
 107  
     public void setPropertyContributions(Map properties)
 108  
     {
 109  0
         _propertyMap = properties;
 110  0
     }
 111  
 }