KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > jxpath > ri > model > dynamic > TestDynamicPropertyFactory


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.dynamic;
17
18 import java.util.HashMap JavaDoc;
19 import java.util.Map JavaDoc;
20 import java.util.Vector JavaDoc;
21
22 import org.apache.commons.jxpath.AbstractFactory;
23 import org.apache.commons.jxpath.JXPathContext;
24 import org.apache.commons.jxpath.NestedTestBean;
25 import org.apache.commons.jxpath.Pointer;
26 import org.apache.commons.jxpath.TestBean;
27
28 /**
29  * Test AbstractFactory.
30  *
31  * @author Dmitri Plotnikov
32  * @version $Revision: 1.5 $ $Date: 2004/02/29 14:17:45 $
33  */

34 public class TestDynamicPropertyFactory extends AbstractFactory {
35
36     /**
37      * Create a new instance and put it in the collection on the parent object.
38      * Return <b>false</b> if this factory cannot create the requested object.
39      */

40     public boolean createObject(
41         JXPathContext context,
42         Pointer pointer,
43         Object JavaDoc parent,
44         String JavaDoc name,
45         int index)
46     {
47         if (name.equals("map")) {
48             ((TestBean) parent).setMap(new HashMap JavaDoc());
49             return true;
50         }
51         else if (name.equals("TestKey1")) {
52             ((Map JavaDoc) parent).put(name, "");
53             return true;
54         }
55         else if (name.equals("TestKey2")) {
56             ((Map JavaDoc) parent).put(name, new NestedTestBean("newName"));
57             return true;
58         }
59         else if (name.equals("TestKey3")) {
60             Vector JavaDoc v = new Vector JavaDoc();
61             for (int i = 0; i <= index; i++) {
62                 v.add(null);
63             }
64             ((Map JavaDoc) parent).put(name, v);
65             return true;
66         }
67         else if (name.equals("TestKey4")) {
68             ((Map JavaDoc) parent).put(name, new Object JavaDoc[] { new TestBean()});
69             return true;
70         }
71         return false;
72     }
73
74     public boolean declareVariable(JXPathContext context, String JavaDoc name) {
75         return false;
76     }
77 }
78
Popular Tags