KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > simple > GarageImpl


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
// $Id$
8

9 package test.simple;
10
11 import org.ozoneDB.DxLib.*;
12 import org.ozoneDB.OzoneObject;
13
14
15 public class GarageImpl extends OzoneObject implements Garage {
16     String JavaDoc name = "Morris";
17     DxHashMap table = new DxHashMap();
18     DxBag list = new DxArrayBag();
19
20
21     /** */
22     public GarageImpl() {
23     }
24
25
26     /** */
27     public void print() {
28         System.out.println(toString());
29     }
30
31
32     /** */
33     public void printAll() throws Exception JavaDoc {
34         DxIterator it = table.iterator();
35         Auto auto;
36         while ((auto = (Auto) it.next()) != null) {
37             auto.print();
38         }
39     }
40
41
42     /** */
43     public Auto[] getAll() throws Exception JavaDoc {
44         Auto[] ans = new Auto[table.count()];
45         DxIterator it = table.iterator();
46         for (int c = 0; it.next() != null; c++) {
47             ans[c] = (Auto) it.object();
48         }
49         return ans;
50     }
51
52
53     /** */
54     public int[] _setAll(Auto a0, int[] a1, Integer JavaDoc[] a2) throws Exception JavaDoc {
55         System.out.println("Got " + a1.length + " ints...");
56         System.out.println("Got " + a2.length + " Integrs...");
57         return a1;
58     }
59
60
61     /** */
62     public void setAll(Integer JavaDoc age) throws Exception JavaDoc {
63         DxIterator it = table.iterator();
64         Auto auto;
65         while ((auto = (Auto) it.next()) != null) {
66             auto.setAge(age);
67         }
68     }
69
70
71     /** */
72     public void _addAuto(Auto auto) throws Exception JavaDoc {
73         table.addForKey(auto, auto.name());
74     }
75
76
77     /** */
78     public void _newAuto(String JavaDoc name) throws Exception JavaDoc {
79         Auto auto = (Auto) database().createObject(AutoImpl.class.getName());
80         auto.setName(name.toString());
81         table.addForKey(auto, name);
82         list.add(auto);
83     }
84
85
86     /** */
87     public void _populate(Integer JavaDoc num) throws Exception JavaDoc {
88         for (int i = 0; i < num.intValue(); i++) {
89             String JavaDoc name = "Auto" + String.valueOf(i);
90             _newAuto(name);
91         }
92     }
93
94
95     /** */
96     public Auto autoForName(String JavaDoc search) {
97         return (Auto) table.elementForKey(search);
98     }
99
100
101     /** */
102     public void setAlter(DxInteger alter) throws Exception JavaDoc {
103         DxIterator it = table.iterator();
104         Auto auto;
105         while ((auto = (Auto) it.next()) != null) {
106             auto.setAge(new Integer JavaDoc(alter.toInt()));
107         }
108     }
109
110
111     /** */
112     public void crunch(DxInteger num) throws Exception JavaDoc {
113         int n = num.toInt();
114         for (int i = 0; i < n; i++) {
115             _newAuto(String.valueOf(i));
116         }
117
118         DxIterator it = table.iterator();
119         Auto auto;
120         while ((auto = (Auto) it.next()) != null) {
121             auto.age();
122         }
123     }
124
125
126     /** */
127     public void _lockThis() throws Exception JavaDoc {
128     }
129
130
131     /** */
132     public void _langeTA(Garage garage) throws Exception JavaDoc {
133         Thread.currentThread().sleep(10000);
134         if (garage != null) {
135             garage._lockThis();
136         }
137     }
138
139
140     /**
141      * destructor fuer db-objekte
142      */

143     public void done() throws Exception JavaDoc {
144         System.out.println(toString() + " done.");
145         DxIterator it = table.iterator();
146         Auto auto;
147         while ((auto = (Auto) it.next()) != null) {
148             database().deleteObject(auto);
149         }
150     }
151
152
153     /** */
154     public String JavaDoc toString() {
155         return "Garage:" + name;
156     }
157
158
159     /*
160      * public Object invoke (String methodName, int argNum, Object arg1, Object arg2, Object arg3)
161          throws MethodNotFoundException, IllegalAccessException, IllegalArgumentException, Throwable {
162       if (methodName.equals("toString"))
163          return toString();
164       else if (methodName.equals("print"))
165          print();
166       else if (methodName.equals("crunch"))
167          crunch ((DxInteger)arg1);
168       else if (methodName.equals("langeTA"))
169          langeTA ((Auto)arg1);
170       else if (methodName.equals("lockThis"))
171          lockThis();
172       else if (methodName.equals("printAll"))
173          printAll();
174       else
175          throw new MethodNotFoundException();
176       return null;
177       }
178      */

179     protected void finalize() throws Throwable JavaDoc {
180         // System.out.println (toString() + " abgeraeumt...");
181
}
182 }
183
Popular Tags