KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > dyade > aaa > agent > AgentObject


1 /*
2  * Copyright (C) 1996 - 2000 BULL
3  * Copyright (C) 1996 - 2000 INRIA
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA.
19  */

20
21 package fr.dyade.aaa.agent;
22
23 import java.io.*;
24 import java.util.*;
25 import java.lang.reflect.*;
26 import fr.dyade.aaa.util.*;
27
28 /**
29  * The <code>AgentObject</code> class represents ...
30  */

31 public abstract class AgentObject implements Serializable {
32
33
34   transient String JavaDoc name;
35   /**
36    * Loads the <code>AgentObject</code> object
37    * internally designed by the <code>name</code> parameter. Be careful that
38    * including agent should be intialized in engine.
39    *
40    * @param name The object name.
41    *
42    * @exception IOException
43    * when accessing the stored image
44    * @exception ClassNotFoundException
45    * if the stored image class may not be found
46    */

47   static AgentObject
48   load(String JavaDoc name) throws IOException, ClassNotFoundException JavaDoc {
49     return (AgentObject) AgentServer.transaction.load("AgentObject_" + name);
50   }
51
52   /**
53    * Saves the <code>AgentObject</code> object. Be careful, this method
54    * should only be used in the <code>save</code> method of including Agent
55    * in order to preserve the atomicity.
56    *
57    * @exception Exception unspecialized exception
58    */

59   void save() throws IOException {
60     AgentServer.transaction.save(this, "AgentObject_" + name);
61   }
62
63   /**
64    * The <code>writeObject</code> method is responsible for writing the
65    * state of the object for its particular class so that the corresponding
66    * <code>readObject</code> method can restore it.
67    *
68    * @param out the underlying output stream.
69    */

70   private void writeObject(java.io.ObjectOutputStream JavaDoc out)
71     throws IOException {
72     // May be we could not save the name field and get it from
73
// the load method!
74
out.writeObject(name);
75   }
76
77   /**
78    * The <code>readObject</code> is responsible for reading from the stream
79    * and restoring the classes fields.
80    *
81    * @param in the underlying input stream.
82    */

83   private void readObject(java.io.ObjectInputStream JavaDoc in)
84     throws IOException, ClassNotFoundException JavaDoc {
85       name = (String JavaDoc) in.readObject();
86   }
87
88   public AgentObject(String JavaDoc name) {
89     this.name = name;
90   }
91
92   /**
93    * Returns a string representation of this object.
94    *
95    * @return A string representation of this object.
96    */

97   public String JavaDoc toString() {
98     return new String JavaDoc("AgentObject_" + name);
99   }
100 }
101
Popular Tags