1 15 package org.apache.tapestry.services.impl; 16 17 import java.util.HashMap ; 18 import java.util.Iterator ; 19 import java.util.List ; 20 import java.util.Map ; 21 22 import org.apache.hivemind.Location; 23 import org.apache.tapestry.IBinding; 24 import org.apache.tapestry.IComponent; 25 import org.apache.tapestry.binding.BindingFactory; 26 import org.apache.tapestry.binding.BindingSource; 27 28 34 public class BindingSourceImpl implements BindingSource 35 { 36 private List _contributions; 37 38 private BindingFactory _literalBindingFactory; 39 40 43 private Map _factoryMap = new HashMap (); 44 45 public void initializeService() 46 { 47 Iterator i = _contributions.iterator(); 48 49 while (i.hasNext()) 50 { 51 BindingPrefixContribution c = (BindingPrefixContribution) i.next(); 52 53 _factoryMap.put(c.getPrefix(), c.getFactory()); 54 } 55 } 56 57 public IBinding createBinding(IComponent component, String bindingDescription, 58 String reference, String defaultPrefix, Location location) 59 { 60 String prefix = defaultPrefix; 61 String path = reference; 62 63 int colonx = reference.indexOf(':'); 64 65 if (colonx > 1) 66 { 67 prefix = reference.substring(0, colonx); 68 69 if (_factoryMap.containsKey(prefix)) 70 path = reference.substring(colonx + 1); 71 } 72 73 BindingFactory factory = (BindingFactory) _factoryMap.get(prefix); 74 75 if (factory == null) 76 factory = _literalBindingFactory; 77 78 return factory.createBinding(component, bindingDescription, path, location); 79 } 80 81 public void setContributions(List contributions) 82 { 83 _contributions = contributions; 84 } 85 86 public void setLiteralBindingFactory(BindingFactory literalBindingFactory) 87 { 88 _literalBindingFactory = literalBindingFactory; 89 } 90 } | Popular Tags |