Statistics
| Revision:

root / trunk / extensions / extSymbology / src / org / gvsig / remoteClient / sld / layers / AbstractSLDLayer.java @ 20768

History | View | Annotate | Download (8.75 KB)

1
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib��ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41

    
42
package org.gvsig.remoteClient.sld.layers;
43

    
44
import java.util.ArrayList;
45
import java.util.HashSet;
46
import java.util.Set;
47

    
48
import org.gvsig.remoteClient.sld.SLDFeatureTypeStyle;
49
import org.gvsig.remoteClient.sld.SLDLayerFeatureConstraints;
50
import org.gvsig.remoteClient.sld.SLDRule;
51
import org.gvsig.remoteClient.sld.filterEncoding.Filter;
52
import org.gvsig.remoteClient.sld.styles.AbstractSLDStyle;
53
import org.gvsig.remoteClient.sld.styles.SLDUserStyle;
54
import org.gvsig.remoteClient.sld.symbolizers.ISLDSymbolizer;
55

    
56
import com.iver.cit.gvsig.fmap.core.FShape;
57

    
58
/**
59
 * Implements an abstract class for the different kinds of layer that supports SLD
60
 * implementation specification .<p>
61
 * The Name element identifies the well-known name of the layer being referenced, and is
62
 * required. All possible well-known names are usually identified in the capabilities
63
 * document for a server.<p>
64
 * The LayerFeatureConstraints element is optional in a NamedLayer and allows the
65
 * user to specify constraints on what features of what feature types are to be 
66
 * selected by the named-layer reference. It is essentially a filter that allows the
67
 * selection of fewer features than are present in the named layer.<p>
68
 * A named styled layer can include any number of named styles and user-defined 
69
 * styles,including zero, mixed in any order. If zero styles are specified, then 
70
 * the default styling for the specified named layer is to be used.<p>
71
 * A named style, similar to a named layer, is referenced by a well-known name. A
72
 * particular named style only has meaning when used in conjunction with a particular
73
 * named layer. All available styles for each available layer are normally named in a
74
 * capabilities document.
75
 * 
76
 * @see SLDNamedLayer
77
 * @see SLDUserLayer
78
 * @see http://portal.opengeospatial.org/files/?artifact_id=1188
79
 * 
80
 * @author pepe vidal salvador - jose.vidal.salvador@iver.es
81
 */
82
public abstract class AbstractSLDLayer implements ISLDLayer {
83

    
84
        protected String name;
85
        protected ArrayList<SLDLayerFeatureConstraints>layerFeatureConstraints = new ArrayList<SLDLayerFeatureConstraints>();
86
        protected ArrayList<AbstractSLDStyle>layerStyles = new ArrayList<AbstractSLDStyle>();
87
                
88

    
89
        public ArrayList<ISLDSymbolizer> getSymbolizersByShapeType(int type) {
90

    
91
                ArrayList<ISLDSymbolizer> symbolizers = new ArrayList<ISLDSymbolizer>();
92
                for (int i = 0; i < this.getLayerStyles().size(); i++) {
93
                        if (getLayerStyles().get(i) instanceof SLDUserStyle) {
94
                                SLDUserStyle myStyle = (SLDUserStyle) this.getLayerStyles().get(i);
95
                                for (int k = 0; k < myStyle.getFeatureTypeStyle().size(); k++) {
96
                                        SLDFeatureTypeStyle myFeatureTypeStyle = myStyle.getFeatureTypeStyle().get(k);
97
                                        for (int s = 0; s < myFeatureTypeStyle.getRules().size(); s++) {
98
                                                SLDRule myRule = (SLDRule) myFeatureTypeStyle.getRules().get(s);
99

    
100
                                                if(type == FShape.LINE) {
101
                                                        for (int j = 0; j < myRule.getLineSymbolizers().size(); j++) {
102
                                                                symbolizers.add(myRule.getLineSymbolizers().get(j));
103
                                                        }
104
                                                }
105
                                                else if(type == FShape.POLYGON) {
106
                                                        for (int j = 0; j < myRule.getPolygonSymbolizers().size(); j++) {
107
                                                                symbolizers.add(myRule.getPolygonSymbolizers().get(j));
108
                                                        }
109
                                                }
110
                                                else if(type == FShape.POINT) {
111
                                                        for (int j = 0; j < myRule.getPointSymbolizers().size(); j++) {
112
                                                                symbolizers.add(myRule.getPointSymbolizers().get(j));
113
                                                        }
114
                                                }
115
                                        }
116
                                }
117
                        }
118
                }
119
                return symbolizers;
120
        }
121
        
122
        public ArrayList<Filter> getLayerFilters() {
123
                ArrayList<Filter> layerFilter = new ArrayList<Filter>();
124
                for (int i = 0; i < this.getLayerStyles().size(); i++) {
125
                        if (this.getLayerStyles().get(i) instanceof SLDUserStyle) {
126
                                SLDUserStyle userStyle = (SLDUserStyle) this.getLayerStyles().get(i);
127
                                for (int j = 0; j < userStyle.getFeatureTypeStyle().size(); j++) {
128
                                        SLDFeatureTypeStyle featTypeStyle = userStyle.getFeatureTypeStyle().get(j);
129
                                        for (int k = 0; k < featTypeStyle.getRules().size(); k++) {
130
                                                SLDRule rule = (SLDRule) featTypeStyle.getRules().get(k);
131
                                                if (rule.getFilter() != null)
132
                                                        layerFilter.add(rule.getFilter());
133
                                        }
134
                                }
135
                        }
136
                }
137
                return layerFilter;
138
        }
139

    
140
        public String[] getFieldNames() {
141
                Set <String> l = new HashSet<String>();
142
                for (int i = 0; i < this.getLayerFilters().size(); i++) {
143
                        l.addAll(getLayerFilters().get(i).getFieldNames());        
144
                }
145
                return l.toArray(new String[l.size()]);
146
        }
147

    
148
        public boolean layerHasFilterForSymbolizers(int shapeType) {
149
                for (int i = 0; i < getLayerStyles().size(); i++) {
150
                        if(getLayerStyles().get(i) instanceof SLDUserStyle) {
151
                                SLDUserStyle myStyle = (SLDUserStyle) getLayerStyles().get(i);
152
                                for (int j = 0; j < myStyle.getFeatureTypeStyle().size(); j++) {
153
                                        SLDFeatureTypeStyle myFeatureTypeStyle = myStyle.getFeatureTypeStyle().get(j);
154
                                        for (int k = 0; k < myFeatureTypeStyle.getRules().size(); k++) {
155
                                                SLDRule myRule = (SLDRule) myFeatureTypeStyle.getRules().get(k);
156
                                                if(myRule.hasFilter()) {
157
                                                        if(shapeType == FShape.LINE && myRule.getLineSymbolizers().size() > 0)return true;
158
                                                        else if (shapeType == FShape.POLYGON && myRule.getPolygonSymbolizers().size() > 0)return true;
159
                                                        else if (shapeType == FShape.POINT && myRule.getPointSymbolizers().size() > 0)return true;
160
                                                }
161
                                        }
162
                                }
163
                        }
164
                }
165
                return false;
166
        }
167

    
168
        public boolean layerHasFilters() {
169
                for (int i = 0; i < getLayerStyles().size(); i++) {
170
                        if(getLayerStyles().get(i) instanceof SLDUserStyle) {
171
                                SLDUserStyle myStyle = (SLDUserStyle) getLayerStyles().get(i);
172
                                for (int j = 0; j < myStyle.getFeatureTypeStyle().size(); j++) {
173
                                        SLDFeatureTypeStyle myFeatureTypeStyle = myStyle.getFeatureTypeStyle().get(j);
174
                                        for (int k = 0; k < myFeatureTypeStyle.getRules().size(); k++) {
175
                                                SLDRule myRule = (SLDRule) myFeatureTypeStyle.getRules().get(k);
176
                                                if(myRule.hasFilter())return true;
177
                                        }
178
                                }
179
                        }
180
                }
181
                return false;
182
        }
183
        
184
        public boolean layerHasSymbolizers(int shapeType) {
185
                for (int i = 0; i < getLayerStyles().size(); i++) {
186
                        if(getLayerStyles().get(i) instanceof SLDUserStyle) {
187
                                SLDUserStyle myStyle = (SLDUserStyle) getLayerStyles().get(i);
188
                                for (int j = 0; j < myStyle.getFeatureTypeStyle().size(); j++) {
189
                                        SLDFeatureTypeStyle myFeatureTypeStyle = myStyle.getFeatureTypeStyle().get(j);
190
                                        for (int k = 0; k < myFeatureTypeStyle.getRules().size(); k++) {
191
                                                SLDRule myRule = (SLDRule) myFeatureTypeStyle.getRules().get(k);
192
                                                if(shapeType == FShape.LINE && myRule.getLineSymbolizers().size() > 0)return true;
193
                                                else if (shapeType == FShape.POLYGON && myRule.getPolygonSymbolizers().size() > 0)return true;
194
                                                else if (shapeType == FShape.POINT && myRule.getPointSymbolizers().size() > 0)return true;
195
                                        }
196
                                }
197
                        }
198
                }
199
                return false;
200
        }
201
        
202
        public String getName() { return name; }
203
        public void setName(String name) { this.name = name; }
204
        public ArrayList<AbstractSLDStyle> getLayerStyles() { return layerStyles; }
205
        public void setLayerStyles(ArrayList<AbstractSLDStyle> layerStyles) { this.layerStyles = layerStyles; }
206
        public ArrayList<SLDLayerFeatureConstraints> getLayerFeatureConstraints() {return layerFeatureConstraints;}
207
        public void setLayerFeatureConstraints(ArrayList<SLDLayerFeatureConstraints> layerFeatureConstraints) {        this.layerFeatureConstraints = layerFeatureConstraints;        }
208
        public void addLayerFeatureConstraint(SLDLayerFeatureConstraints layerFeatureCons) {this.layerFeatureConstraints.add(layerFeatureCons);        }
209
        public void addLayerStyle(AbstractSLDStyle style) {this.layerStyles.add(style);}
210
}