001    // $HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/ogcwebservices/getcapabilities/OperationsMetadata.java $
002    /*----------------------------------------------------------------------------
003     This file is part of deegree, http://deegree.org/
004     Copyright (C) 2001-2009 by:
005       Department of Geography, University of Bonn
006     and
007       lat/lon GmbH
008    
009     This library is free software; you can redistribute it and/or modify it under
010     the terms of the GNU Lesser General Public License as published by the Free
011     Software Foundation; either version 2.1 of the License, or (at your option)
012     any later version.
013     This library is distributed in the hope that it will be useful, but WITHOUT
014     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
015     FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
016     details.
017     You should have received a copy of the GNU Lesser General Public License
018     along with this library; if not, write to the Free Software Foundation, Inc.,
019     59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020    
021     Contact information:
022    
023     lat/lon GmbH
024     Aennchenstr. 19, 53177 Bonn
025     Germany
026     http://lat-lon.de/
027    
028     Department of Geography, University of Bonn
029     Prof. Dr. Klaus Greve
030     Postfach 1147, 53001 Bonn
031     Germany
032     http://www.geographie.uni-bonn.de/deegree/
033    
034     e-mail: info@deegree.org
035    ----------------------------------------------------------------------------*/
036    package org.deegree.ogcwebservices.getcapabilities;
037    
038    import java.io.Serializable;
039    import java.util.HashMap;
040    import java.util.Map;
041    
042    import org.deegree.owscommon.OWSDomainType;
043    
044    /**
045     * Represents the <code>OperationMetadata</code> part in the capabilities document of an OGC-web
046     * service according to the <code>OWS Common Implementation
047     * Specification 0.3</code> (and
048     * especially <code>owsOperationsMetadata.xsd</code>). As this class is abstract, it only defines
049     * the <code>GetCapabilities</code> operation, which all types of <code>OWS Common</code>
050     * -compliant web services must implement.
051     * <p>
052     * It consists of the following elements: <table border="1">
053     * <tr>
054     * <th>Name</th>
055     * <th>Occurences</th>
056     * <th>Function</th>
057     * </tr>
058     * <tr>
059     * <td>ows:Operation</td>
060     * <td align="center">2-*</td>
061     * <td>Metadata for unordered list of all the (requests for) operations that this server interface
062     * implements. The list of required and optional operations implemented shall be specified in the
063     * Implementation Specification for this service.</td>
064     * </tr>
065     * <tr>
066     * <td>ows:Parameter</td>
067     * <td align="center">0-*</td>
068     * <td>Optional unordered list of parameter valid domains that each apply to one or more operations
069     * which this server interface implements. The list of required and optional parameter domain
070     * limitations shall be specified in the Implementation Specification for this service.</td>
071     * </tr>
072     * <tr>
073     * <td>ows:Constraint</td>
074     * <td align="center">0-*</td>
075     * <td>Optional unordered list of valid domain constraints on non-parameter quantities that each
076     * apply to this server. The list of required and optional constraints shall be specified in the
077     * Implementation Specification for this service.</td>
078     * </tr>
079     * <tr>
080     * <td>ows:ExtendedCapabilities</td>
081     * <td align="center">0 or 1</td>
082     * <td>Individual software vendors and servers can use this element to provide metadata about any
083     * additional server abilities.</td>
084     * </tr>
085     * </table>
086     *
087     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a>
088     * @author <a href="mailto:mschneider@lat-lon.de">Markus Schneider </a>
089     * @author last edited by: $Author: mschneider $
090     *
091     * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18 Jun 2009) $
092     */
093    public abstract class OperationsMetadata implements Serializable {
094    
095        /**
096         *
097         */
098        public static final String GET_CAPABILITIES_NAME = "GetCapabilities";
099    
100        protected Operation getCapabilitiesOperation = null;
101    
102        // keys are Strings (the names of the parameters), values are
103        // OWSDomainType-instances
104        protected Map<String, OWSDomainType> parameters;
105    
106        // keys are Strings (the names of constrained domains), values are
107        // OWSDomainType-instances
108        protected Map<String, OWSDomainType> constraints;
109    
110        /**
111         * Creates a new <code>OperationsMetadata</code> instance with the given configuration for the
112         * getCapabilitiesOperation.
113         *
114         * @param getCapabilitiesOperation
115         * @param parameters
116         * @param constraints
117         */
118        public OperationsMetadata( Operation getCapabilitiesOperation, OWSDomainType[] parameters,
119                                   OWSDomainType[] constraints ) {
120            this.getCapabilitiesOperation = getCapabilitiesOperation;
121            setOperationParameter( parameters );
122            setConstraints( constraints );
123        }
124    
125        /**
126         * @return The configuration for the <code>GetCapabilities</code> -operation.
127         */
128        public Operation getGetCapabilitiesOperation() {
129            return getCapabilitiesOperation;
130        }
131    
132        /**
133         * Sets the configuration for the <code>GetCapabilities</code> -operation.
134         *
135         * @param getCapabilitiesOperation
136         *            configuration for the <code>GetCapabilities</code> -operation to be set
137         */
138        public void setGetCapabilitiesOperation( Operation getCapabilitiesOperation ) {
139            this.getCapabilitiesOperation = getCapabilitiesOperation;
140        }
141    
142        /**
143         * @return all <code>Operation</code> configurations.
144         */
145        public Operation[] getOperations() {
146            return new Operation[] { getCapabilitiesOperation };
147        }
148    
149        /**
150         *
151         * @return a list of parameters assigned directly to the OperationsMetadata.
152         */
153        public OWSDomainType[] getParameter() {
154            return parameters.values().toArray( new OWSDomainType[parameters.size()] );
155        }
156    
157        /**
158         * adds a parameter to the OperationsMetadata
159         *
160         * @param parameter
161         */
162        public void addParameter( OWSDomainType parameter ) {
163            parameters.put( parameter.getName(), parameter );
164        }
165    
166        /**
167         *
168         *
169         * @param name
170         *            removes a parameter from the OperationsMetadata
171         * @return the removed parameter
172         */
173        public OWSDomainType removeParameter( String name ) {
174            return parameters.remove( name );
175        }
176    
177        /**
178         * sets a complete list of parameters to the OperationMetadata
179         *
180         * @param parameters
181         */
182        public void setOperationParameter( OWSDomainType[] parameters ) {
183            if ( this.parameters == null ) {
184                this.parameters = new HashMap<String, OWSDomainType>();
185            } else {
186                this.parameters.clear();
187            }
188            if ( parameters != null ) {
189                for ( int i = 0; i < parameters.length; i++ ) {
190                    addParameter( parameters[i] );
191                }
192            }
193        }
194    
195        /**
196         * @return Returns the constraints.
197         */
198        public OWSDomainType[] getConstraints() {
199            return constraints.values().toArray( new OWSDomainType[constraints.values().size()] );
200        }
201    
202        /**
203         * Sets the constraints of the <code>OperationMetadata</code>.
204         *
205         * @param constraints
206         *            may be null
207         */
208        public void setConstraints( OWSDomainType[] constraints ) {
209            if ( this.constraints == null ) {
210                this.constraints = new HashMap<String, OWSDomainType>();
211            } else {
212                this.constraints.clear();
213            }
214            if ( constraints != null ) {
215                for ( int i = 0; i < constraints.length; i++ ) {
216                    addConstraint( constraints[i] );
217                }
218            }
219        }
220    
221        /**
222         * Adds a constraint.
223         *
224         * @param constraint
225         */
226        public void addConstraint( OWSDomainType constraint ) {
227            constraints.put( constraint.getName(), constraint );
228        }
229    }