Search in sources :

Example 6 with JsonLoader

use of org.nutz.ioc.loader.json.JsonLoader in project nutz by nutzam.

the class EvensJsonIocTest method test_event_from_parent.

@Test
public void test_event_from_parent() {
    Ioc ioc = new NutIoc(new JsonLoader("org/nutz/ioc/json/events.js"));
    Animal f = ioc.get(Animal.class, "fox");
    assertEquals(1, f.getCreateTime());
    assertEquals(1, f.getFetchTime());
    assertEquals(0, f.getDeposeTime());
    ioc.depose();
    assertEquals(1, f.getCreateTime());
    assertEquals(1, f.getFetchTime());
    assertEquals(1, f.getDeposeTime());
}
Also used : NutIoc(org.nutz.ioc.impl.NutIoc) Animal(org.nutz.ioc.json.pojo.Animal) JsonLoader(org.nutz.ioc.loader.json.JsonLoader) Ioc(org.nutz.ioc.Ioc) NutIoc(org.nutz.ioc.impl.NutIoc) Test(org.junit.Test)

Example 7 with JsonLoader

use of org.nutz.ioc.loader.json.JsonLoader in project nutz by nutzam.

the class SimpleJsonIocTest method test_load_from_reader.

@Test
public void test_load_from_reader() throws ObjectLoadException {
    IocLoader loader = new JsonLoader(Streams.fileInr("org/nutz/ioc/json/main.js"));
    assertTrue(loader.getName().length > 0);
}
Also used : IocLoader(org.nutz.ioc.IocLoader) JsonLoader(org.nutz.ioc.loader.json.JsonLoader) Test(org.junit.Test)

Example 8 with JsonLoader

use of org.nutz.ioc.loader.json.JsonLoader in project nutz by nutzam.

the class SimpleJsonIocTest method test_load_from_dir.

@Test
public void test_load_from_dir() throws ObjectLoadException {
    IocLoader loader = new JsonLoader("org/nutz/ioc/json/");
    assertTrue(loader.getName().length > 0);
}
Also used : IocLoader(org.nutz.ioc.IocLoader) JsonLoader(org.nutz.ioc.loader.json.JsonLoader) Test(org.junit.Test)

Example 9 with JsonLoader

use of org.nutz.ioc.loader.json.JsonLoader in project nutz by nutzam.

the class ComboIocLoader method load.

public IocObject load(IocLoading loading, String name) throws ObjectLoadException {
    for (IocLoader iocLoader : iocLoaders) if (iocLoader.has(name)) {
        IocObject iocObject = iocLoader.load(loading, name);
        if (log.isDebugEnabled()) {
            // TODO 弄成更好看的格式,方便debug
            String printName;
            if (iocLoader instanceof AnnotationIocLoader) {
                String packages = Arrays.toString(((AnnotationIocLoader) iocLoader).getPackages());
                printName = "AnnotationIocLoader(packages=" + packages + ")";
            } else if (JsonLoader.class.equals(iocLoader.getClass()) && ((JsonLoader) iocLoader).getPaths() != null) {
                String paths = Arrays.toString(((JsonLoader) iocLoader).getPaths());
                printName = "JsonLoader(paths=" + paths + ")";
            } else {
                printName = iocLoader.getClass().getSimpleName() + "@" + iocLoader.hashCode();
            }
            log.debugf("Found IocObject(%s) in %s", name, printName);
        }
        return iocObject;
    }
    throw new ObjectLoadException("Object '" + name + "' without define!");
}
Also used : AnnotationIocLoader(org.nutz.ioc.loader.annotation.AnnotationIocLoader) ObjectLoadException(org.nutz.ioc.ObjectLoadException) IocObject(org.nutz.ioc.meta.IocObject) XmlIocLoader(org.nutz.ioc.loader.xml.XmlIocLoader) IocLoader(org.nutz.ioc.IocLoader) AsyncAopIocLoader(org.nutz.aop.interceptor.async.AsyncAopIocLoader) AnnotationIocLoader(org.nutz.ioc.loader.annotation.AnnotationIocLoader) PropertiesIocLoader(org.nutz.ioc.loader.properties.PropertiesIocLoader) TransIocLoader(org.nutz.aop.interceptor.ioc.TransIocLoader) JsonLoader(org.nutz.ioc.loader.json.JsonLoader)

Aggregations

JsonLoader (org.nutz.ioc.loader.json.JsonLoader)9 Test (org.junit.Test)7 Ioc (org.nutz.ioc.Ioc)6 NutIoc (org.nutz.ioc.impl.NutIoc)6 IocLoader (org.nutz.ioc.IocLoader)5 AsyncAopIocLoader (org.nutz.aop.interceptor.async.AsyncAopIocLoader)1 TransIocLoader (org.nutz.aop.interceptor.ioc.TransIocLoader)1 ObjectLoadException (org.nutz.ioc.ObjectLoadException)1 Animal (org.nutz.ioc.json.pojo.Animal)1 Mammal (org.nutz.ioc.json.pojo.Mammal)1 AnnotationIocLoader (org.nutz.ioc.loader.annotation.AnnotationIocLoader)1 PropertiesIocLoader (org.nutz.ioc.loader.properties.PropertiesIocLoader)1 XmlIocLoader (org.nutz.ioc.loader.xml.XmlIocLoader)1 IocObject (org.nutz.ioc.meta.IocObject)1 Log (org.nutz.log.Log)1 SystemLogAdapter (org.nutz.log.impl.SystemLogAdapter)1