1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jxpath.ri.model.beans;
17
18 import org.apache.commons.jxpath.AbstractFactory;
19 import org.apache.commons.jxpath.JXPathContext;
20 import org.apache.commons.jxpath.NestedTestBean;
21 import org.apache.commons.jxpath.Pointer;
22 import org.apache.commons.jxpath.TestBean;
23
24 /***
25 * Test AbstractFactory.
26 *
27 * @author Dmitri Plotnikov
28 * @version $Revision: 1.8 $ $Date: 2004/02/29 14:17:43 $
29 */
30 public class TestBeanFactory extends AbstractFactory {
31
32 /***
33 * Return <b>false</b> if this factory cannot create the requested object.
34 */
35 public boolean createObject(
36 JXPathContext context,
37 Pointer pointer,
38 Object parent,
39 String name,
40 int index)
41 {
42 if (name.equals("nestedBean")) {
43 ((TestBean) parent).setNestedBean(new NestedTestBean("newName"));
44 return true;
45 }
46 else if (name.equals("beans")) {
47 TestBean bean = (TestBean) parent;
48 if (bean.getBeans() == null || index >= bean.getBeans().length) {
49 bean.setBeans(new NestedTestBean[index + 1]);
50 }
51 bean.getBeans()[index] = new NestedTestBean("newName");
52 return true;
53 }
54 else if (name.equals("integers")) {
55
56 ((TestBean) parent).setIntegers(index, 0);
57 return true;
58 }
59 return false;
60 }
61
62 /***
63 * Create a new object and set it on the specified variable
64 */
65 public boolean declareVariable(JXPathContext context, String name) {
66 return false;
67 }
68 }