01: /*
02: * Copyright 1999-2004 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
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(JXPathContext context, Pointer pointer,
36: Object parent, String name, int index) {
37: if (name.equals("nestedBean")) {
38: ((TestBean) parent).setNestedBean(new NestedTestBean(
39: "newName"));
40: return true;
41: } else if (name.equals("beans")) {
42: TestBean bean = (TestBean) parent;
43: if (bean.getBeans() == null
44: || index >= bean.getBeans().length) {
45: bean.setBeans(new NestedTestBean[index + 1]);
46: }
47: bean.getBeans()[index] = new NestedTestBean("newName");
48: return true;
49: } else if (name.equals("integers")) {
50: // This will implicitly expand the collection
51: ((TestBean) parent).setIntegers(index, 0);
52: return true;
53: }
54: return false;
55: }
56:
57: /**
58: * Create a new object and set it on the specified variable
59: */
60: public boolean declareVariable(JXPathContext context, String name) {
61: return false;
62: }
63: }
|