1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.jxpath.ri.model.dynamic;
18
19 import java.util.HashMap;
20 import java.util.Map;
21 import java.util.Vector;
22
23 import org.apache.commons.jxpath.AbstractFactory;
24 import org.apache.commons.jxpath.JXPathContext;
25 import org.apache.commons.jxpath.NestedTestBean;
26 import org.apache.commons.jxpath.Pointer;
27 import org.apache.commons.jxpath.TestBean;
28
29
30
31
32
33
34
35 public class TestDynamicPropertyFactory extends AbstractFactory {
36
37
38
39
40
41 public boolean createObject(
42 JXPathContext context,
43 Pointer pointer,
44 Object parent,
45 String name,
46 int index)
47 {
48 if (name.equals("map")) {
49 ((TestBean) parent).setMap(new HashMap());
50 return true;
51 }
52 else if (name.equals("TestKey1")) {
53 ((Map) parent).put(name, "");
54 return true;
55 }
56 else if (name.equals("TestKey2")) {
57 ((Map) parent).put(name, new NestedTestBean("newName"));
58 return true;
59 }
60 else if (name.equals("TestKey3")) {
61 Vector v = new Vector();
62 for (int i = 0; i <= index; i++) {
63 v.add(null);
64 }
65 ((Map) parent).put(name, v);
66 return true;
67 }
68 else if (name.equals("TestKey4")) {
69 ((Map) parent).put(name, new Object[] { new TestBean()});
70 return true;
71 }
72 return false;
73 }
74
75 public boolean declareVariable(JXPathContext context, String name) {
76 return false;
77 }
78 }