KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > webflow > conversation > impl > ContainedConversation


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.springframework.webflow.conversation.impl;
17
18 import java.io.IOException JavaDoc;
19 import java.io.ObjectInputStream JavaDoc;
20 import java.io.ObjectOutputStream JavaDoc;
21 import java.io.Serializable JavaDoc;
22 import java.util.HashMap JavaDoc;
23 import java.util.Map JavaDoc;
24
25 import org.springframework.webflow.conversation.Conversation;
26 import org.springframework.webflow.conversation.ConversationId;
27
28 /**
29  * Internal {@link Conversation} implementation used by the conversation
30  * container.
31  * <p>
32  * This is an internal helper class of the {@link SessionBindingConversationManager}.
33  *
34  * @author Erwin Vervaet
35  */

36 class ContainedConversation implements Conversation, Serializable JavaDoc {
37
38     private ConversationContainer container;
39
40     private ConversationId id;
41
42     private transient ConversationLock lock;
43
44     private Map JavaDoc attributes;
45
46     /**
47      * Create a new contained conversation.
48      * @param container the container containing the conversation
49      * @param id the unique id assigned to the conversation
50      */

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 JavaDoc();
56     }
57
58     public ConversationId getId() {
59         return id;
60     }
61
62     public void lock() {
63         lock.lock();
64     }
65
66     public Object JavaDoc getAttribute(Object JavaDoc name) {
67         return attributes.get(name);
68     }
69
70     public void putAttribute(Object JavaDoc name, Object JavaDoc value) {
71         attributes.put(name, value);
72     }
73
74     public void removeAttribute(Object JavaDoc 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 JavaDoc toString() {
87         return getId().toString();
88     }
89
90     // id based equality
91

92     public boolean equals(Object JavaDoc 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     // custom serialisation
104

105     private void writeObject(ObjectOutputStream JavaDoc out) throws IOException JavaDoc {
106         out.defaultWriteObject();
107     }
108
109     private void readObject(ObjectInputStream JavaDoc in) throws IOException JavaDoc, ClassNotFoundException JavaDoc {
110         in.defaultReadObject();
111         lock = ConversationLockFactory.createLock();
112     }
113 }
Popular Tags