--- projects/cms/source/util/uk/org/iscream/cms/util/XMLPacket.java 2000/11/30 02:04:18 1.4 +++ projects/cms/source/util/uk/org/iscream/cms/util/XMLPacket.java 2002/05/18 18:16:04 1.13 @@ -1,15 +1,34 @@ +/* + * i-scream central monitoring system + * Copyright (C) 2000-2002 i-scream + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + //---PACKAGE DECLARATION--- -package uk.ac.ukc.iscream.xml; +package uk.org.iscream.cms.server.util; //---IMPORTS--- -import java.util.HashMap; +import java.util.*; /** - * Object in which to store incoming XML data - * to be passed around the CORBA system. + * Object in which to store incoming XML data for processing + * by a component of the system. * * @author $Author: tdb $ - * @version $Id: XMLPacket.java,v 1.4 2000/11/30 02:04:18 tdb Exp $ + * @version $Id: XMLPacket.java,v 1.13 2002/05/18 18:16:04 tdb Exp $ */ public class XMLPacket { @@ -18,7 +37,7 @@ public class XMLPacket { /** * The current CVS revision of this class */ - public final String REVISION = "$Revision: 1.4 $"; + public final String REVISION = "$Revision: 1.13 $"; //---STATIC METHODS--- @@ -26,24 +45,54 @@ public class XMLPacket { //---PUBLIC METHODS--- - // Add a key and value pair to the HashMap. + /** + * Add a key and value pair to the HashMap. + * + * @param key The key value + * @param value The value associated with the key + */ public synchronized void addParam (String key, String value) { - _params.put(key, value); - // debug by println ;-) - // System.out.println("Adding to hash: " + key + " = " + value); - // end debug code + _params.put(key, value); } - // Return the value associated with a particular key. - // Returns null if the key does not exist, although - // this should not necessarily indicate that the key - // does not exist. + /** + * Return the value associated with a particular key. + * Returns null if the key does not exist, although + * this should not necessarily indicate that the key + * does not exist. + * + * @param key The key to retrieve + * @return The value associated with the key, if one exists, otherwise null. + */ public synchronized String getParam (String key) { return (String) _params.get(key); } - // Print out the entire HashMap. - // (Mainly for assisting debugging.) + /** + * Return a Set of the keys in the HashMap. + * + * @return a Set of the values in this Packet. + */ + public synchronized Set getSet () { + return _params.keySet(); + } + + /** + * Find if a particular key exists in the HashMap. + * + * @param key The key to check for + * @return whether the key exists + */ + public synchronized boolean containsKey(String key){ + return _params.containsKey(key); + } + + /** + * Print out the entire HashMap. + * (Mainly for assisting debugging.) + * + * @return A String representation of the data in this Packet + */ public synchronized String printAll () { return _params.toString(); } @@ -52,10 +101,16 @@ public class XMLPacket { * Overrides the {@link java.lang.Object#toString() Object.toString()} * method to provide clean logging (every class should have this). * + * This uses the uk.org.iscream.cms.server.util.NameFormat class + * to format the toString() + * * @return the name of this class and its CVS revision */ public String toString() { - return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")"; + return FormatName.getName( + _name, + getClass().getName(), + REVISION); } //---PRIVATE METHODS--- @@ -64,8 +119,22 @@ public class XMLPacket { //---ATTRIBUTES--- + /** + * A HashMap of parameters + */ private HashMap _params = new HashMap(); + + /** + * This is the friendly identifier of the + * component this class is running in. + * eg, a Filter may be called "filter1", + * If this class does not have an owning + * component, a name from the configuration + * can be placed here. This name could also + * be changed to null for utility classes. + */ + private String _name = null; //---STATIC ATTRIBUTES--- -} \ No newline at end of file +}