Package tests.jfun.yan.xml

Source Code of tests.jfun.yan.xml.NamingServiceWiring

package tests.jfun.yan.xml;

import java.util.Map;

import jfun.util.Misc;
import jfun.yan.ComponentResolutionException;
import jfun.yan.Components;
import jfun.yan.Creator;
import jfun.yan.Monad;
import jfun.yan.PropertyBinder;
import jfun.yan.Recovery;
import jfun.yan.xml.NutsUtils;

final class NamingServiceWiring implements PropertyBinder {
  private final Map names;
  public Creator bind(Class component_type, Object key, Class type) {
    final String lookup_key = (Misc.getTypeName(component_type)+'.'+key)
      .replace('.', '/').replace('$', '/');
    Object v = names.get(lookup_key);
    if(v==null){
      final Recovery rec = Monad.onException(ComponentResolutionException.class,
          Monad.fail("failed to lookup " + lookup_key));
      return Components.useProperty(component_type, key, type)
        .recover(rec);
    }
    else{
      return NutsUtils.asComponent(v);
    }
  }
  NamingServiceWiring(Map names) {
    this.names = names;
  }
 
}
TOP

Related Classes of tests.jfun.yan.xml.NamingServiceWiring

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.