KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > broker > ObjectRepository


1 package org.apache.ojb.broker;
2
3 import java.io.Serializable JavaDoc;
4 import java.util.Collection JavaDoc;
5
6 import org.apache.commons.lang.builder.EqualsBuilder;
7 import org.apache.commons.lang.builder.ToStringBuilder;
8
9 /**
10  * Helper class centralize test classes.
11  *
12  * @author <a HREF="mailto:armin@codeAuLait.de">Armin Waibel</a>
13  * @version $Id: ObjectRepository.java,v 1.6.2.2 2005/12/17 01:39:10 arminw Exp $
14  */

15 public class ObjectRepository
16 {
17     public static class Component
18             implements ComponentIF
19     {
20         Integer JavaDoc id;
21         int type;
22         String JavaDoc name;
23         Group group;
24         ComponentIF parentComponent;
25         Collection JavaDoc childComponents;
26
27         public boolean equals(Object JavaDoc obj)
28         {
29             boolean result = false;
30             if(obj instanceof ComponentIF)
31             {
32                 ComponentIF other = (ComponentIF) obj;
33                 result = new EqualsBuilder()
34                  .append(this.getId(), other.getId())
35                  .append(this.getName(), other.getName())
36                  .append(this.getType(), other.getType())
37                  .isEquals();
38             }
39             return result;
40         }
41
42         public String JavaDoc toString()
43         {
44             return ToStringBuilder.reflectionToString(this);
45         }
46
47         public Integer JavaDoc getId()
48         {
49             return id;
50         }
51
52         public void setId(Integer JavaDoc id)
53         {
54             this.id = id;
55         }
56
57         public Group getGroup()
58         {
59             return group;
60         }
61
62         public void setGroup(Group group)
63         {
64             this.group = group;
65         }
66
67         public ComponentIF getParentComponent()
68         {
69             return parentComponent;
70         }
71
72         public void setParentComponent(ComponentIF parentComponent)
73         {
74             this.parentComponent = parentComponent;
75         }
76
77         public Collection JavaDoc getChildComponents()
78         {
79             return childComponents;
80         }
81
82         public void setChildComponents(Collection JavaDoc childComponents)
83         {
84             this.childComponents = childComponents;
85         }
86
87         public int getType()
88         {
89             return type;
90         }
91
92         public void setType(int type)
93         {
94             this.type = type;
95         }
96
97         public String JavaDoc getName()
98         {
99             return name;
100         }
101
102         public void setName(String JavaDoc name)
103         {
104             this.name = name;
105         }
106     }
107
108     public static interface ComponentIF extends Serializable JavaDoc
109     {
110         Integer JavaDoc getId();
111         void setId(Integer JavaDoc id);
112         ObjectRepository.Group getGroup();
113         void setGroup(ObjectRepository.Group group);
114         ComponentIF getParentComponent();
115         void setParentComponent(ComponentIF parentComponent);
116         Collection JavaDoc getChildComponents();
117         void setChildComponents(Collection JavaDoc childComponents);
118         int getType();
119         void setType(int type);
120         String JavaDoc getName();
121         void setName(String JavaDoc name);
122     }
123
124     public static class Group implements Serializable JavaDoc
125     {
126         Integer JavaDoc id;
127         String JavaDoc name;
128
129         public Integer JavaDoc getId()
130         {
131             return id;
132         }
133
134         public void setId(Integer JavaDoc id)
135         {
136             this.id = id;
137         }
138
139         public String JavaDoc getName()
140         {
141             return name;
142         }
143
144         public void setName(String JavaDoc name)
145         {
146             this.name = name;
147         }
148     }
149
150     public static abstract class AB implements Serializable JavaDoc
151     {
152         private int id;
153         /**
154          * This special attribute telling OJB which concrete class this Object has.
155          * NOTE: this attribute MUST be called ojbConcreteClass
156          */

157         private String JavaDoc ojbConcreteClass;
158
159         protected AB()
160         {
161             // this guarantee that always the correct class name will be set
162
this.ojbConcreteClass = this.getClass().getName();
163         }
164
165         protected AB(int id)
166         {
167             this();
168             this.id = id;
169         }
170
171         public int getId()
172         {
173             return id;
174         }
175
176         public void setId(int id)
177         {
178             this.id = id;
179         }
180
181         public String JavaDoc getOjbConcreteClass()
182         {
183             return ojbConcreteClass;
184         }
185
186         public void setOjbConcreteClass(String JavaDoc ojbConcreteClass)
187         {
188             this.ojbConcreteClass = ojbConcreteClass;
189         }
190     }
191
192     public static interface AAlone
193     {
194     }
195
196     public static class A extends AB implements AAlone
197     {
198         private int someValue;
199         private String JavaDoc someAField;
200
201         public A()
202         {
203             super();
204         }
205
206         public A(int pId, int pSomeValue)
207         {
208             super(pId);
209             this.someValue = pSomeValue;
210         }
211
212         public String JavaDoc getSomeAField()
213         {
214             return someAField;
215         }
216
217         public void setSomeAField(String JavaDoc someAField)
218         {
219             this.someAField = someAField;
220         }
221
222         public int getSomeValue()
223         {
224             return someValue;
225         }
226
227         public void setSomeValue(int someValue)
228         {
229             this.someValue = someValue;
230         }
231     }
232
233     public static class B extends AB
234     {
235         private int someValue;
236         private String JavaDoc someBField;
237
238         public B()
239         {
240             super();
241         }
242
243         public B(int pId, int pSomeValue)
244         {
245             super(pId);
246             this.someValue = pSomeValue;
247         }
248
249         public String JavaDoc getSomeBField()
250         {
251             return someBField;
252         }
253
254         public void setSomeBField(String JavaDoc someBField)
255         {
256             this.someBField = someBField;
257         }
258
259         public int getSomeValue()
260         {
261             return someValue;
262         }
263
264         public void setSomeValue(int someValue)
265         {
266             this.someValue = someValue;
267         }
268     }
269
270     public static class B1 extends B
271     {
272         public B1()
273         {
274             super();
275         }
276
277         public B1(int pId, int pSomeValue)
278         {
279             super(pId, pSomeValue);
280         }
281     }
282
283     public static class C implements Serializable JavaDoc
284     {
285         private String JavaDoc ojbConcreteClass;
286         private int id;
287         private int someValue;
288
289         public C()
290         {
291             ojbConcreteClass = this.getClass().getName();
292         }
293
294         public C(int pId, int pSomeValue)
295         {
296             this();
297             this.id = pId;
298             this.someValue = pSomeValue;
299         }
300
301         public int getId()
302         {
303             return id;
304         }
305
306         public void setId(int id)
307         {
308             this.id = id;
309         }
310
311         public String JavaDoc getOjbConcreteClass()
312         {
313             return ojbConcreteClass;
314         }
315
316         public void setOjbConcreteClass(String JavaDoc ojbConcreteClass)
317         {
318             this.ojbConcreteClass = ojbConcreteClass;
319         }
320
321         public int getSomeValue()
322         {
323             return someValue;
324         }
325
326         public void setSomeValue(int someValue)
327         {
328             this.someValue = someValue;
329         }
330     }
331
332     public static class D extends C
333     {
334         public D()
335         {
336             super();
337         }
338
339         public D(int pId, int pSomeValue)
340         {
341             super(pId, pSomeValue);
342         }
343     }
344
345     public static class E implements Serializable JavaDoc
346     {
347         private Integer JavaDoc id;
348         private int someSuperValue;
349
350         public Integer JavaDoc getId()
351         {
352             return id;
353         }
354
355         public void setId(Integer JavaDoc id)
356         {
357             this.id = id;
358         }
359
360         public int getSomeSuperValue()
361         {
362             return someSuperValue;
363         }
364
365         public void setSomeSuperValue(int someSuperValue)
366         {
367             this.someSuperValue = someSuperValue;
368         }
369     }
370
371     /**
372      * important note:
373      * This class uses an anonymous field to hold the foreign key referencing to the parent table.
374      * thus there is no attribute holding the FK in the class.
375      * There is also no additional coding required to populate the inherited attributes
376      * on loading or persiting an instance of this class.
377      */

378     public static class F extends E implements Serializable JavaDoc
379     {
380         int someValue;
381
382         public int getSomeValue()
383         {
384             return someValue;
385         }
386
387         public void setSomeValue(int someValue)
388         {
389             this.someValue = someValue;
390         }
391     }
392
393     public static class G extends F implements Serializable JavaDoc
394     {
395         int someSubValue;
396
397         public int getSomeSubValue()
398         {
399             return someSubValue;
400         }
401
402         public void setSomeSubValue(int someSubValue)
403         {
404             this.someSubValue = someSubValue;
405         }
406     }
407
408     public static class F1 extends E implements Serializable JavaDoc
409     {
410         int someValue;
411
412         public int getSomeValue()
413         {
414             return someValue;
415         }
416
417         public void setSomeValue(int someValue)
418         {
419             this.someValue = someValue;
420         }
421     }
422
423     public static class G1 extends F1 implements Serializable JavaDoc
424     {
425         int someSubValue;
426
427         public int getSomeSubValue()
428         {
429             return someSubValue;
430         }
431
432         public void setSomeSubValue(int someSubValue)
433         {
434             this.someSubValue = someSubValue;
435         }
436     }
437 }
438
439
Popular Tags