KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > framework > engine > pipeline > MessageProcessingContext


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

18
19 package sync4j.framework.engine.pipeline;
20
21 import java.io.Serializable JavaDoc;
22 import java.util.Map JavaDoc;
23 import java.util.HashMap JavaDoc;
24
25 /**
26  * This class allows the pipeline components to share session-scoped and
27  * request-scoped properties.
28  * <p>
29  * Standard session properties are:
30  * <ul>
31  * sync4j.session.id - the server session id
32  * </ul>
33  * Standard request properties are:
34  * <ul>
35  * sync4j.request.parameters - parameters specified on the query string of
36  * the current request
37  * sync4j.request.headers - headers given with the current message
38  * </ul>
39  * <p>
40  * <b>NOTE:</b> the prefix <i>sync4j.</i> for property keys is reserved for
41  * Sync4j internal use.
42  *
43  * @version $Id: MessageProcessingContext.java,v 1.7 2005/03/02 20:57:37 harrie Exp $
44  */

45 public class MessageProcessingContext implements Serializable JavaDoc {
46
47     // --------------------------------------------------------------- Constants
48
public static final String JavaDoc PROPERTY_SESSION_ID = "sync4j.session.id";
49     
50     public static final String JavaDoc PROPERTY_REQUEST_HEADERS
51         = "sync4j.request.headers";
52     
53     public static final String JavaDoc PROPERTY_REQUEST_PARAMETERS
54         = "sync4j.request.parameters";
55     
56     // ------------------------------------------------------------ Private data
57

58     /**
59      * Session scoped properties
60      */

61     private HashMap JavaDoc sessionProperties;
62     
63     /**
64      * Request scoped properties
65      */

66      private HashMap JavaDoc requestProperties;
67     
68     // ------------------------------------------------------------ Constructors
69

70     /**
71      * Creates a new MessageProcessingContext object
72      *
73      */

74     public MessageProcessingContext() {
75         sessionProperties = new HashMap JavaDoc();
76         requestProperties = new HashMap JavaDoc();
77     }
78
79     // ---------------------------------------------------------- Public methods
80

81     /**
82      * Getter for sessionProperties
83      * @return Value of properties
84      */

85     public Map JavaDoc getSessionProperties() {
86         return this.sessionProperties;
87     }
88
89     /**
90      * Setter for sessionProperties.
91      *
92      * @param properties New value of properties.
93      */

94     public void setSessionProperties(Map JavaDoc properties) {
95         this.sessionProperties.clear();
96         this.sessionProperties.putAll(properties);
97     }
98     
99     /**
100      * Getter for requestProperties
101      * @return Value of properties
102      */

103     public Map JavaDoc getRequestProperties() {
104         return this.requestProperties;
105     }
106
107     /**
108      * Setter for sessionProperties.
109      *
110      * @param properties New value of properties.
111      */

112     public void setRequestProperties(Map JavaDoc properties) {
113         this.requestProperties.clear();
114         this.requestProperties.putAll(properties);
115     }
116     
117     /**
118      * Returns the value of the session property associated to the given key
119      *
120      * @param key the context property key
121      *
122      * @return the property value or null if key was not found
123      */

124     public Object JavaDoc getSessionProperty(String JavaDoc key) {
125         return sessionProperties.get(key);
126     }
127
128     /**
129      * Sets a given session property
130      *
131      * @param key the context property key
132      * @param value the context property value
133      *
134      */

135     public void setSessionProperty(String JavaDoc key, Object JavaDoc value) {
136         sessionProperties.put(key, value);
137     }
138
139     
140     /**
141      * Returns the value of the request property associated to the given key
142      *
143      * @param key the context property key
144      *
145      * @return the property value or null if key was not found
146      */

147     public Object JavaDoc getRequestProperty(String JavaDoc key) {
148         return sessionProperties.get(key);
149     }
150
151     /**
152      * Sets a given request property
153      *
154      * @param key the context property key
155      * @param value the context property value
156      *
157      */

158     public void setRequestProperty(String JavaDoc key, Object JavaDoc value) {
159         sessionProperties.put(key, value);
160     }
161     
162     /**
163      * Returns a String representation of request and session properties
164      * (for debug purposes).
165      *
166      * @return a String representation of request and session properties
167      * (for debug purposes).
168      */

169     public String JavaDoc toString() {
170         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
171         
172         sb.append(super.toString()).append(" {")
173           .append("\n\tSession properties: ").append(sessionProperties)
174           .append("\n\tRequest properties: ").append(requestProperties)
175           .append("\n}");
176         
177         return sb.toString();
178           
179     }
180
181 }
Popular Tags