1 4 package org.oddjob.quartz; 5 6 import java.io.IOException ; 7 import java.io.NotSerializableException ; 8 import java.io.ObjectInputStream ; 9 import java.io.ObjectOutputStream ; 10 import java.io.Serializable ; 11 12 import org.oddjob.arooa.registry.ComponentRegistry; 13 import org.oddjob.arooa.registry.Path; 14 15 public class JobToken implements Serializable { 16 private static final long serialVersionUID = 20060112; 17 18 private transient Object job; 19 private Path path; 20 21 private JobToken() {} 22 23 private JobToken(Path path, Object job) { 24 this.path = path; 25 this.job = job; 26 } 27 28 static JobToken create(ComponentRegistry registry, Object job) { 29 if (job == null) { 30 throw new NullPointerException ("No Job!"); 31 } 32 if (registry == null) { 33 return new JobToken(null, job); 34 } 35 Path path = registry.pathForObject(job); 36 return new JobToken(path, job); 37 } 38 39 static Object retrieve(ComponentRegistry registry, JobToken token) { 40 if (token.path != null) { 41 return registry.objectForPath(token.path); 42 } 43 return token.job; 44 } 45 46 private void writeObject(ObjectOutputStream s) 47 throws IOException { 48 if (path == null) { 49 throw new NotSerializableException ("Can't serialize - has the job got an id?"); 50 } 51 s.defaultWriteObject(); 52 } 53 54 private void readObject(ObjectInputStream s) 55 throws IOException , ClassNotFoundException { 56 s.defaultReadObject(); 57 } 58 59 public String toString() { 60 if (path != null) { 61 return "Path: " + path; 62 } 63 else { 64 return job.toString(); 65 } 66 } 67 } 68 | Popular Tags |