Package jfun.yan

Examples of jfun.yan.Component


   * retrieves a component identified by a key.
   * The key is first looked up in the child container,
   * if not found, the parent container is looked up.
   */
  public Component getComponent(Object key) {
    Component cc = child.getComponent(key);
    if(cc==null) return parent.getComponent(key);
    else return cc;
  }
View Full Code Here


   * retrieves a component of a provided type.
   * the child container is first looked up,
   * if no such component is found, the parent container is looked up.
   */
  public Component getComponentOfType(Class type){
    Component c1 = getComponent(type);
    if(c1!=null) return c1;
    c1 = child.getComponentOfType(type);
    if(c1!=null) return c1;
    else return parent.getComponentOfType(type);
  }
View Full Code Here

      final Object key = it.next();
      if(!(key instanceof String)){
        //non-configured component, skip.
        continue;
      }
      final Component c = nuts.getComponent(key);
      final Class type = c.getType();
      if(type==null){
        throw new IllegalArgumentException("unknown type for nut component "+key
            + ", consider using 'type' attribute to explicitly specify the type for it");
      }
      if(!Nut.class.isAssignableFrom(type)){
View Full Code Here

      return Constants.AUTODETECT;
    }
  };
  private static Component useKey(Object key, java.util.Map cache){
    synchronized(cache){
      Component result = (Component)cache.get(key);
      if(result == null){
        result = useKey(key);
        cache.put(key, result);
      }
      return result;
View Full Code Here

      return result;
    }
  }
  private static Component useType(Class type, java.util.Map cache){
    synchronized(cache){
      Component result = (Component)cache.get(type);
      if(result == null){
        result = useType(type);
        cache.put(type, result);
      }
      return result;
View Full Code Here

      params.put(name, name);
    }
    return cc.fromProperties(mandatory_params).bean()
      .bindProperties(new PropertyBinder(){
        public Creator bind(Class component_type, Object key, Class type){
          final Component p = Components.useProperty(component_type, key, type);
          if(params.containsKey(key)){
            return p;
          }
          else return p.optional();
        }
      });
  }
View Full Code Here

   * @return the new Component that instantiates the proxied object.
   */
  public static Component getProxyComponentReturningInjected(
      final ClassLoader cloader, final Class itf,
      Component proxied, final Class injectee_type, Binder binder){
    final Component mutation = getInjectorComponent(Mutation.class, binder);
    final Component injected = Monad.map(proxied, mutation, new Map2(){
      public Object map(Object proxied, Object mut){
        return InjectingProxy.getInjectingProxy(cloader, itf,
            proxied, injectee_type, (Mutation)mut);
      }
    });
View Full Code Here

            singleton_mode==null?null:
              (SingletonMode)singleton_mode.run(frame, runtime);
          final boolean sync = sync_stmt==null?false:
            ((Boolean)sync_stmt.run(frame, runtime)).booleanValue();
          if(obj instanceof Creator){
            final Component result = MyUtil.wrapComponent(
                Components.adapt((Creator)obj), runtime, loc,
                casttype, singleton, autowire, sync, BodyCompiler.this);
            if(eager!=null){
              final boolean eagerly_instantiated =
                ((Boolean)eager.run(frame, runtime)).booleanValue();
View Full Code Here

          final Object id = new ReferentialId(exit);
          final NutsContinuation cont = new NutsContinuation(exit, loc, id);
          frame = frame.put(exit, cont);
          final Object r = body.run(frame, runtime);
          if(r instanceof Component){
            final Component c = (Component)r;
            return new DelegatingComponent(c){
              public Object create(Dependency dep){
                try{
                  return super.create(dep);
                }
View Full Code Here

    }
    private Component evalDefinitions(final Definition[] defs,
        final int begin, final int end, Dict frame, Runtime runtime) {
      if(begin==end)
        return Components.value(null);
      Component cc = null;
      final int last = end - 1;
      for(int i=begin;i<end;i++){
        final Definition def = defs[i];
        final Object retval = evalStmt(def.stmt, runtime, frame);
        final boolean isComponent = retval instanceof Component;
        if(isComponent){
          cc = seq(cc,(Component)retval);
          if(i==last) return cc;
        }
        else if(i==last){
          return seq(cc, NutsUtils.asComponent(retval));
        }
        /*
        if(isComponent){
          final Component cur = (Component)retval;
          cc = cc==null?cur:cc.seq(cur);
        }
        else{
          //relax this restriction because sometimes we may have a tag
          //that may or may not result in a component.
          if(i==last){
            cc = NutsUtils.asComponent(retval);
          }
        }*/
        frame = nextFrame(def, frame, retval);
        final String vi = def.var;
        if(vi != null){
          if(isComponent){
            final Stmt binder = bindStatements(defs, i+1, end);
            return cc.bind(evalBinder(vi,
                binder, runtime, frame));
          }
          else{
            frame = frame.put(vi, retval);
          }
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.