KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > jxpath > TestBean


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;
17
18 import java.util.ArrayList JavaDoc;
19 import java.util.HashMap JavaDoc;
20 import java.util.HashSet JavaDoc;
21 import java.util.List JavaDoc;
22 import java.util.Map JavaDoc;
23 import java.util.Set JavaDoc;
24
25 import org.apache.commons.jxpath.util.ValueUtils;
26
27 /**
28  * General purpose test bean for JUnit tests for the "jxpath" component.
29  *
30  * @author Dmitri Plotnikov
31  * @version $Revision: 1.8 $ $Date: 2004/02/29 14:17:40 $
32  */

33 public class TestBean {
34
35     // ------------------------------------------------------------- Properties
36

37     /**
38      * An array of nested java beans.
39      */

40     private NestedTestBean[] beans;
41     {
42         beans = new NestedTestBean[2];
43         beans[0] = new NestedTestBean("Name 1");
44         beans[1] = new NestedTestBean("Name 2");
45         beans[1].setInt(3);
46     }
47
48     public NestedTestBean[] getBeans() {
49         return beans;
50     }
51
52     public void setBeans(NestedTestBean[] beans) {
53         this.beans = beans;
54     }
55
56     /**
57      * A boolean property.
58      */

59     private boolean bool = false;
60     public boolean getBoolean() {
61         return bool;
62     }
63
64     public void setBoolean(boolean bool) {
65         this.bool = bool;
66     }
67
68     private int integer = 1;
69     /**
70      * A read-only integer property
71      */

72     public int getInt() {
73         return integer;
74     }
75
76     public void setInt(int integer) {
77         this.integer = integer;
78     }
79
80     /**
81      * A read-only array of integers
82      */

83     private int[] array = { 1, 2, 3, 4 };
84     public int[] getIntegers() {
85         return array;
86     }
87
88     public int getIntegers(int index) {
89         return array[index];
90     }
91
92     public void setIntegers(int index, int value) {
93         if (index >= array.length) {
94             array = (int[]) ValueUtils.expandCollection(array, index + 1);
95         }
96         array[index] = value;
97     }
98
99     /**
100      * A heterogeneous list: String, Integer, NestedTestBean
101      */

102     private ArrayList JavaDoc list;
103     public List JavaDoc getList() {
104         if (list == null) {
105             list = new ArrayList JavaDoc();
106             list.add("String 3");
107             list.add(new Integer JavaDoc(3));
108             list.add(new NestedTestBean("Name 3"));
109         }
110         return list;
111     }
112
113     /**
114      * A Map
115      */

116     private HashMap JavaDoc map;
117     {
118         map = new HashMap JavaDoc();
119         map.put("Key1", "Value 1");
120         map.put("Key2", new NestedTestBean("Name 6"));
121     }
122
123     public Map JavaDoc getMap() {
124         return map;
125     }
126
127     public void setMap(Map JavaDoc map) {
128         this.map = (HashMap JavaDoc) map;
129     }
130
131     /**
132      * A nested read-only java bean
133      */

134     private NestedTestBean nestedBean = new NestedTestBean("Name 0");
135     public NestedTestBean getNestedBean() {
136         return nestedBean;
137     }
138
139     public void setNestedBean(NestedTestBean bean) {
140         this.nestedBean = bean;
141     }
142
143     private NestedTestBean object = new NestedTestBean("Name 5");
144
145     /**
146      * Returns a NestedTestBean: testing recognition of generic objects
147      */

148     public Object JavaDoc getObject() {
149         return object;
150     }
151
152     /**
153      * Returns an array of ints: testing recognition of generic objects
154      */

155     public Object JavaDoc getObjects() {
156         return getIntegers();
157     }
158
159     /**
160      * A heterogeneous set: String, Integer, NestedTestBean
161      */

162     private HashSet JavaDoc set;
163     public Set JavaDoc getSet() {
164         if (set == null) {
165             set = new HashSet JavaDoc();
166             set.add("String 4");
167             set.add(new Integer JavaDoc(4));
168             set.add(new NestedTestBean("Name 4"));
169         }
170         return set;
171     }
172
173     public String JavaDoc toString() {
174         return "ROOT";
175     }
176 }
177
Popular Tags