001    //$HeadURL: $
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    
037    package org.deegree.ogcwebservices.wcts.operation;
038    
039    import java.util.ArrayList;
040    import java.util.List;
041    import java.util.Map;
042    
043    import org.deegree.i18n.Messages;
044    import org.deegree.ogcbase.ExceptionCode;
045    import org.deegree.ogcwebservices.OGCWebServiceException;
046    import org.deegree.ogcwebservices.wcts.WCTService;
047    
048    /**
049     * <code>GetResourceByID</code> encapsulates the xml-dom representation or kvp request parameters of a GetResourceById
050     * request.
051     *
052     * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a>
053     *
054     * @author last edited by: $Author:$
055     *
056     * @version $Revision:$, $Date:$
057     *
058     */
059    public class GetResourceByID extends WCTSRequestBase {
060    
061        private static final long serialVersionUID = 9201043457053591617L;
062    
063        private final List<String> resourceIDs;
064    
065        private final String outputFormat;
066    
067        /**
068         * *
069         *
070         * @param version
071         *            of the request
072         * @param id
073         *            of the request
074         * @param resourceIDs
075         *            a list of resources a client is interested in.
076         * @param outputFormat
077         *            if <code>null</code> it will be set to 'text/xml'
078         */
079        public GetResourceByID( String version, String id, List<String> resourceIDs, String outputFormat ) {
080            super( version, id, null );
081            if ( resourceIDs == null ) {
082                resourceIDs = new ArrayList<String>();
083            }
084            this.resourceIDs = resourceIDs;
085    
086            if ( outputFormat == null ) {
087                //ows 1.1.0 spec proposal.
088                outputFormat = "text/xml";
089            }
090            this.outputFormat = outputFormat;
091    
092        }
093    
094        /**
095         * @return the resourceIDs, may be empty but never <code>null</code>
096         */
097        public final List<String> getResourceIDs() {
098            return resourceIDs;
099        }
100    
101        /**
102         * @return the outputFormat, may be empty but never <code>null</code>
103         */
104        public final String getOutputFormat() {
105            return outputFormat;
106        }
107    
108        /**
109         * Create a {@link GetResourceByID}-request by extracting the values from the map, and calling the constructor with
110         * these values.
111         *
112         * @param requestID
113         *            service internal id for this request.
114         * @param map
115         *            to extract requested values from.
116         * @return the bean representation
117         * @throws OGCWebServiceException
118         *             if the map is <code>null</code> or has size==0, or the service,request parameters have none
119         *             accepted values.
120         */
121        public static GetResourceByID create( String requestID, Map<String, String> map )
122                                                                                         throws OGCWebServiceException {
123            if ( map == null || map.size() == 0 ) {
124                throw new OGCWebServiceException( Messages.getMessage( "WCTS_REQUESTMAP_NULL" ),
125                                                  ExceptionCode.MISSINGPARAMETERVALUE );
126            }
127            String service = map.get( "SERVICE" );
128            if ( service == null || !"WCTS".equals( service ) ) {
129                throw new OGCWebServiceException( Messages.getMessage( "WCTS_NO_VERSION_KVP", service ),
130                                                  ExceptionCode.MISSINGPARAMETERVALUE );
131            }
132            String request = map.get( "REQUEST" );
133            if ( request == null || !"GetResourceByID".equalsIgnoreCase( request ) ) {
134                throw new OGCWebServiceException( Messages.getMessage( "WCTS_NO_REQUEST_KVP", "GetResourceByID" ),
135                                                  ( request == null ? ExceptionCode.MISSINGPARAMETERVALUE
136                                                                   : ExceptionCode.OPERATIONNOTSUPPORTED ) );
137            }
138    
139            String version = map.get( "VERSION" );
140            if ( version == null || !WCTService.version.equalsIgnoreCase( version ) ) {
141                throw new OGCWebServiceException( Messages.getMessage( "WCTS_NO_VERSION_KVP", version ),
142                                                  ExceptionCode.MISSINGPARAMETERVALUE );
143            }
144    
145            String tmp = map.get( "RESOURCEID" );
146            List<String> resourceIDs = new ArrayList<String>( 10 );
147            if ( tmp != null && !"".equals( tmp.trim() ) ) {
148                String[] splitter = tmp.split( "," );
149                for ( String split : splitter ) {
150                    if ( split != null && !"".equals( split.trim() ) ) {
151                        resourceIDs.add( split.trim() );
152                    }
153                }
154            } else {
155                throw new OGCWebServiceException( Messages.getMessage( "WCTS_MISSING_MANDATORY_KEY_KVP", "ResourceID" ),
156                                                  ExceptionCode.MISSINGPARAMETERVALUE );
157            }
158    
159            String outputFormat = map.get( "OUTPUTFORMAT" );
160    
161            return new GetResourceByID( version, requestID, resourceIDs, outputFormat );
162        }
163    
164    }