KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > framework > SerializableJob


1 /*
2  * (c) Rob Gordon 2005
3  */

4 package org.oddjob.framework;
5
6 import java.io.IOException JavaDoc;
7 import java.io.ObjectInputStream JavaDoc;
8 import java.io.ObjectOutputStream JavaDoc;
9 import java.io.Serializable JavaDoc;
10
11 import org.oddjob.images.IconHelper;
12 import org.oddjob.state.JobStateHandler;
13
14 abstract public class SerializableJob extends SimpleJob
15 implements Serializable JavaDoc {
16     private static final long serialVersionUID = 20050925;
17
18     
19     /**
20      * Custom serialsation.
21      */

22     private void writeObject(ObjectOutputStream JavaDoc s)
23     throws IOException JavaDoc {
24         if (destroyed) {
25             throw new IllegalStateException JavaDoc("[" + this + "] destroyed");
26         }
27         lock.accquire("Hard reset in progress.");
28         try {
29             s.defaultWriteObject();
30             s.writeObject(getName());
31             if (getLogger().startsWith(getClass().getName())) {
32                 s.writeObject(null);
33             }
34             else {
35                 s.writeObject(getLogger());
36             }
37             s.writeObject(stateHandler);
38             s.writeObject(iconHelper);
39         }
40         finally {
41             lock.release();
42         }
43     }
44
45     /**
46      * Custom serialisation.
47      */

48     private void readObject(ObjectInputStream JavaDoc s)
49     throws IOException JavaDoc, ClassNotFoundException JavaDoc {
50         s.defaultReadObject();
51         setName((String JavaDoc) s.readObject());
52         setLogger((String JavaDoc) s.readObject());
53         stateHandler = (JobStateHandler) s.readObject();
54         stateHandler.setSource(this);
55         iconHelper = (IconHelper) s.readObject();
56         iconHelper.setSource(this);
57     }
58
59 }
60
Popular Tags