Package jfun.yan

Examples of jfun.yan.Component


    assertEquals("someone", icache3.getName());
    assertEquals(0, icache3.getCapacity());     
  }
  public void testCustomizationsOnProductComponentShouldOverrideFactoryParameter(){
    final Container yan = createYanContainer();
    final Component mycache =
      Components.ctor(MyCache.class,
          new Class[]{String.class, int.class})
      .withArgument(1, Components.value(100));
   
    final Component factory =
      mycache.factory(ICacheFactory.class);
    yan.registerComponent("target", factory);
    final ICacheFactory ifactory =
      (ICacheFactory)yan.getInstance("target");
    final tests.jfun.yan.testmodel.ICache icache = ifactory.createCache("tom", 10);
View Full Code Here


    assertEquals(100, icache3.getCapacity());     
  }
  public void testLocalCustomizationOverridesFactoryParametersRedirectedToPropeties()
  throws Exception{
    final Container yan = createYanContainer();
    final Component mycache =
      Components.bean(MyCache.class)
      //.withProperty("name", Components.value("should not see me"))
      .withProperty("name",
          Components.useProperty(MyCache.class, "capacity", int.class)
          .map(new jfun.yan.Map(){
            public Object map(Object obj){
              return obj.toString();
            }
          }).cast(String.class)
      )
      .withProperty("name", Components.value("should not see me"))
      ;
   
    final Component factory =
      Components.fromArguments(mycache, new String[]{"name","capacity"})
      .factory(ICacheFactory.class);
    yan.registerComponent("target", factory);
    final ICacheFactory ifactory =
      (ICacheFactory)yan.getInstance("target");
View Full Code Here

    assertEquals(0, icache3.getCapacity());     
  }
  public void testFactoryWithParametersRedirectedToPropeties()
  throws Exception{
    final Container yan = createYanContainer();
    final Component mycache =
      Components.bean(MyCache.class);
   
    final Component factory =
      Components.fromArguments(mycache, new String[]{"name","capacity"})
      .factory(ICacheFactory.class);
    yan.registerComponent("target", factory);
    final ICacheFactory ifactory =
      (ICacheFactory)yan.getInstance("target");
View Full Code Here

    assertEquals(0, icache3.getCapacity());     
  }
  public void testFactoryWithParametersRedirectedToPropertiesThenRedirectedBackToArguments()
  throws Exception{
    final Container yan = createYanContainer();
    final Component mycache =
      Components.ctor(MyCache.class, new Class[]{String.class, int.class})
      .fromProperties(new String[]{"name","capacity"});
   
    final Component factory =
      mycache.fromArguments(new String[]{"name","capacity"})
      .factory(ICacheFactory.class);
    yan.registerComponent("target", factory);
    final ICacheFactory ifactory =
      (ICacheFactory)yan.getInstance("target");
View Full Code Here

    assertEquals(0, icache3.getCapacity());     
  }
  public void testFactoryWithBadParameterSequence()
  throws Exception{
    final Container yan = createYanContainer();
    final Component mycache =
      Components.ctor(MyCache.class,
          new Class[]{String.class, int.class});
   
    final Component factory =
      mycache.factory(ICacheFactory2.class);
    yan.registerComponent("target", factory);
    try{
      yan.verify();
      fail("should have failed with ParameterTypeMismatchException");
View Full Code Here

      assertEquals(int.class, e.getActualType());
    }
  }
  public void testFactoryWithBadReturnType(){
    final Container yan = createYanContainer();
    final Component mycache =
      Components.ctor(MyCache.class,
          new Class[]{String.class, int.class});
   
    final Component factory =
      mycache.factory(tests.jfun.yan.testmodel.IMonitoredCacheFactory.class);
    yan.registerComponent("target", factory);
    try{
      yan.verify();
      fail("should have failed with ReturnTypeMismatchException");
View Full Code Here

      assertEquals(MyCache.class, e.getActualType());
    }
  }
  public void testSealedComponent(){
    final Container yan = createYanContainer();
    final Component c1 = Components.ctor(java.util.ArrayList.class, new Class[]{int.class});
    yan.registerComponent("list", c1.seal());
    yan.registerValue(new Integer(10));
    try{
      yan.getInstance("list");
      fail ("should have failed with IrresolveableArgumentException");
    }
    catch(IrresolveableArgumentException e){}
    yan.registerComponent("list", c1.seal().withArgument(0, Components.value(5)));
    yan.getInstance("list");
    //fail ("should have failed with IrresolveableArgumentException");

    yan.registerComponent("list", c1);
    yan.registerComponent("target", Components.useKey("list").seal()
        .withArgument(0, Components.value(12)));
    //try{
      yan.getInstance("target");
      //fail("should have failed with IrresolveableArgumentException");
    //}
    //catch(IrresolveableArgumentException e){}
    //assertEquals(10, result.size());
    yan.registerComponent("list", c1.withArgument(0,
        Components.useArgument(Functions.ctor(
            ArrayList.class, new Class[]{int.class}), 0, int.class)));
    yan.registerComponent("target", Components.useKey("list").seal()
        .withArgument(0, Components.value(12)));
    //try{
      yan.getInstance("target");
      //fail("should have failed with IrresolveableArgumentException");
    //}
    //catch(IrresolveableArgumentException e){}
    yan.registerComponent("list", c1.withArgument(0, Components.useType(int.class)));
    yan.registerComponent("target", Components.useKey("list").seal()
        .withArgument(0, Components.value(12)));
    final java.util.ArrayList result = (ArrayList)yan.getInstance("target");
    final Component array = Components.ctor(String[].class);
   
   
    yan.registerComponent("array", array.withArgument(0, Components.useType(int.class)));
    yan.registerComponent("target", Components.useKey("array").seal()
        .withArgument(0, Components.value(12)));
    final String[] arr = (String[])yan.getInstance("target");
    assertEquals(10, arr.length);
    final Component array2 = Components.ctor(int[].class, new Class[]{int.class});
    yan.registerComponent("array", array2.withArgument(0, Components.useType(int.class)));
    yan.registerComponent("target", Components.useKey("array").seal()
        .withArgument(0, Components.value(12)));
    final int[] arr2 = (int[])yan.getInstance("target");
    assertEquals(10, arr2.length);
    try{
View Full Code Here

    xFire = fire;
  }


  public Component eval() throws IntrospectionException {
    /**
     * Use the ServiceInterface if that is set, otherwise use the Class of
     * the service object.
     */
    final Component cc = super.getComponent();
    Class impltype = getImplementationClass();
    if(impltype==null){
      if(cc!=null){
        impltype = cc.getType();
      }
    }
    Class intf = getServiceClass();
    if (intf == null)
    {
View Full Code Here

  }
  /**
   * Get the Component for the actual servant.
   */
  public Component getServant(){
    final Component cc = getComponent();
    if(cc!=null) return cc;
    if(this.implementationClass != null)
      return Components.ctor(this.implementationClass);
    if(this.serviceInterface != null)
      return Components.ctor(this.serviceInterface);
View Full Code Here

    ServiceBuilder add(String key, Object val){
      props.put(key, toComponent(val));
      return this;
    }
    Component getResult()throws IntrospectionException{
      final Component c = Components.bean(ServiceBean.class)
        .withProperties(props).map(new jfun.yan.Map(){
          public Object map(Object bean){
            return ((ServiceBean)bean).buildService();
          }
        });
      if(getId()==null && isGloballyDefined()){
        //instantiate it using "name".
        registerEagerInstantiation(c);
        return c;
      }
      else
        return c.cast(Service.class);
    }
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.