Search in sources :

Example 11 with Ioc

use of org.nutz.ioc.Ioc in project nutz by nutzam.

the class SimpleJsonIocTest method test_2darray_iocvalue.

@Test
public void test_2darray_iocvalue() {
    Ioc ioc = I("obj:{args:[[['a','b'],['c','d']]]}");
    IocTO00 obj = ioc.get(IocTO00.class, "obj");
    assertEquals(2, obj.getStrss().length);
    assertEquals(2, obj.getStrss()[0].length);
    assertEquals("a", obj.getStrss()[0][0]);
    assertEquals("b", obj.getStrss()[0][1]);
    assertEquals("c", obj.getStrss()[1][0]);
    assertEquals("d", obj.getStrss()[1][1]);
}
Also used : IocTO00(org.nutz.ioc.json.pojo.IocTO00) Ioc(org.nutz.ioc.Ioc) NutIoc(org.nutz.ioc.impl.NutIoc) Test(org.junit.Test)

Example 12 with Ioc

use of org.nutz.ioc.Ioc in project nutz by nutzam.

the class SimpleJsonIocTest method test_break_parent2.

@Test(expected = IocException.class)
public void test_break_parent2() {
    Ioc ioc = I(J("fox", "name:'P',age:10"), J("f2", "parent:'x'"), J("f3", "parent:'y'"));
    ioc.get(Animal.class, "f3");
}
Also used : Ioc(org.nutz.ioc.Ioc) NutIoc(org.nutz.ioc.impl.NutIoc) Test(org.junit.Test)

Example 13 with Ioc

use of org.nutz.ioc.Ioc in project nutz by nutzam.

the class SimpleJsonIocTest method test_array_and_refer.

@Test
public void test_array_and_refer() {
    Ioc ioc = I(J("fox", "name:'Fox'"), J("rabit", "name:'Rabit',enemies:[{refer:'fox:org.nutz.ioc.json.pojo.Animal'},null]"));
    Animal r = ioc.get(Animal.class, "rabit");
    Animal f = ioc.get(Animal.class, "fox");
    assertEquals(2, r.getEnemies().length);
    assertTrue(f == r.getEnemies()[0]);
    assertEquals("Fox", f.getName());
    assertEquals("Rabit", r.getName());
    assertNull(r.getEnemies()[1]);
}
Also used : Animal(org.nutz.ioc.json.pojo.Animal) Ioc(org.nutz.ioc.Ioc) NutIoc(org.nutz.ioc.impl.NutIoc) Test(org.junit.Test)

Example 14 with Ioc

use of org.nutz.ioc.Ioc in project nutz by nutzam.

the class SimpleJsonIocTest method test_break_parent.

@Test(expected = IocException.class)
public void test_break_parent() {
    Ioc ioc = I(J("f2", "parent:'f3'"), J("f3", "parent:'f2'"));
    ioc.get(Animal.class, "f3");
}
Also used : Ioc(org.nutz.ioc.Ioc) NutIoc(org.nutz.ioc.impl.NutIoc) Test(org.junit.Test)

Example 15 with Ioc

use of org.nutz.ioc.Ioc in project nutz by nutzam.

the class ModuleProcessor method process.

public void process(ActionContext ac) throws Throwable {
    RequestIocContext reqContext = null;
    try {
        if (null != moduleObj) {
            ac.setModule(moduleObj);
        } else {
            Ioc ioc = ac.getIoc();
            Object obj;
            /*
                 * 如果 Ioc 容器实现了高级接口,那么会为当前请求设置上下文对象
                 */
            if (NutSessionListener.isSessionScopeEnable && ioc instanceof Ioc2) {
                reqContext = new RequestIocContext(ac.getRequest());
                HttpSession sess = Mvcs.getHttpSession(false);
                IocContext myContext = null;
                // 如果容器可以创建 Session ...
                if (null != sess) {
                    SessionIocContext sessionContext = new SessionIocContext(sess);
                    myContext = new ComboContext(reqContext, sessionContext);
                } else // 如果容器禁止了 Session ...
                {
                    myContext = reqContext;
                }
                Mvcs.setIocContext(myContext);
                obj = ((Ioc2) ioc).get(moduleType, injectName, myContext);
            } else
                /*
                 * 否则,则仅仅简单的从容器获取
                 */
                obj = ioc.get(moduleType, injectName);
            ac.setModule(obj);
        }
        ac.setMethod(method);
        // if (log.isDebugEnabled()) //打印实际执行的Method信息
        // log.debugf("Handle URL[%s] by Method[%s]",ac.getPath(),method);
        doNext(ac);
    } finally {
        if (reqContext != null)
            try {
                reqContext.depose();
            } catch (Throwable e) {
                if (log.isDebugEnabled())
                    log.debug("ReqContext depose fail?!", e);
            }
    }
}
Also used : ComboContext(org.nutz.ioc.impl.ComboContext) SessionIocContext(org.nutz.mvc.ioc.SessionIocContext) RequestIocContext(org.nutz.mvc.ioc.RequestIocContext) IocContext(org.nutz.ioc.IocContext) SessionIocContext(org.nutz.mvc.ioc.SessionIocContext) HttpSession(javax.servlet.http.HttpSession) Ioc2(org.nutz.ioc.Ioc2) Ioc(org.nutz.ioc.Ioc) RequestIocContext(org.nutz.mvc.ioc.RequestIocContext)

Aggregations

Ioc (org.nutz.ioc.Ioc)35 NutIoc (org.nutz.ioc.impl.NutIoc)29 Test (org.junit.Test)27 Animal (org.nutz.ioc.json.pojo.Animal)15 JsonLoader (org.nutz.ioc.loader.json.JsonLoader)6 Ioc2 (org.nutz.ioc.Ioc2)3 IocContext (org.nutz.ioc.IocContext)2 IocLoader (org.nutz.ioc.IocLoader)2 IocTO00 (org.nutz.ioc.json.pojo.IocTO00)2 MapLoader (org.nutz.ioc.loader.map.MapLoader)2 Stopwatch (org.nutz.lang.Stopwatch)2 LoadingException (org.nutz.mvc.LoadingException)2 File (java.io.File)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Properties (java.util.Properties)1 HttpSession (javax.servlet.http.HttpSession)1 User (net.wendal.nutzdemo.bean.User)1 Dao (org.nutz.dao.Dao)1 ComboContext (org.nutz.ioc.impl.ComboContext)1