1 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 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 { 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 ( "backConnect(): parameter is not converted." ); 34 } 35 36 from.addElement( part ); 37 } 39 40 41 public void deconnect() throws Exception { 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 } 53 54 55 public void deBackConnect( Part part ) { 56 if (!from.removeElement( part )) { 57 throw new RuntimeException ( "deBackConnect(): cannot remove part." ); 58 } 59 60 } 69 70 71 public void set( String _type, int _x, int _y ) { 72 type = _type.toString(); 73 x = _x; 74 y = _y; 75 } 77 78 79 public void get() { 80 } 81 82 83 public void traversal( int _x, int _y, int depth ) throws Exception { 84 x = _x; 85 y = _y; 86 87 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 { 113 build = new Date( in.readLong() ); 114 type = (String )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 { 123 } 124 125 } 126
| Popular Tags
|