1 16 package org.springframework.webflow.conversation.impl; 17 18 import java.io.IOException ; 19 import java.io.ObjectInputStream ; 20 import java.io.ObjectOutputStream ; 21 import java.io.Serializable ; 22 import java.util.HashMap ; 23 import java.util.Map ; 24 25 import org.springframework.webflow.conversation.Conversation; 26 import org.springframework.webflow.conversation.ConversationId; 27 28 36 class ContainedConversation implements Conversation, Serializable { 37 38 private ConversationContainer container; 39 40 private ConversationId id; 41 42 private transient ConversationLock lock; 43 44 private Map attributes; 45 46 51 public ContainedConversation(ConversationContainer container, ConversationId id) { 52 this.container = container; 53 this.id = id; 54 this.lock = ConversationLockFactory.createLock(); 55 this.attributes = new HashMap (); 56 } 57 58 public ConversationId getId() { 59 return id; 60 } 61 62 public void lock() { 63 lock.lock(); 64 } 65 66 public Object getAttribute(Object name) { 67 return attributes.get(name); 68 } 69 70 public void putAttribute(Object name, Object value) { 71 attributes.put(name, value); 72 } 73 74 public void removeAttribute(Object name) { 75 attributes.remove(name); 76 } 77 78 public void end() { 79 container.removeConversation(getId()); 80 } 81 82 public void unlock() { 83 lock.unlock(); 84 } 85 86 public String toString() { 87 return getId().toString(); 88 } 89 90 92 public boolean equals(Object obj) { 93 if (!(obj instanceof ContainedConversation)) { 94 return false; 95 } 96 return id.equals(((ContainedConversation)obj).id); 97 } 98 99 public int hashCode() { 100 return id.hashCode(); 101 } 102 103 105 private void writeObject(ObjectOutputStream out) throws IOException { 106 out.defaultWriteObject(); 107 } 108 109 private void readObject(ObjectInputStream in) throws IOException , ClassNotFoundException { 110 in.defaultReadObject(); 111 lock = ConversationLockFactory.createLock(); 112 } 113 } | Popular Tags |