KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > PartImpl


1 // $Id: PartImpl.java,v 1.1 2001/12/17 17:45:08 per_nyfelt Exp $
2

3 import java.io.*;
4 import java.util.*;
5 import org.ozoneDB.*;
6
7
8 public final class PartImpl extends OzoneObject implements Part, Externalizable {
9     
10     protected String JavaDoc type = "part-type9999";
11     protected int x;
12     protected int y;
13     protected Date build;
14     protected Vector to;
15     protected Vector from;
16     
17     
18     public PartImpl() {
19         build = new Date();
20         to = new Vector();
21         from = new Vector();
22     }
23     
24     
25     public void connect( int index, Part part ) throws Exception JavaDoc {
26         to.addElement( new Connection( part ) );
27         part.backConnect( this );
28     }
29     
30     
31     public void backConnect( Part part ) {
32         if (!(part instanceof OzoneProxy)) {
33             throw new RuntimeException JavaDoc( "backConnect(): parameter is not converted." );
34         }
35         
36         from.addElement( part );
37     // from.add (part);
38
}
39     
40     
41     public void deconnect() throws Exception JavaDoc {
42         for (Enumeration e = to.elements(); e.hasMoreElements();) {
43             Connection connection = (Connection)e.nextElement();
44             connection.p.deBackConnect( this );
45         }
46         to.clear();
47     
48     // DxIterator it = to.iterator();
49
// Connection connection;
50
// while ((connection=(Connection)it.next()) != null)
51
// connection.p.deBackConnect (this);
52
}
53     
54     
55     public void deBackConnect( Part part ) {
56         if (!from.removeElement( part )) {
57             throw new RuntimeException JavaDoc( "deBackConnect(): cannot remove part." );
58         }
59     
60     // DxIterator it = from.iterator();
61
// while (it.next() != null) {
62
// if (((OzoneProxy)part).isSame ((OzoneProxy)it.object())) {
63
// it.removeObject();
64
// break;
65
// }
66
// }
67
// throw new RuntimeException ("deBackConnect(): part not found.");
68
}
69     
70     
71     public void set( String JavaDoc _type, int _x, int _y ) {
72         type = _type.toString();
73         x = _x;
74         y = _y;
75     //throw new NullPointerException();
76
}
77     
78     
79     public void get() {
80     }
81     
82     
83     public void traversal( int _x, int _y, int depth ) throws Exception JavaDoc {
84         x = _x;
85         y = _y;
86         
87         // do some db independent crunching
88
// String[] dummies = new String[1000];
89
// for (int i=0; i<1000; i++)
90
// dummies[i] = String.valueOf (i);
91

92         
93         if (depth > 1) {
94             for (Enumeration e = to.elements(); e.hasMoreElements();) {
95                 Connection connection = (Connection)e.nextElement();
96                 connection.p.traversal( _x, _y, depth - 1 );
97             }
98         }
99     }
100     
101     
102     public void writeExternal( ObjectOutput out ) throws IOException {
103         out.writeLong( build.getTime() );
104         out.writeObject( type );
105         out.writeInt( x );
106         out.writeInt( y );
107         out.writeObject( to );
108         out.writeObject( from );
109     }
110     
111     
112     public synchronized void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException JavaDoc {
113         build = new Date( in.readLong() );
114         type = (String JavaDoc)in.readObject();
115         x = in.readInt();
116         y = in.readInt();
117         to = (Vector)in.readObject();
118         from = (Vector)in.readObject();
119     }
120     
121     
122     public void done() throws Exception JavaDoc {
123     }
124     
125 }
126
Popular Tags