Package jfun.yan

Examples of jfun.yan.Component


      throw e;
    }
  }
  public Class verifyKey(Object key){
    try{
      final Component c = getComponent(key);
      if(c==null){
        throw new UnresolvedComponentException(key);
      }
      return c.verify(getDependency(key));
    }
    catch(YanException e){
      e.push("verifyKey <" + key +">");
      throw e;
    }
View Full Code Here


      throw e;
    }
  }
  public Class verifyType(Class type){
    try{
      final Component c = getComponentOfType(type);
      if(c==null)
        throw new UnresolvedComponentException(type);
      return c.verify(getDependencyOfType(type));
    }
    catch(YanException e){
      e.push("verifyType <" + Misc.getTypeName(type) +">");
      throw e;
    }
View Full Code Here

      e.push("verifyType <" + Misc.getTypeName(type) +">");
      throw e;
    }
  }
  public Class getComponentType(Object key) {
    final Component cc = getComponent(key);
    if(cc==null) return null;
    return cc.getType();
  }
View Full Code Here

  UnresolvedComponentException, UnsatisfiedComponentException, YanException {
    return instantiateComponent(key, cc, this);
  }
  public Object getInstance(Object key, ComponentMap cmap) {
    try{
      final Component cc = getComponent(key);
      if(cc==null){
        throw new UnresolvedComponentException(key);
      }
      return cc.create(cmap.getDependency(key,cmap));
    }
    catch(YanException e){
      e.push("getInstance <" + key + ">");
      throw e;
    }
View Full Code Here

   * which makes it singleton.
   * Override {@link #defaultTransform(Component)} if a different default behavior
   * is desired.
   */
  public void registerStaticMethod(Class c, String name){
    final Component comp = Components.static_method(c, name);
    registerComponent(defaultTransform(comp));
  }
View Full Code Here

   * which makes it singleton.
   * Override {@link #defaultTransform(Component)} if a different default behavior
   * is desired.
   */
  public void registerStaticMethod(Class c, String name, Class[] param_types){
    final Component comp = Components.static_method(c, name, param_types);
    registerComponent(defaultTransform(comp));
  }
View Full Code Here

  }
  public void getInstances(Map store, ComponentMap cmap){
    try{
      for(Iterator it = keys().iterator(); it.hasNext();){
        final Object ky = it.next();
        final Component cc = getComponent(ky);
        store.put(ky, cc.create(cmap.getDependency(ky, cmap)));
      }
    }
    catch(YanException e){
      e.push("getInstances");
      throw e;
View Full Code Here

    try{
      final java.util.Set ks = keys();
      final ArrayList ret = new ArrayList();
      for(Iterator it = ks.iterator(); it.hasNext();){
        final Object ky = it.next();
        final Component cc = getComponent(ky);
        ret.add(cc.create(cmap.getDependency(ky, cmap)));
      }
      return ret;
    }
    catch(YanException e){
      e.push("getInstances");
View Full Code Here

  }
  public synchronized Component getComponent(final Object key) {
    return (Component)creators.get(key);
  }
  public synchronized boolean containsType(final Class type){
    Component cc = getComponent(type);
    if(cc!=null){
      final Class ctype = cc.getType();
      if(ctype == null
          || ReflectionUtil.isAssignableFrom(type, ctype)){
        //if the type is dynamically bound, we trust the key.
        return true;
      }
      cc = null;
    }
    for(Iterator it=creators.values().iterator();it.hasNext();){
      final Component cci = (Component)it.next();
      final Class typei = cci.getType();
      if(typei!=null && !void.class.equals(typei) &&
          //void type does actively feed itself to a by-type search.
          //It does suppress type error when forced to match against another type.
          ReflectionUtil.isAssignableFrom(
          type, typei)){
View Full Code Here

      }
    }
    return false;
  }
  public synchronized Component getComponentOfType(final Class type){
    Component cc = getComponent(type);
    if(cc!=null){
      final Class ctype = cc.getType();
      if(ctype == null
          || ReflectionUtil.isAssignableFrom(type, ctype)){
        //if the type is dynamically bound, we trust the key.
        return cc;
      }
      cc = null;
    }
    Class subtype = null;
    for(Iterator it=creators.values().iterator();it.hasNext();){
      final Component cci = (Component)it.next();
      final Class typei = cci.getType();
      if(typei!=null && !void.class.equals(typei) &&
          //void type does actively feed itself to a by-type search.
          //It does suppress type error when forced to match against another type.
          ReflectionUtil.isAssignableFrom(
          type, typei)){
View Full Code Here

TOP

Related Classes of jfun.yan.Component

Copyright © 2018 www.massapicom. 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.