Examples of BeanDefine


Examples of org.tamacat.di.define.BeanDefine

            startValue(attributes);
        }
    }

    protected void startBean(Attributes attributes) {
        bean = new BeanDefine();
        bean.setId(attributes.getValue(ID));
        bean.setAliases(attributes.getValue(NAME));
        bean.setType(ClassUtils.forName(attributes.getValue(CLASS), getClassLoader()));
        //factory-method
        String factoryMethod = attributes.getValue(FACTORY_METHOD);
View Full Code Here

Examples of org.tamacat.di.define.BeanDefine

     * @param id
     * @return Object
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
  synchronized <T> T getBean(String id, Class<T> type) {
        BeanDefine def = defines.get(id);
        if (def == null) {
            throw new DIContainerException("Error: [" + id + "] is not found in BeanDefines.");
        }

        //singleton instance
        if (def.isSingleton()) {
            //instance is null then create new instance.
            BeanAdapter<Object> adapter = beans.get(id);
            if (adapter == null) {
                Object instance = newInstance(def);
                beans.put(id, new BeanAdapter(id, def.getType(), instance));
                return (T) instance;
            } else {
                return (T) initializeInstance(def, adapter.getInstance());
            }
        } else { //Prototype, always new instance.
View Full Code Here

Examples of org.tamacat.di.define.BeanDefine

    }
   
    public synchronized <T>void removeBeans(Class<T> type) {
        String[] keys = StringUtils.toStringArray(defines.keySet());
        for (String key : keys) {
          BeanDefine def = defines.get(key);
          if (def.getType().equals(type)) {
            defines.remove(key);
            beans.remove(key);
          }
        }
    }
View Full Code Here

Examples of org.tamacat.di.define.BeanDefine

    assertEquals(SampleCore.class, di.getBean("Core").getClass());
  }
 
  @Test
  public void testConfigureBeanDefine() {
    BeanDefine define = new BeanDefine();
    define.setId("Core");
    define.setType(SampleCore.class);
    DIContainer di = DI.configure(define);
    assertEquals(SampleCore.class, di.getBean("Core").getClass());
  }
View Full Code Here

Examples of org.tamacat.di.define.BeanDefine

  }
 
  @Test
  public void testConfigureBeanDefineMap() {
    BeanDefineMap map = new BeanDefineMap();
    BeanDefine define = new BeanDefine();
    define.setId("Core");
    define.setType(SampleCore.class);
    map.add(define);
   
    DIContainer di = DI.configure(map);
    assertEquals(SampleCore.class, di.getBean("Core").getClass());
  }
View Full Code Here

Examples of org.tamacat.di.define.BeanDefine

    }

    @Test
    public void testGetBean() {
        for (Entry<String, BeanDefine> def : creator.getDefines().entrySet()) {
            BeanDefine bean = def.getValue();
            trace("class=" + bean.getType().getName());
            trace("  id=" + bean.getId() + " singleton=" + bean.isSingleton());
            List<BeanConstructorParam> cpList = bean.getConstructorArgs();
            for (BeanConstructorParam p : cpList) {
                trace("    constructor-arg ref=" + p.getRefId());
                trace("    constructor-arg value=" + p.getValue());
                trace("    constructor-arg type=" + p.getType());
            }

            List<BeanDefineParam> pList = bean.getPropertyList();
            for (BeanDefineParam p : pList) {
                if (p.isRef()) {
                    trace("    setter ref=" + p.getRefId());
                } else {
                    trace("    setter name=" + p.getName() + " value=" + p.getValue());
View Full Code Here

Examples of org.tamacat.di.define.BeanDefine

    }

    @Test
    public void testDIContainerConstructorMap() {
        BeanDefineMap defines = new BeanDefineMap();
        BeanDefine def = new BeanDefine();
        def.setId("test");
        def.setType("org.tamacat.core.SampleCore", loader);
        def.setSingleton(false);
        defines.put(def.getId(), def);

        di = new TamaCatDIContainer(defines, loader);
        Object o = di.getBean("test");
        assertEquals(o.getClass(), ClassUtils.forName("org.tamacat.core.SampleCore", loader));
    }
View Full Code Here

Examples of org.tamacat.di.define.BeanDefine

   */
  public static void main(String[] args) {
    ClassLoader loader = ClassUtils.getDefaultClassLoader();//new UnloadableClassLoader();
    BeanDefineMap defines = new BeanDefineMap();
   
    BeanDefine def1 = new BeanDefine();
        def1.setId("super");
        def1.setType("org.tamacat.di.impl.DIContainer_test$Super", loader);
        def1.setSingleton(false);
        defines.put(def1.getId(), def1);
       
    BeanDefine def2 = new BeanDefine();
        def2.setId("sub");
        def2.setType("org.tamacat.di.impl.DIContainer_test$Sub", loader);
        def2.setSingleton(false);
        defines.put(def2.getId(), def2);
       
    DIContainer di = new TamaCatDIContainer(defines, loader);
    Super get1 = di.getBean("sub", Super.class);
    System.out.println(get1);
   
View Full Code Here

Examples of org.tamacat.di.define.BeanDefine

    }

    @Test
    public void testDIContainerConstructorMap() {
        BeanDefineMap defines = new BeanDefineMap();
        BeanDefine def = new BeanDefine();
        def.setId("test");
        def.setType("org.tamacat.core.SampleCore", loader);
        def.setSingleton(false);
        defines.put(def.getId(), def);

        di = new TamaCatDIContainer(defines, loader);
        Object o = di.getBean("test");
        assertEquals(o.getClass(), ClassUtils.forName("org.tamacat.core.SampleCore", loader));
    }
View Full Code Here

Examples of org.tamacat.di.define.BeanDefine

    }

    @Test
    public void testDIContainerConstructorMap() {
        BeanDefineMap defines = new BeanDefineMap();
        BeanDefine def = new BeanDefine();
        def.setId("test");
        def.setType("org.tamacat.groovy.test.SampleCore", loader.getClass().getClassLoader());
        def.setSingleton(false);
        defines.put(def.getId(), def);

        di = new GroovyDIContainer(defines, loader);
        Object o = di.getBean("test");
        assertEquals(o.getClass(), ClassUtils.forName(
            "org.tamacat.groovy.test.SampleCore", getClass().getClassLoader()));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.