1 package tests.jfun.yan.xml; 2 3 import java.util.Map ; 4 5 import jfun.util.Misc; 6 import jfun.yan.ComponentResolutionException; 7 import jfun.yan.Components; 8 import jfun.yan.Creator; 9 import jfun.yan.Monad; 10 import jfun.yan.PropertyBinder; 11 import jfun.yan.Recovery; 12 import jfun.yan.xml.NutsUtils; 13 14 final class NamingServiceWiring implements PropertyBinder { 15 private final Map names; 16 public Creator bind(Class component_type, Object key, Class type) { 17 final String lookup_key = (Misc.getTypeName(component_type)+'.'+key) 18 .replace('.', '/').replace('$', '/'); 19 Object v = names.get(lookup_key); 20 if(v==null){ 21 final Recovery rec = Monad.onException(ComponentResolutionException.class, 22 Monad.fail("failed to lookup " + lookup_key)); 23 return Components.useProperty(component_type, key, type) 24 .recover(rec); 25 } 26 else{ 27 return NutsUtils.asComponent(v); 28 } 29 } 30 NamingServiceWiring(Map names) { 31 this.names = names; 32 } 33 34 } 35 | Popular Tags |