    001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.4_testing/src/org/deegree/model/filterencoding/OperationDefines.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 OperationsMetadata (both XML-Entities &
    043     * JavaObjects).
    044     *
    045     * @author Markus Schneider
    046     * @version 06.08.2002
    047     */
    048    public class OperationDefines {
    049
    050        // used to associate names with the OperationInfos
    051        private static Map<String, OperationInfo> names = null;
    052
    053        // used to associate ids (Integers) with the OperationInfos
    054        private static Map<Integer, OperationInfo> ids = null;
    055
    056        // different types of operations
    057        /**
    058         *
    059         */
    060        public static final int TYPE_SPATIAL = 0;
    061
    062        /**
    063         *
    064         */
    065        public static final int TYPE_COMPARISON = 1;
    066
    067        /**
    068         *
    069         */
    070        public static final int TYPE_LOGICAL = 2;
    071
    072        /**
    073         *
    074         */
    075        public static final int TYPE_UNKNOWN = -1;
    076
    077        // spatial operations
    078        /**
    079         *
    080         */
    081        public static final int EQUALS = 0;
    082
    083        /**
    084         *
    085         */
    086        public static final int DISJOINT = 1;
    087
    088        /**
    089         *
    090         */
    091        public static final int INTERSECTS = 2;
    092
    093        /**
    094         *
    095         */
    096        public static final int TOUCHES = 3;
    097
    098        /**
    099         *
    100         */
    101        public static final int CROSSES = 4;
    102
    103        /**
    104         *
    105         */
    106        public static final int WITHIN = 5;
    107
    108        /**
    109         *
    110         */
    111        public static final int CONTAINS = 6;
    112
    113        /**
    114         *
    115         */
    116        public static final int OVERLAPS = 7;
    117
    118        /**
    119         *
    120         */
    121        public static final int BEYOND = 8;
    122
    123        /**
    124         *
    125         */
    126        public static final int BBOX = 9;
    127
    128        // calvin added on 10/21/2003
    129        /**
    130         *
    131         */
    132        public static final int DWITHIN = 10;
    133
    134        // comparison operations
    135        /**
    136         *
    137         */
    138        public static final int PROPERTYISEQUALTO = 100;
    139
    140        /**
    141         *
    142         */
    143        public static final int PROPERTYISNOTEQUALTO = 108;
    144
    145        /**
    146         *
    147         */
    148        public static final int PROPERTYISLESSTHAN = 101;
    149
    150        /**
    151         *
    152         */
    153        public static final int PROPERTYISGREATERTHAN = 102;
    154
    155        /**
    156         *
    157         */
    158        public static final int PROPERTYISLESSTHANOREQUALTO = 103;
    159
    160        /**
    161         *
    162         */
    163        public static final int PROPERTYISGREATERTHANOREQUALTO = 104;
    164
    165        /**
    166         *
    167         */
    168        public static final int PROPERTYISLIKE = 105;
    169
    170        /**
    171         *
    172         */
    173        public static final int PROPERTYISNULL = 106;
    174
    175        /**
    176         *
    177         */
    178        public static final int PROPERTYISBETWEEN = 107;
    179
    180        /**
    181         *
    182         */
    183        public static final int PROPERTYISINSTANCEOF = 150;
    184
    185        // logical operations
    186        /**
    187         *
    188         */
    189        public static final int AND = 200;
    190
    191        /**
    192         *
    193         */
    194        public static final int OR = 201;
    195
    196        /**
    197         *
    198         */
    199        public static final int NOT = 202;
    200
    201        /**
    202         *
    203         */
    204        public static final int UNKNOWN = -1;
    205
    206        static {
    207            if ( names == null )
    208                buildHashMaps();
    209        }
    210
    211        /**
    212         * Returns the type of an operation for a given name.
    213         *
    214         * @param name
    215         *
    216         * @return TYPE_SPATIAL / TYPE_COMPARISON / TYPE_LOGICAL / TYPE_UNKNOWN
    217         */
    218        public static int getTypeByName( String name ) {
    219            OperationInfo operationInfo = names.get( name );
    220            if ( operationInfo == null )
    221                return TYPE_UNKNOWN;
    222            return operationInfo.type;
    223        }
    224
    225        /**
    226         * Returns the id of an operation for a given name.
    227         *
    228         * @param name
    229         *
    230         * @return BBOX / PROPERTYISEQUAL / AND / ...
    231         */
    232        public static int getIdByName( String name ) {
    233            OperationInfo operationInfo = names.get( name.toLowerCase() );
    234            if ( operationInfo == null )
    235                return UNKNOWN;
    236            return operationInfo.id;
    237        }
    238
    239        /**
    240         * Returns the type of an operation for a given id.
    241         *
    242         * @param id
    243         *
    244         * @return TYPE_SPATIAL / TYPE_COMPARISON / TYPE_LOGICAL / TYPE_UNKNOWN
    245         */
    246        public static int getTypeById( int id ) {
    247            OperationInfo operationInfo = ids.get( new Integer( id ) );
    248            if ( operationInfo == null )
    249                return TYPE_UNKNOWN;
    250            return operationInfo.type;
    251        }
    252
    253        /**
    254         * Returns the name of an operation for a given id.
    255         *
    256         * @param id
    257         *
    258         * @return null / Name of operation
    259         */
    260        public static String getNameById( int id ) {
    261
    262            OperationInfo operationInfo = ids.get( new Integer( id ) );
    263            if ( operationInfo == null )
    264                return null;
    265            return operationInfo.name;
    266        }
    267
    268        private static void addOperationInfo( int id, String name, int type ) {
    269            OperationInfo operationInfo = new OperationInfo( id, type, name );
    270            names.put( name, operationInfo );
    271            names.put( name.toLowerCase(), operationInfo );
    272            names.put( name.toUpperCase(), operationInfo );
    273            ids.put( new Integer( id ), operationInfo );
    274        }
    275
    276        private static void buildHashMaps() {
    277            names = new HashMap<String, OperationInfo>( 25 );
    278            ids = new HashMap<Integer, OperationInfo>( 25 );
    279
    280            addOperationInfo( BBOX, "BBOX", TYPE_SPATIAL );
    281            addOperationInfo( EQUALS, "Equals", TYPE_SPATIAL );
    282            addOperationInfo( DISJOINT, "Disjoint", TYPE_SPATIAL );
    283            addOperationInfo( INTERSECTS, "Intersects", TYPE_SPATIAL );
    284            addOperationInfo( TOUCHES, "Touches", TYPE_SPATIAL );
    285            addOperationInfo( CROSSES, "Crosses", TYPE_SPATIAL );
    286            addOperationInfo( WITHIN, "Within", TYPE_SPATIAL );
    287            addOperationInfo( CONTAINS, "Contains", TYPE_SPATIAL );
    288            addOperationInfo( OVERLAPS, "Overlaps", TYPE_SPATIAL );
    289            addOperationInfo( BEYOND, "Beyond", TYPE_SPATIAL );
    290            addOperationInfo( DWITHIN, "DWithin", TYPE_SPATIAL );
    291
    292            addOperationInfo( PROPERTYISEQUALTO, "PropertyIsEqualTo", TYPE_COMPARISON );
    293            addOperationInfo( PROPERTYISNOTEQUALTO, "PropertyIsNotEqualTo", TYPE_COMPARISON );
    294            addOperationInfo( PROPERTYISLESSTHAN, "PropertyIsLessThan", TYPE_COMPARISON );
    295            addOperationInfo( PROPERTYISGREATERTHAN, "PropertyIsGreaterThan", TYPE_COMPARISON );
    296            addOperationInfo( PROPERTYISLESSTHANOREQUALTO, "PropertyIsLessThanOrEqualTo", TYPE_COMPARISON );
    297            addOperationInfo( PROPERTYISGREATERTHANOREQUALTO, "PropertyIsGreaterThanOrEqualTo", TYPE_COMPARISON );
    298            addOperationInfo( PROPERTYISLIKE, "PropertyIsLike", TYPE_COMPARISON );
    299            addOperationInfo( PROPERTYISNULL, "PropertyIsNull", TYPE_COMPARISON );
    300            addOperationInfo( PROPERTYISBETWEEN, "PropertyIsBetween", TYPE_COMPARISON );
    301            addOperationInfo( PROPERTYISINSTANCEOF, "PropertyIsInstanceOf", TYPE_COMPARISON );
    302
    303            addOperationInfo( AND, "And", TYPE_LOGICAL );
    304            addOperationInfo( OR, "Or", TYPE_LOGICAL );
    305            addOperationInfo( NOT, "Not", TYPE_LOGICAL );
    306        }
    307    }
    308
    309    class OperationInfo {
    310        int id;
    311
    312        int type;
    313
    314        String name;
    315
    316        OperationInfo( int id, int type, String name ) {
    317            this.id = id;
    318            this.type = type;
    319            this.name = name;
    320        }
    321    }