001 //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.4_testing/src/org/deegree/model/filterencoding/ExpressionDefines.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.model.filterencoding;
037
038 import java.util.HashMap;
039 import java.util.Map;
040
041 /**
042 * Defines codes and constants for easy coping with the different kinds of Expressions (both
043 * XML-Entities & JavaObjects).
044 *
045 * @author Markus Schneider
046 * @version 06.08.2002
047 */
048 public class ExpressionDefines {
049
050 // expression codes
051 /**
052 *
053 */
054 public static final int EXPRESSION = 0;
055
056 /**
057 *
058 */
059 public static final int PROPERTYNAME = 1;
060
061 /**
062 *
063 */
064 public static final int LITERAL = 2;
065
066 /**
067 *
068 */
069 public static final int FUNCTION = 3;
070
071 /**
072 *
073 */
074 public static final int ADD = 4;
075
076 /**
077 *
078 */
079 public static final int SUB = 5;
080
081 /**
082 *
083 */
084 public static final int MUL = 6;
085
086 /**
087 *
088 */
089 public static final int DIV = 7;
090
091 /**
092 *
093 */
094 public static final int UNKNOWN = -1;
095
096 /**
097 * Returns the id of an expression for a given name.
098 *
099 * @param name
100 *
101 * @return EXPRESSION / PROPERTYNAME / LITERAL / ...
102 */
103 public synchronized static int getIdByName( String name ) {
104 if ( names == null )
105 buildHashMaps();
106 ExpressionInfo expression = names.get( name.toLowerCase() );
107 if ( expression == null )
108 return UNKNOWN;
109 return expression.id;
110 }
111
112 /**
113 * Returns the name of an expression for a given id.
114 *
115 * @param id
116 *
117 * @return null / Name of expression
118 */
119 public static String getNameById( int id ) {
120 if ( names == null )
121 buildHashMaps();
122 ExpressionInfo expression = ids.get( new Integer( id ) );
123 if ( expression == null )
124 return null;
125 return expression.name;
126 }
127
128 // used to associate names with the expressions
129 private static Map<String, ExpressionInfo> names = null;
130
131 // used to associate ids (Integers) with the expressions
132 private static Map<Integer, ExpressionInfo> ids = null;
133
134 private static void addExpression( int id, String name ) {
135 ExpressionInfo expressionInfo = new ExpressionInfo( id, name );
136 names.put( name.toLowerCase(), expressionInfo );
137 ids.put( new Integer( id ), expressionInfo );
138 }
139
140 private static void buildHashMaps() {
141 names = new HashMap<String, ExpressionInfo>();
142 ids = new HashMap<Integer, ExpressionInfo>();
143 addExpression( EXPRESSION, "Expression" );
144 addExpression( PROPERTYNAME, "PropertyName" );
145 addExpression( LITERAL, "Literal" );
146 addExpression( FUNCTION, "Function" );
147 addExpression( ADD, "Add" );
148 addExpression( SUB, "Sub" );
149 addExpression( MUL, "Mul" );
150 addExpression( DIV, "Div" );
151 }
152 }
153
154 class ExpressionInfo {
155
156 int id;
157
158 String name;
159
160 ExpressionInfo( int id, String name ) {
161 this.id = id;
162 this.name = name;
163
164 }
165 }