001    //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/io/datastore/schema/content/SpecialContent.java $
002    /*----------------    FILE HEADER  ------------------------------------------
003    
004     This file is part of deegree.
005     Copyright (C) 2001-2008 by:
006     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     Aennchenstraße 19
030     53177 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    package org.deegree.io.datastore.schema.content;
044    
045    import java.util.HashMap;
046    import java.util.Map;
047    
048    import org.deegree.i18n.Messages;
049    import org.deegree.ogcwebservices.wfs.operation.Query;
050    
051    /**
052     * Special content class that allows to refer to parameters of the {@link Query} or other properties
053     * of the environment.
054     * <p>
055     * Currently defined variables:
056     * 
057     * <table border="1">
058     * <tr>
059     * <th>Variable name</th>
060     * <th>Description</th>
061     * </tr>
062     * <tr>
063     * <td>$QUERY.BBOX</td>
064     * <td>Bounding box of the query (null if it is not present).</td>
065     * </tr>
066     * </table>
067     * </p>
068     * 
069     * @author <a href="mailto:schneider@lat-lon.de">Markus Schneider</a>
070     * @author last edited by: $Author: apoth $
071     * 
072     * @version $Revision: 9342 $, $Date: 2007-12-27 13:32:57 +0100 (Do, 27 Dez 2007) $
073     */
074    public class SpecialContent implements FunctionParam {
075    
076        /**
077         * Known variables.
078         */
079        public static enum VARIABLE {
080    
081            /**
082             * Bounding box of the query.
083             */
084            QUERY_BBOX
085        }
086    
087        /**
088         * Bounding box of the query (null if it is not present).
089         */
090        public final static String QUERY_BBOX_NAME = "$QUERY.BBOX";
091    
092        private static Map<String, VARIABLE> variableNameMap = new HashMap<String, VARIABLE>();
093    
094        static {
095            variableNameMap.put( QUERY_BBOX_NAME, VARIABLE.QUERY_BBOX );
096        }
097    
098        private VARIABLE variable;
099    
100        // backend-specific SRS (derived from other FunctionParams)
101        private int internalSRS = -1;
102    
103        /**
104         * Initializes a newly created <code>SpecialContent</code> object so that it represents the
105         * given variable.
106         * 
107         * @param variableName
108         * @throws IllegalArgumentException
109         *             if given variable is not known
110         */
111        public SpecialContent( String variableName ) {
112            variable = variableNameMap.get( variableName );
113            if ( variable == null ) {
114                StringBuffer variableList = new StringBuffer();
115                String[] knownVariables = getKnownVariables();
116                for ( int i = 0; i < knownVariables.length; i++ ) {
117                    variableList.append( '\'' );
118                    variableList.append( knownVariables[i] );
119                    variableList.append( '\'' );
120                    if ( i != knownVariables.length - 1 ) {
121                        variableList.append( ',' );
122                    }
123                }
124                String msg = Messages.getMessage( "DATASTORE_VARIABLE_UNKNOWN", variableName, variableList );
125                throw new IllegalArgumentException( msg );
126            }
127        }
128    
129        /**
130         * Returns the {@link VARIABLE}.
131         * 
132         * @return the variable
133         */
134        public VARIABLE getVariable() {
135            return this.variable;
136        }
137    
138        /**
139         * Returns all known variable names.
140         * 
141         * @return all known variable names
142         */
143        public static String[] getKnownVariables() {
144            return variableNameMap.keySet().toArray( new String[variableNameMap.keySet().size()] );
145        }
146    
147        /**
148         * Returns the vendor dependent descriptor for the SRS of the associated geometry.
149         * 
150         * @return vendor dependent descriptor for the SRS, may be null
151         */
152        public int getSRS() {
153            return this.internalSRS;
154        }
155    
156        /**
157         * Sets the vendor dependent descriptor for the SRS of the associated geometry.
158         * 
159         * @param internalSRS
160         *            the vendor dependent descriptor for the SRS
161         */
162        public void setSRS( int internalSRS ) {
163            this.internalSRS = internalSRS;
164        }
165    }