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