001    //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/framework/util/ParameterList.java $
002    /*----------------    FILE HEADER  ------------------------------------------
003    
004     This file is part of deegree.
005     Copyright (C) 2001-2008 by:
006     EXSE, Department of Geography, University of Bonn
007     http://www.giub.uni-bonn.de/deegree/
008     lat/lon GmbH
009     http://www.lat-lon.de
010    
011     This library is free software; you can redistribute it and/or
012     modify it under the terms of the GNU Lesser General Public
013     License as published by the Free Software Foundation; either
014     version 2.1 of the License, or (at your option) any later version.
015    
016     This library is distributed in the hope that it will be useful,
017     but WITHOUT ANY WARRANTY; without even the implied warranty of
018     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
019     Lesser General Public License for more details.
020    
021     You should have received a copy of the GNU Lesser General Public
022     License along with this library; if not, write to the Free Software
023     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
024    
025     Contact:
026    
027     Andreas Poth
028     lat/lon GmbH
029     Aennchenstr. 19
030     53115 Bonn
031     Germany
032     E-Mail: poth@lat-lon.de
033    
034     Prof. Dr. Klaus Greve
035     Department of Geography
036     University of Bonn
037     Meckenheimer Allee 166
038     53115 Bonn
039     Germany
040     E-Mail: greve@giub.uni-bonn.de
041     
042     ---------------------------------------------------------------------------*/
043    
044    package org.deegree.framework.util;
045    
046    import java.util.ArrayList;
047    import java.util.HashMap;
048    import java.util.Iterator;
049    
050    /**
051     * The interface defines the access to a list of paramters that can be used as submitted parameters
052     * to methods that may receive an variable list of parameters.
053     * 
054     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
055     * @author last edited by: $Author: apoth $
056     * 
057     * @version $Revision: 9339 $ $Date: 2007-12-27 13:31:52 +0100 (Do, 27 Dez 2007) $
058     */
059    final public class ParameterList {
060    
061        private HashMap<String, Parameter> params = new HashMap<String, Parameter>();
062    
063        private ArrayList<String> keys = new ArrayList<String>( 100 );
064    
065        /**
066         * returns the parameter that matches the submitted name. if no parameter can be found
067         * <tt>null</tt> will be returned.
068         * 
069         * @param name
070         * @return name parameter
071         */
072        public Parameter getParameter( String name ) {
073            return params.get( name );
074        }
075    
076        /**
077         * adds a new <tt>Parameter</tt> to the list
078         * 
079         * @param name
080         * @param value
081         * 
082         */
083        public void addParameter( String name, Object value ) {
084            Parameter p = new Parameter( name, value );
085            addParameter( p );
086        }
087    
088        /**
089         * adds a new <tt>Parameter</tt> to the list
090         * 
091         * @param param
092         */
093        public void addParameter( Parameter param ) {
094            params.put( param.getName(), param );
095            keys.add( param.getName() );
096        }
097    
098        /**
099         * returns all <tt>Parameter</tt>s contained within the list as array. it is guarenteered
100         * that the arrays isn't <tt>null</tt>
101         * 
102         * @return returns an array with all Parameters from the list.
103         */
104        public Parameter[] getParameters() {
105            Parameter[] p = new Parameter[keys.size()];
106            Iterator iter = keys.iterator();
107            int i = 0;
108            while ( iter.hasNext() ) {
109                p[i++] = params.get( iter.next() );
110            }
111            return p;
112        }
113    
114        /**
115         * returns an array of all <tt>Parameter</tt>s names. it is guarenteered that the arrays
116         * isn't <tt>null</tt>
117         * 
118         * @return parameter names
119         */
120        public String[] getParameterNames() {
121            String[] s = new String[keys.size()];
122            return keys.toArray( s );
123        }
124    
125        /**
126         * returns an array of all <tt>Parameter</tt>s values. it is guarenteered that the arrays
127         * isn't <tt>null</tt>
128         * 
129         * @return parameter values
130         */
131        public Object[] getParameterValues() {
132            Object[] o = new Object[keys.size()];
133            for ( int i = 0; i < o.length; i++ ) {
134                Parameter p = params.get( keys.get( i ) );
135                o[i] = p.getValue();
136            }
137            return o;
138        }
139    
140        /**
141         * removes a parameter from the list
142         * 
143         * @param name
144         *            name of the parameter
145         * @return nemd parameter
146         */
147        public Parameter removeParameter( String name ) {
148            keys.remove( name );
149            return params.remove( name );
150        }
151    
152        /**
153         * @return string representation
154         */
155        public String toString() {
156            String ret = null;
157            ret = "params = " + params + "\n";
158            return ret;
159        }
160    
161    }