Package jfun.yan

Examples of jfun.yan.Component


        r = r.followedBy(Components.method(v, givers[i]));
      }
      return r;
    }
    private Verifiable verifyProperties(Class t, String[] givers){
      Component r = Components.value(null).cast(t);
      for(int i=0; i<givers.length; i++){
        r = r.followedBy(
            Components.method(t, null, givers[i])
        );
      }
      return r;
    }
View Full Code Here


   * Subclass can call this method and apply customized lifecycle.
   */
  protected Component evaluateNoLifecycle(){
    checkMandatory("class", hostclass, "component", cc);
    checkMandatory("name", method_name);
    Component result;
    final Class[] param_types = getParameterTypes();
    if(cc != null){
      if(hostclass != null){
        final Method mtd = lookupMethod(param_types);
        result = cc.method(mtd);
View Full Code Here

public class SimpleTestCase extends BaseConfigurationTest {
  public void test1()
  throws Throwable{

    runTest("test/yan/test.xml");
    final Component c = yan.getComponent("service_maker");
    assertNotNull(c);
    final BankAccount acc = new BankAccount("test", 1000000);
    final Component service =
      c.withArguments(new Component[]{Components.value(acc), Components.value("getBalance")});
    final Integer bal = (Integer)yan.instantiateComponent(service);
    assertEquals(1000000, bal.intValue());
   
    final Component acct_request = yan.getComponent("bankaccount_request");
    final HashMap props = new HashMap();
    props.put("balance", new Integer(6666));
    final Integer result = (Integer)yan.instantiateComponent(
        acct_request.withArgument(0, Components.value(props)));
    assertEquals(6666, result.intValue());
   
    final Component acct_request2 = yan.getComponent("bankaccount_request2");
    final HashMap props2 = new HashMap();
    props.put("balance", new Integer(7777));
    final String result2 = (String)yan.instantiateComponent(
        acct_request2.withArgument(0, Components.value(props2)));
    assertEquals("this is my test", result2);
   
   
  }
View Full Code Here

  public Component eval()
  throws IntrospectionException{
    checkMandatory("component", component);
    checkMandatory("name", name);
    Component result = component;
    if(ind < 0){
      result = result.setter(name);
    }
    else{
      result = result.setter(name, ind);
    }
    final Object val = getVal();
    final Object defval = getDefault();
    if(val==null && defval==null){
      return result;
    }
   
    return result.bindArguments(new ParameterBinder(){
      public Creator bind(Signature src, int ind, Class type) {
        if(ind==0){
          Component arg = getVal(type);
          Component def = getDefault(type);
          Component result = arg;
          if(result==null){
            result = Components.useArgument(src, ind, type);
          }
          if(def!=null){
            result = Monad.mplus(result, def);
View Full Code Here

   * Subclass can call this method and apply customized lifecycle.
   */
  protected Component evaluateNoLifecycle(){
    checkMandatory("class", type);
    final Constructor ctor = lookupConstructor();
    Component result = Components.fun(Functions.ctor(ctor));
    return decorateComponent(result);
  }
View Full Code Here

    this.binder = binder;
  }


  public Component eval(){
    final Component c1 = getMandatory();
    checkMandatory("binder", binder);
    return followup?c1.followedBy(binder):c1.bind(binder);
  }
View Full Code Here

    }
  }
  public Component eval(){
    final Component[] elements = getMandatoryElements();
    final Class ltype = getType(HashSet.class);
    final Component step1 = new SimpleComponent(ltype){
      public Object create(){
        return createSet(elements.length);
      }
      public String toString(){
        return "set"+StringUtils.listArray("[",",","]",elements);
View Full Code Here

    final int sz = keys.size();
    final Component[] vals = new Component[sz];
    for(int i=0; i<sz; i++){
      final Object key = keys.get(i);
      final MapEntry entry = (MapEntry)components.get(key);
      Component val = entry.getVal(Object.class);
      final Component def = entry.getDefault(Object.class);
      if(def!=null){
        val = Monad.mplus(val, def);
      }
      vals[i] = (of==null)?val:Util.convert(entry, of, val);
    }
View Full Code Here

    }
  }
  public Component eval(){
    final Component[] elements = getMandatoryElements();
    final Class ltype = getType(ArrayList.class);
    final Component step1 = new SimpleComponent(ltype){
      public Object create(){
        return createList(elements.length);
      }
      public String toString(){
        return "list"+StringUtils.listArray("[",",","]",elements);
View Full Code Here

  public Component eval(){
    checkMandatory("map type", type);
    final List keys = getKeys();
    final int sz = keys.size();
    final Component[] vals = getEntryComponents();
    final Component step1 = new SimpleComponent(type){
      public Object create(){
        return createMap(sz);
      }
    };
    return Components.storeMap(step1, keys.toArray(), vals);
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.