KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > webservice > handler > MessageContextImpl


1 /**
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.webservice.handler;
8
9 // $Id: MessageContextImpl.java,v 1.2 2004/07/20 13:48:55 tdiesler Exp $
10

11 import javax.xml.rpc.handler.MessageContext JavaDoc;
12 import java.util.HashMap JavaDoc;
13 import java.util.Iterator JavaDoc;
14
15 /**
16  * The message context that is processed by a handler
17  * in the handle method.
18  * <p/>
19  * Provides methods to manage a property set.
20  * MessageContext properties enable handlers in a handler chain to share
21  * processing related state.
22  *
23  * @author Thomas.Diesler@jboss.org
24  * @since 06-May-2004
25  */

26 public class MessageContextImpl implements MessageContext JavaDoc
27 {
28    // The map of the properties
29
private HashMap JavaDoc props = new HashMap JavaDoc();
30
31    /**
32     * Returns true if the MessageContext contains a property with the specified name.
33     *
34     * @param name Name of the property whose presense is to be tested
35     * @return Returns true if the MessageContext contains the property; otherwise false
36     */

37    public boolean containsProperty(String JavaDoc name)
38    {
39       return props.containsKey(name);
40    }
41
42    /**
43     * Gets the value of a specific property from the MessageContext
44     *
45     * @param name Name of the property whose value is to be retrieved
46     * @return Value of the property
47     * @throws IllegalArgumentException if an illegal property name is specified
48     */

49    public Object JavaDoc getProperty(String JavaDoc name)
50    {
51       assertPropertyKey(name);
52       return props.get(name);
53    }
54
55    /**
56     * Returns an Iterator view of the names of the properties in this MessageContext
57     *
58     * @return Iterator for the property names
59     */

60    public Iterator JavaDoc getPropertyNames()
61    {
62       return props.keySet().iterator();
63    }
64
65    /**
66     * Removes a property (name-value pair) from the MessageContext
67     *
68     * @param name Name of the property to be removed
69     * @throws IllegalArgumentException if an illegal property name is specified
70     */

71    public void removeProperty(String JavaDoc name)
72    {
73       assertPropertyKey(name);
74       props.remove(name);
75    }
76
77    /**
78     * Sets the name and value of a property associated with the MessageContext.
79     * If the MessageContext contains a value of the same property, the old value is replaced.
80     *
81     * @param name Name of the property associated with the MessageContext
82     * @param value Value of the property
83     * @throws IllegalArgumentException If some aspect of the property is prevents it from being stored in the context
84     * @throws UnsupportedOperationException If this method is not supported.
85     */

86    public void setProperty(String JavaDoc name, Object JavaDoc value)
87    {
88       props.put(name, value);
89    }
90
91    /**
92     * Throws an IllegalArgumentException if the key is not present
93     */

94    private void assertPropertyKey(String JavaDoc name)
95    {
96       if (containsProperty(name) == false)
97          throw new IllegalArgumentException JavaDoc("Property key not present: " + name);
98    }
99
100 }
101
Popular Tags