KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > tests > jfun > yan > xml > NamingServiceWiring


1 package tests.jfun.yan.xml;
2
3 import java.util.Map JavaDoc;
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 JavaDoc names;
16   public Creator bind(Class JavaDoc component_type, Object JavaDoc key, Class JavaDoc type) {
17     final String JavaDoc lookup_key = (Misc.getTypeName(component_type)+'.'+key)
18       .replace('.', '/').replace('$', '/');
19     Object JavaDoc 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 JavaDoc names) {
31     this.names = names;
32   }
33   
34 }
35
Popular Tags