Package jfun.yan

Examples of jfun.yan.Component


    this.echo = echo;
  }

  public Component eval() {
    // TODO Auto-generated method stub
    final Component r = super.eval();
    if(echo){
      final String msg = (String)this.getNutEnvironment().findService("echo_msg");
      if(msg == null)
        throw raise("echo_msg not found.");
      return r.mutate(new Mutation(){
        public void mutate(Object r){
          System.out.println(msg + r +" constructed.");
        }
      });
    }
View Full Code Here


  }

  public Component eval(){
    final List keys = getKeys();
    final Component[] vals = getEntryComponents();
    final Component step1 = new SimpleComponent(Properties.class){
      public Object create(){
        return new Properties();
      }
    };
    return Components.storeMap(step1, keys.toArray(), vals);
View Full Code Here

  public Component eval(){
    final Component[] elements = getMandatoryElements();
    final Class type = getType(Object[].class);
    final Class oftype = getOf();
    final Class etype = oftype==null?Object.class:oftype;
    final Component step1 = new SimpleComponent(type){
      public Object create(){
        return Array.newInstance(etype, elements.length);
      }
      public String toString(){
        return StringUtils.listArray("[",",","]",elements);
View Full Code Here

          assertEquals(cc, cc);
          if(cc!=null)
            assertFalse(cc.equals(null));
          final HashMap hmap = new HashMap();
          hmap.put(cc, cc);
          final Component cc1 = (Component)hmap.get(cc);
          assertEquals(cc, cc1);
          assertEquals(""+cc, ""+cc1);
        }
      };
    }
View Full Code Here

       yan.unregisterComponentsOfType(Integer.class);
     }
     yan.unregisterComponent("superman");
     yan.unregisterComponent("supermanref");
     yan.unregisterComponent("badsupermanref");
     final Component anonymous_person = Components.bean(
         Components.method(this, "newPerson"),
         new String[]{"name","age"}
     )
     .withProperty("name", Components.useKey("personName"))
     .withProperty("age", Components.useType(Integer.class));
    
     yan.registerComponent(anonymous_person);
     final Component bad_person =          Components.bean(
         Components.value(null).subsume(Person.class),
         new String[]{"name","age"}
     )
     .withProperty("name", Components.useKey("personName"))
     .withProperty("age", Components.useType(Integer.class));
View Full Code Here

      assertEquals("target arrived!", yan.getInstance("target"));
    }
    public void testLifeycles()
    throws Throwable{
      final Container yan = new DefaultContainer();
      final Component real_engine =
        Components.useKey("real engine").singleton(new ThreadLocalScope());
      final DefaultLifecycleDescriptor desc = new DefaultLifecycleDescriptor();
      desc.setCloser(new Phase(desc.getCloser().getPhaseKey(), ExceptionHandlers.suppresser()));
      desc.setStopper(new Phase(desc.getStopper().getPhaseKey(), ExceptionHandlers.suppresser()));
      final DefaultLifecycleManager lm = new DefaultLifecycleManager(desc);
      final DefaultLifecycleManager.DefaultLifecycle lc = lm.newLifecycle()
      .starter("start")
      .stopper("stop")
      .initializer("initialize")
      .disposer("destroy");
      final Component engine_lc = lc.manage(real_engine);
      yan.registerComponent(CarEngine.class, engine_lc);
      /*
      yan.registerComponent(CarEngine.class, LifecycleDescriptor.instance(
          Components.useKey("real engine").singleton(new ThreadLocalScope()),
          ExceptionHandlers.suppresser())
          .starter("start")
          .stopper("stop")
          .initializer("initialize")
          .disposer("destroy")
          .get());
      */
      yan.registerConstructor("real engine", CarEngine.class);
      final Component sttfrc = Components.ctor(StatefulResource.class)
      .withArgument(0, Components.useType(CarEngine.class));
      yan.registerComponent(lc.manage(sttfrc));
      /*
      yan.registerComponent(LifecycleDescriptor.instance(
          Components.ctor(StatefulResource.class)
          .withArgument(0, Components.useType(CarEngine.class))
          , ExceptionHandlers.suppresser())
          .initializer("initialize")
          .disposer("destroy")
          .starter("start")
          .stopper("stop")
          .get());
      */
      final Component car_engine = yan.getComponentOfType(CarEngine.class);
      assertNull(car_engine.getType());
     
      final StatefulResource resource = (StatefulResource)yan.getInstanceOfType(StatefulResource.class);
      final CarEngine engine = (CarEngine)yan.getInstanceOfType(CarEngine.class);
      assertEquals(0, engine.getStarted());
      assertEquals(0, engine.getStopped());
View Full Code Here

      c = c.field(parts[i].trim(), private_access);
    }
    return c;
  }
  public Component eval(){
    final Component cc = getComponent();
    checkMandatory("class", hostclass, "component", cc);
    checkMandatory("name", fldname);
    return getFieldComponent(hostclass, cc, fldname, private_access);
    /*
    if(hostclass != null){
View Full Code Here

        }
      });
    }

    Component custProperties(Component c, String[] givers){
      Component r = c;
      for(int i=0;i<givers.length;i++){
        r = custProperty(r, givers[i]);
      }
      return r;
    }
View Full Code Here

    }
    public void testComponentArgumentsShouldNotPropogateToParts(){
      final Container yan = createYanContainer();
      yan.registerValue("default prefix");
      yan.registerComponent(Components.value(1));
      final Component tag = Components.method(this, "tag");
      final Component target = tag
        .withArgument(0, Components.method(this, "tag"))
        .withArgument(1, Components.value(0));
      yan.registerComponent("target", target);
      final Object result = yan.getInstance("target");
      assertEquals("default prefix10", ""+result);
View Full Code Here

      yan.registerComponent("target", target);
      final Object result = yan.getInstance("target");
      assertEquals("default prefix10", ""+result);
    }
    public void testUsePropertyCannotBeAppliedToTopLevel(){
      final Component use1 = Components.useProperty(String.class, "prop1", String.class)
        .withProperty("prop1", Components.value("hello"));
      final Container yan = createYanContainer();
      yan.registerComponent("target", use1);
      try{
        yan.verify();
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.