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.compiler;
17:
18: import org.apache.commons.jxpath.AbstractFactory;
19: import org.apache.commons.jxpath.JXPathContext;
20: import org.apache.commons.jxpath.Pointer;
21: import org.apache.commons.jxpath.TestBean;
22:
23: /**
24: * Test AbstractFactory.
25: *
26: * @author Dmitri Plotnikov
27: * @version $Revision: 1.5 $ $Date: 2004/02/29 14:17:42 $
28: */
29: public class VariableFactory extends AbstractFactory {
30:
31: /**
32: */
33: public boolean createObject(JXPathContext context, Pointer pointer,
34: Object parent, String name, int index) {
35: if (name.equals("testArray")) {
36: ((TestBean[]) parent)[index] = new TestBean();
37: return true;
38: } else if (name.equals("stringArray")) {
39: ((String[]) parent)[index] = "";
40: return true;
41: } else if (name.equals("array")) {
42: ((String[]) parent)[index] = "";
43: return true;
44: }
45: return false;
46: }
47:
48: /**
49: * Create a new object and set it on the specified variable
50: */
51: public boolean declareVariable(JXPathContext context, String name) {
52: if (name.equals("test")) {
53: context.getVariables()
54: .declareVariable(name, new TestBean());
55: return true;
56: } else if (name.equals("testArray")) {
57: context.getVariables().declareVariable(name,
58: new TestBean[0]);
59: return true;
60: } else if (name.equals("stringArray")) {
61: context.getVariables().declareVariable(name,
62: new String[] { "Value1" });
63: return true;
64: }
65: context.getVariables().declareVariable(name, null);
66: return true;
67: }
68: }
|