]> dev.renevier.net Git - syp.git/blob - openlayers/lib/OpenLayers/Filter/Logical.js
initial commit
[syp.git] / openlayers / lib / OpenLayers / Filter / Logical.js
1 /* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
2  * license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
3   * full text of the license. */
4
5
6 /**
7  * @requires OpenLayers/Filter.js
8  */
9
10 /**
11  * Class: OpenLayers.Filter.Logical
12  * This class represents ogc:And, ogc:Or and ogc:Not rules.
13  * 
14  * Inherits from
15  * - <OpenLayers.Filter>
16  */
17 OpenLayers.Filter.Logical = OpenLayers.Class(OpenLayers.Filter, {
18
19     /**
20      * APIProperty: filters
21      * {Array(<OpenLayers.Filter>)} Child filters for this filter.
22      */
23     filters: null, 
24      
25     /**
26      * APIProperty: type
27      * {String} type of logical operator. Available types are:
28      * - OpenLayers.Filter.Logical.AND = "&&";
29      * - OpenLayers.Filter.Logical.OR  = "||";
30      * - OpenLayers.Filter.Logical.NOT = "!";
31      */
32     type: null,
33
34     /** 
35      * Constructor: OpenLayers.Filter.Logical
36      * Creates a logical filter (And, Or, Not).
37      *
38      * Parameters:
39      * options - {Object} An optional object with properties to set on the
40      *     filter.
41      * 
42      * Returns:
43      * {<OpenLayers.Filter.Logical>}
44      */
45     initialize: function(options) {
46         this.filters = [];
47         OpenLayers.Filter.prototype.initialize.apply(this, [options]);
48     },
49     
50     /** 
51      * APIMethod: destroy
52      * Remove reference to child filters.
53      */
54     destroy: function() {
55         this.filters = null;
56         OpenLayers.Filter.prototype.destroy.apply(this);
57     },
58
59     /**
60      * APIMethod: evaluate
61      * Evaluates this filter in a specific context.  Should be implemented by
62      *     subclasses.
63      * 
64      * Parameters:
65      * context - {Object} Context to use in evaluating the filter.
66      * 
67      * Returns:
68      * {Boolean} The filter applies.
69      */
70     evaluate: function(context) {
71         switch(this.type) {
72             case OpenLayers.Filter.Logical.AND:
73                 for (var i=0, len=this.filters.length; i<len; i++) {
74                     if (this.filters[i].evaluate(context) == false) {
75                         return false;
76                     }
77                 }
78                 return true;
79                 
80             case OpenLayers.Filter.Logical.OR:
81                 for (var i=0, len=this.filters.length; i<len; i++) {
82                     if (this.filters[i].evaluate(context) == true) {
83                         return true;
84                     }
85                 }
86                 return false;
87             
88             case OpenLayers.Filter.Logical.NOT:
89                 return (!this.filters[0].evaluate(context));
90         }
91     },
92     
93     /**
94      * APIMethod: clone
95      * Clones this filter.
96      * 
97      * Returns:
98      * {<OpenLayers.Filter.Logical>} Clone of this filter.
99      */
100     clone: function() {
101         var filters = [];        
102         for(var i=0, len=this.filters.length; i<len; ++i) {
103             filters.push(this.filters[i].clone());
104         }
105         return new OpenLayers.Filter.Logical({
106             type: this.type,
107             filters: filters
108         });
109     },
110     
111     CLASS_NAME: "OpenLayers.Filter.Logical"
112 });
113
114
115 OpenLayers.Filter.Logical.AND = "&&";
116 OpenLayers.Filter.Logical.OR  = "||";
117 OpenLayers.Filter.Logical.NOT = "!";