Das Attribut vom Typ AgentProfile enthält einen Typ
org.omg.CORBA.Any welcher nicht serialisierbar ist. Deshalb werden
die Methoden writeObject() und readObject() neu
implementiert:
1 private void writeObject(java.io.ObjectOutputStream out)
2 throws java.io.IOException {
3 // write AgentProfile in the stream
4 out.writeShort(_agentProfile.language_id);
5 out.writeShort(_agentProfile.agent_system_type);
6 out.writeObject(_agentProfile.agent_system_description);
7 out.writeShort(_agentProfile.major_version);
8 out.writeShort(_agentProfile.minor_version);
9 out.writeShort(_agentProfile.serialization);
10 out.writeInt(_agentProfile.properties.length);
11 for(int i=0; i < _agentProfile.properties.length; i++)
12 out.writeObject(_agentProfile.properties[i].extract_wstring());
13 // go on with the rest of the class
14 out.defaultWriteObject();
15 }
In den Zeilen 4-12 werden die Attribute der Klasse AgentProfile
einzeln serialisiert und in den Stream geschrieben. Anschließend wird
mit der Serialisierung der Agenten-Klasse fortgefahren.
Die Methode readObject(...) liest die Objekte in derselben
Reihenfolge wieder aus:
1 private void readObject(java.io.ObjectInputStream in)
2 throws java.io.IOException, java.lang.ClassNotFoundException{
3 _agentProfile= new CfMAF.AgentProfile();
4 // read AgentProfile out of stream
5 _agentProfile.language_id= in.readShort();
6 _agentProfile.agent_system_type= in.readShort();
7 _agentProfile.agent_system_description= (String)in.readObject();
8 _agentProfile.major_version= in.readShort();
9 _agentProfile.minor_version= in.readShort();
10 _agentProfile.serialization= in.readShort();
11 int nProperties= in.readInt();
12 String props[]= new String[nProperties];
13 org.omg.CORBA.Any anies[]= new org.omg.CORBA.Any[nProperties];
14 for(int i=0; i < nProperties; i++)
15 props[i]= (String) in.readObject();
16 org.omg.CORBA.ORB orb= org.omg.CORBA.ORB.init();
17 for(int i=0; i < nProperties; i++) {
18 org.omg.CORBA.Any any= orb.create_any();
19 any.insert_wstring(props[i]);
20 anies[i]= any;
21 }
22 _agentProfile.properties= anies;
23 // read the rest of the class
24 in.defaultReadObject();
25 }