--- projects/cms/source/util/uk/org/iscream/cms/util/XMLPacket.java 2000/11/22 08:40:53 1.1 +++ projects/cms/source/util/uk/org/iscream/cms/util/XMLPacket.java 2003/02/05 14:27:59 1.15 @@ -1,33 +1,141 @@ -import java.util.HashMap; +/* + * i-scream central monitoring system + * http://www.i-scream.org.uk + * 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. + */ -// Paul Mutton, pjm2@ukc.ac.uk +//---PACKAGE DECLARATION--- +package uk.org.iscream.cms.util; -// Object in which to store incoming XML data -// to be passed around the CORBA system. +//---IMPORTS--- +import java.util.*; + +/** + * 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.15 2003/02/05 14:27:59 tdb Exp $ + */ public class XMLPacket { - // Add a key and value pair to the HashMap. +//---FINAL ATTRIBUTES--- + + /** + * The current CVS revision of this class + */ + public final String REVISION = "$Revision: 1.15 $"; + +//---STATIC METHODS--- + +//---CONSTRUCTORS--- + +//---PUBLIC METHODS--- + + /** + * 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); + return (String) _params.get(key); } - // Print out the entire HashMap. - // (Mainly for assisting debugging.) - public synchronized void printAll () { - System.out.println(params); + /** + * 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(); } - - private HashMap params = new HashMap(); + /** + * 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(); + } + + /** + * 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 FormatName.getName( + _name, + getClass().getName(), + REVISION); + } + +//---PRIVATE METHODS--- + +//---ACCESSOR/MUTATOR METHODS--- + +//---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--- + }