1 package org.catacomb.druid.load;
2
3 import org.catacomb.interlish.reflect.ObjectBuilder;
4 import org.catacomb.interlish.reflect.ReflectionConstructor;
5 import org.catacomb.interlish.service.ResourceLoader;
6 import org.catacomb.interlish.structure.Element;
7 import org.catacomb.interlish.util.JUtil;
8 import org.catacomb.serial.om.ElementConstructor;
9 import org.catacomb.serial.xml.XMLReader;
10
11 import java.util.ArrayList;
12
13
14 public class DruidResourceLoader implements ResourceLoader {
15
16
17 ArrayList<String> paths = new ArrayList<String>();
18
19
20 public void addPath(String s) {
21 paths.add(s);
22 }
23
24
25 public Object getResource(String configPath, String selector) {
26 String s = JUtil.getXMLResource(configPath);
27 ReflectionConstructor rin = new ReflectionConstructor();
28
29 if (paths.size() == 0) {
30 rin.addSearchPackage("org.catacomb.druid.blocks");
31 } else {
32 for (String sp : paths) {
33 rin.addSearchPackage(sp);
34 }
35 }
36
37
38 ElementConstructor ein = new ElementConstructor();
39 XMLReader reader = new XMLReader(ein);
40 Object eltobj = reader.readObject(s);
41 Element elt = (Element)eltobj;
42
43 ObjectBuilder builder = new ObjectBuilder(rin);
44 Object ret = builder.buildFromElement(elt);
45
46 return ret;
47 }
48 }