001    //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/ogcwebservices/csw/discovery/SearchResults.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.csw.discovery;
037    
038    import java.net.URI;
039    import java.net.URISyntaxException;
040    import java.util.Date;
041    import java.util.GregorianCalendar;
042    
043    import org.deegree.ogcwebservices.InvalidParameterValueException;
044    import org.w3c.dom.Node;
045    
046    /**
047     * Class representation of a <csw:SearchResults>-element.
048     *
049     * The SearchResults is a generic container for the actual response to a GetRecords request. The
050     * content of the SearchResults is the set of records returned by the GetRecords operation. The
051     * actual records returned by the catalogue should substitute for AbstractRecord.
052     *
053     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a>
054     * @author <a href="mailto:tfr@users.sourceforge.net">Torsten Friebe </a>
055     * @author <a href="mailto:tfr@users.sourceforge.net">Markus Schneider </a>
056     * @author last edited by: $Author: mschneider $
057     *
058     * @version 2.0, $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18 Jun 2009) $
059     */
060    
061    public class SearchResults {
062    
063        private static final String[] ELEMENT_SETS = { "brief", "summary", "full" };
064    
065        private URI requestId = null;
066    
067        private URI resultSetId = null;
068    
069        private String elementSet = null;
070    
071        private URI recordSchema = null;
072    
073        private int numberOfRecordsReturned = 0;
074    
075        private int numberOfRecordsMatched = 0;
076    
077        private int nextRecord = 0;
078    
079        private Date expires = null;
080    
081        private Node recordsParentNode;
082    
083        /**
084         *
085         * @param requestId
086         * @param resultSetId
087         * @param elementSet
088         * @param recordSchema
089         * @param numberOfRecordsReturned
090         * @param nextRecord
091         * @param recordsParentNode
092         * @throws InvalidParameterValueException
093         */
094        SearchResults( String requestId, String resultSetId, String elementSet, String recordSchema,
095                       int numberOfRecordsReturned, int numberOfRecordsMatched, int nextRecord, Node recordsParentNode,
096                       String expires ) throws InvalidParameterValueException {
097    
098            if ( requestId != null ) {
099                try {
100                    this.requestId = new URI( null, requestId, null );
101                } catch ( URISyntaxException e ) {
102                    throw new InvalidParameterValueException( "Value '" + requestId
103                                                              + "' of Parameter 'requestId' does not denote a valid URI." );
104                }
105            }
106    
107            if ( resultSetId != null ) {
108                try {
109                    this.resultSetId = new URI( null, resultSetId, null );
110                } catch ( URISyntaxException e ) {
111                    throw new InvalidParameterValueException( "Value '" + resultSetId
112                                                              + "' of Parameter 'resultSetId' does not denote a valid URI." );
113                }
114            }
115    
116            if ( elementSet != null ) {
117                for ( int i = 0; i < ELEMENT_SETS.length; i++ ) {
118                    if ( ELEMENT_SETS[i].equals( elementSet ) ) {
119                        this.elementSet = elementSet;
120                    }
121                }
122                if ( this.elementSet == null ) {
123                    throw new InvalidParameterValueException( "Value '" + elementSet
124                                                              + "' of Parameter 'elementSet' is invalid. Valid parameters"
125                                                              + " are: 'full', 'summary' and 'brief'." );
126                }
127            }
128    
129            if ( recordSchema != null ) {
130                try {
131                    this.recordSchema = new URI( null, recordSchema, null );
132                } catch ( URISyntaxException e ) {
133                    throw new InvalidParameterValueException(
134                                                              "Value '"
135                                                                                      + recordSchema
136                                                                                      + "' of Parameter 'recordSchema' does not denote a valid URI." );
137                }
138            }
139    
140            this.numberOfRecordsReturned = numberOfRecordsReturned;
141            this.numberOfRecordsMatched = numberOfRecordsMatched;
142            // TODO
143            this.expires = new GregorianCalendar().getTime();// TimeTools.createCalendar( expires
144                                                                // ).getTime();
145            this.nextRecord = nextRecord;
146            this.recordsParentNode = recordsParentNode;
147        }
148    
149        /**
150         * @return the id
151         */
152        public URI getRequestId() {
153            return requestId;
154        }
155    
156        /**
157         * A server-generated identifier for the result set. May be used in subsequent GetRecords
158         * operations to further refine the result set. If the server does not implement this capability
159         * then the attribute should be omitted.
160         *
161         * @return the id
162         */
163        public URI getResultSetId() {
164            return resultSetId;
165        }
166    
167        /**
168         * The element set returned (brief, summary or full). This is null if getElementNames of
169         * <tt>GetRecord</tt>!= null; Optional
170         *
171         * @return brief, summary or full
172         */
173        public String getElementSet() {
174            return elementSet;
175        }
176    
177        /**
178         * A reference to the type or schema of the records returned. Optional
179         *
180         * @return schema
181         */
182        public URI getRecordSchema() {
183            return recordSchema;
184        }
185    
186        /**
187         * Number of records found by the GetRecords operation
188         *
189         * @return the number
190         */
191        public int getNumberOfRecordsMatched() {
192            return numberOfRecordsMatched;
193        }
194    
195        /**
196         * Number of records actually returned to client. This may not be the entire result set since
197         * some servers may limit the number of records returned to limit the size of the response
198         * package transmitted to the client. Subsequent queries may be executed to see more of the
199         * result set. The nextRecord attribute will indicate to the client where to begin the next
200         * query
201         *
202         * @return the number
203         */
204        public int getNumberOfRecordsReturned() {
205            return numberOfRecordsReturned;
206        }
207    
208        /**
209         * Start position of next record. A value of 0 means all records have been returned.
210         *
211         * @return the position
212         */
213        public int getNextRecord() {
214            return nextRecord;
215        }
216    
217        /**
218         * Returns the contents of the &lt;SearchResults&gt;-element.
219         *
220         * @return a node
221         */
222        public Node getRecords() {
223            return recordsParentNode;
224        }
225    
226        /**
227         * @return the expiration date
228         *
229         */
230        public Date getExpires() {
231            return expires;
232        }
233    
234    }