001    // $HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/ogcwebservices/getcapabilities/OperationsMetadata.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.ogcwebservices.getcapabilities;
045    
046    import java.io.Serializable;
047    import java.util.HashMap;
048    import java.util.Map;
049    
050    import org.deegree.owscommon.OWSDomainType;
051    
052    /**
053     * Represents the <code>OperationMetadata</code> part in the capabilities document of an OGC-web
054     * service according to the <code>OWS Common Implementation
055     * Specification 0.3</code> (and
056     * especially <code>owsOperationsMetadata.xsd</code>). As this class is abstract, it only defines
057     * the <code>GetCapabilities</code> operation, which all types of <code>OWS Common</code>
058     * -compliant web services must implement.
059     * <p>
060     * It consists of the following elements: <table border="1">
061     * <tr>
062     * <th>Name</th>
063     * <th>Occurences</th>
064     * <th>Function</th>
065     * </tr>
066     * <tr>
067     * <td>ows:Operation</td>
068     * <td align="center">2-*</td>
069     * <td>Metadata for unordered list of all the (requests for) operations that this server interface
070     * implements. The list of required and optional operations implemented shall be specified in the
071     * Implementation Specification for this service.</td>
072     * </tr>
073     * <tr>
074     * <td>ows:Parameter</td>
075     * <td align="center">0-*</td>
076     * <td>Optional unordered list of parameter valid domains that each apply to one or more operations
077     * which this server interface implements. The list of required and optional parameter domain
078     * limitations shall be specified in the Implementation Specification for this service.</td>
079     * </tr>
080     * <tr>
081     * <td>ows:Constraint</td>
082     * <td align="center">0-*</td>
083     * <td>Optional unordered list of valid domain constraints on non-parameter quantities that each
084     * apply to this server. The list of required and optional constraints shall be specified in the
085     * Implementation Specification for this service.</td>
086     * </tr>
087     * <tr>
088     * <td>ows:ExtendedCapabilities</td>
089     * <td align="center">0 or 1</td>
090     * <td>Individual software vendors and servers can use this element to provide metadata about any
091     * additional server abilities.</td>
092     * </tr>
093     * </table>
094     * 
095     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a>
096     * @author <a href="mailto:mschneider@lat-lon.de">Markus Schneider </a>
097     * @author last edited by: $Author: apoth $
098     * 
099     * @version $Revision: 9345 $, $Date: 2007-12-27 17:22:25 +0100 (Do, 27 Dez 2007) $
100     */
101    public abstract class OperationsMetadata implements Serializable {
102    
103        /**
104         * 
105         */
106        public static final String GET_CAPABILITIES_NAME = "GetCapabilities";
107    
108        protected Operation getCapabilitiesOperation = null;
109    
110        // keys are Strings (the names of the parameters), values are
111        // OWSDomainType-instances
112        protected Map<String, OWSDomainType> parameters;
113    
114        // keys are Strings (the names of constrained domains), values are
115        // OWSDomainType-instances
116        protected Map<String, OWSDomainType> constraints;
117    
118        /**
119         * Creates a new <code>OperationsMetadata</code> instance with the given configuration for the
120         * getCapabilitiesOperation.
121         * 
122         * @param getCapabilitiesOperation
123         * @param parameters
124         * @param constraints
125         */
126        public OperationsMetadata( Operation getCapabilitiesOperation, OWSDomainType[] parameters,
127                                   OWSDomainType[] constraints ) {
128            this.getCapabilitiesOperation = getCapabilitiesOperation;
129            setOperationParameter( parameters );
130            setConstraints( constraints );
131        }
132    
133        /**
134         * @return The configuration for the <code>GetCapabilities</code> -operation.
135         */
136        public Operation getGetCapabilitiesOperation() {
137            return getCapabilitiesOperation;
138        }
139    
140        /**
141         * Sets the configuration for the <code>GetCapabilities</code> -operation.
142         * 
143         * @param getCapabilitiesOperation
144         *            configuration for the <code>GetCapabilities</code> -operation to be set
145         */
146        public void setGetCapabilitiesOperation( Operation getCapabilitiesOperation ) {
147            this.getCapabilitiesOperation = getCapabilitiesOperation;
148        }
149    
150        /**
151         * @return all <code>Operation</code> configurations.
152         */
153        public Operation[] getOperations() {
154            return new Operation[] { getCapabilitiesOperation };
155        }
156    
157        /**
158         * 
159         * @return a list of parameters assigned directly to the OperationsMetadata.
160         */
161        public OWSDomainType[] getParameter() {
162            return parameters.values().toArray( new OWSDomainType[parameters.size()] );
163        }
164    
165        /**
166         * adds a parameter to the OperationsMetadata
167         * 
168         * @param parameter
169         */
170        public void addParameter( OWSDomainType parameter ) {
171            parameters.put( parameter.getName(), parameter );
172        }
173    
174        /**
175         * 
176         * 
177         * @param name
178         *            removes a parameter from the OperationsMetadata
179         * @return the removed parameter
180         */
181        public OWSDomainType removeParameter( String name ) {
182            return parameters.remove( name );
183        }
184    
185        /**
186         * sets a complete list of parameters to the OperationMetadata
187         * 
188         * @param parameters
189         */
190        public void setOperationParameter( OWSDomainType[] parameters ) {
191            if ( this.parameters == null ) {
192                this.parameters = new HashMap<String, OWSDomainType>();
193            } else {
194                this.parameters.clear();
195            }
196            if ( parameters != null ) {
197                for ( int i = 0; i < parameters.length; i++ ) {
198                    addParameter( parameters[i] );
199                }
200            }
201        }
202    
203        /**
204         * @return Returns the constraints.
205         */
206        public OWSDomainType[] getConstraints() {
207            return constraints.values().toArray( new OWSDomainType[constraints.values().size()] );
208        }
209    
210        /**
211         * Sets the constraints of the <code>OperationMetadata</code>.
212         * 
213         * @param constraints
214         *            may be null
215         */
216        public void setConstraints( OWSDomainType[] constraints ) {
217            if ( this.constraints == null ) {
218                this.constraints = new HashMap<String, OWSDomainType>();
219            } else {
220                this.constraints.clear();
221            }
222            if ( constraints != null ) {
223                for ( int i = 0; i < constraints.length; i++ ) {
224                    addConstraint( constraints[i] );
225                }
226            }
227        }
228    
229        /**
230         * Adds a constraint.
231         * 
232         * @param constraint
233         */
234        public void addConstraint( OWSDomainType constraint ) {
235            constraints.put( constraint.getName(), constraint );
236        }
237    }