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