1 |
< |
import java.util.HashMap; |
1 |
> |
/* |
2 |
> |
* i-scream central monitoring system |
3 |
> |
* http://www.i-scream.org.uk |
4 |
> |
* Copyright (C) 2000-2002 i-scream |
5 |
> |
* |
6 |
> |
* This program is free software; you can redistribute it and/or |
7 |
> |
* modify it under the terms of the GNU General Public License |
8 |
> |
* as published by the Free Software Foundation; either version 2 |
9 |
> |
* of the License, or (at your option) any later version. |
10 |
> |
* |
11 |
> |
* This program is distributed in the hope that it will be useful, |
12 |
> |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
> |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
> |
* GNU General Public License for more details. |
15 |
> |
* |
16 |
> |
* You should have received a copy of the GNU General Public License |
17 |
> |
* along with this program; if not, write to the Free Software |
18 |
> |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 |
> |
*/ |
20 |
|
|
21 |
< |
// Paul Mutton, pjm2@ukc.ac.uk |
21 |
> |
//---PACKAGE DECLARATION--- |
22 |
> |
package uk.org.iscream.cms.server.util; |
23 |
|
|
24 |
< |
// Object in which to store incoming XML data |
25 |
< |
// to be passed around the CORBA system. |
24 |
> |
//---IMPORTS--- |
25 |
> |
import java.util.*; |
26 |
> |
|
27 |
> |
/** |
28 |
> |
* Object in which to store incoming XML data for processing |
29 |
> |
* by a component of the system. |
30 |
> |
* |
31 |
> |
* @author $Author$ |
32 |
> |
* @version $Id$ |
33 |
> |
*/ |
34 |
|
public class XMLPacket { |
35 |
|
|
36 |
< |
// Add a key and value pair to the HashMap. |
36 |
> |
//---FINAL ATTRIBUTES--- |
37 |
> |
|
38 |
> |
/** |
39 |
> |
* The current CVS revision of this class |
40 |
> |
*/ |
41 |
> |
public final String REVISION = "$Revision$"; |
42 |
> |
|
43 |
> |
//---STATIC METHODS--- |
44 |
> |
|
45 |
> |
//---CONSTRUCTORS--- |
46 |
> |
|
47 |
> |
//---PUBLIC METHODS--- |
48 |
> |
|
49 |
> |
/** |
50 |
> |
* Add a key and value pair to the HashMap. |
51 |
> |
* |
52 |
> |
* @param key The key value |
53 |
> |
* @param value The value associated with the key |
54 |
> |
*/ |
55 |
|
public synchronized void addParam (String key, String value) { |
56 |
< |
params.put(key, value); |
12 |
< |
// debug by println ;-) |
13 |
< |
// System.out.println("Adding to hash: " + key + " = " + value); |
14 |
< |
// end debug code |
56 |
> |
_params.put(key, value); |
57 |
|
} |
58 |
|
|
59 |
< |
// Return the value associated with a particular key. |
60 |
< |
// Returns null if the key does not exist, although |
61 |
< |
// this should not necessarily indicate that the key |
62 |
< |
// does not exist. |
59 |
> |
/** |
60 |
> |
* Return the value associated with a particular key. |
61 |
> |
* Returns null if the key does not exist, although |
62 |
> |
* this should not necessarily indicate that the key |
63 |
> |
* does not exist. |
64 |
> |
* |
65 |
> |
* @param key The key to retrieve |
66 |
> |
* @return The value associated with the key, if one exists, otherwise null. |
67 |
> |
*/ |
68 |
|
public synchronized String getParam (String key) { |
69 |
< |
return (String)params.get(key); |
69 |
> |
return (String) _params.get(key); |
70 |
|
} |
71 |
|
|
72 |
< |
// Print out the entire HashMap. |
73 |
< |
// (Mainly for assisting debugging.) |
74 |
< |
public synchronized void printAll () { |
75 |
< |
System.out.println(params); |
72 |
> |
/** |
73 |
> |
* Return a Set of the keys in the HashMap. |
74 |
> |
* |
75 |
> |
* @return a Set of the values in this Packet. |
76 |
> |
*/ |
77 |
> |
public synchronized Set getSet () { |
78 |
> |
return _params.keySet(); |
79 |
|
} |
30 |
– |
|
31 |
– |
private HashMap params = new HashMap(); |
80 |
|
|
81 |
+ |
/** |
82 |
+ |
* Find if a particular key exists in the HashMap. |
83 |
+ |
* |
84 |
+ |
* @param key The key to check for |
85 |
+ |
* @return whether the key exists |
86 |
+ |
*/ |
87 |
+ |
public synchronized boolean containsKey(String key){ |
88 |
+ |
return _params.containsKey(key); |
89 |
+ |
} |
90 |
+ |
|
91 |
+ |
/** |
92 |
+ |
* Print out the entire HashMap. |
93 |
+ |
* (Mainly for assisting debugging.) |
94 |
+ |
* |
95 |
+ |
* @return A String representation of the data in this Packet |
96 |
+ |
*/ |
97 |
+ |
public synchronized String printAll () { |
98 |
+ |
return _params.toString(); |
99 |
+ |
} |
100 |
+ |
|
101 |
+ |
/** |
102 |
+ |
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
103 |
+ |
* method to provide clean logging (every class should have this). |
104 |
+ |
* |
105 |
+ |
* This uses the uk.org.iscream.cms.server.util.NameFormat class |
106 |
+ |
* to format the toString() |
107 |
+ |
* |
108 |
+ |
* @return the name of this class and its CVS revision |
109 |
+ |
*/ |
110 |
+ |
public String toString() { |
111 |
+ |
return FormatName.getName( |
112 |
+ |
_name, |
113 |
+ |
getClass().getName(), |
114 |
+ |
REVISION); |
115 |
+ |
} |
116 |
+ |
|
117 |
+ |
//---PRIVATE METHODS--- |
118 |
+ |
|
119 |
+ |
//---ACCESSOR/MUTATOR METHODS--- |
120 |
+ |
|
121 |
+ |
//---ATTRIBUTES--- |
122 |
+ |
|
123 |
+ |
/** |
124 |
+ |
* A HashMap of parameters |
125 |
+ |
*/ |
126 |
+ |
private HashMap _params = new HashMap(); |
127 |
+ |
|
128 |
+ |
/** |
129 |
+ |
* This is the friendly identifier of the |
130 |
+ |
* component this class is running in. |
131 |
+ |
* eg, a Filter may be called "filter1", |
132 |
+ |
* If this class does not have an owning |
133 |
+ |
* component, a name from the configuration |
134 |
+ |
* can be placed here. This name could also |
135 |
+ |
* be changed to null for utility classes. |
136 |
+ |
*/ |
137 |
+ |
private String _name = null; |
138 |
+ |
|
139 |
+ |
//---STATIC ATTRIBUTES--- |
140 |
+ |
|
141 |
|
} |