svn-gvsig-desktop / tags / v2_0_0_Build_2065 / extensions / extWFS2 / src / org / gvsig / wfs / gui / panels / model / WFSSelectedFeatureManager.java @ 40276
History | View | Annotate | Download (3.93 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2009 {Iver T.I.} {Task}
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.wfs.gui.panels.model; |
29 |
|
30 |
import java.text.Collator; |
31 |
import java.util.ArrayList; |
32 |
import java.util.Collections; |
33 |
import java.util.HashMap; |
34 |
import java.util.Hashtable; |
35 |
import java.util.Iterator; |
36 |
import java.util.Locale; |
37 |
|
38 |
import org.gvsig.fmap.dal.serverexplorer.wfs.WFSServerExplorer; |
39 |
import org.gvsig.remoteclient.wfs.WFSFeature; |
40 |
import org.gvsig.remoteclient.wfs.exceptions.WFSException; |
41 |
import org.gvsig.utils.StringComparator; |
42 |
import org.slf4j.Logger; |
43 |
import org.slf4j.LoggerFactory; |
44 |
|
45 |
|
46 |
/**
|
47 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
48 |
*/
|
49 |
public class WFSSelectedFeatureManager { |
50 |
private static final Logger LOG = LoggerFactory.getLogger(WFSSelectedFeatureManager.class); |
51 |
|
52 |
private WFSServerExplorer serverExplorer = null; |
53 |
|
54 |
//To keep the array of features
|
55 |
private Hashtable hashFeatures; |
56 |
private WFSSelectedFeature[] featuresList; |
57 |
|
58 |
private static HashMap featureManagers = new HashMap(); |
59 |
|
60 |
public static WFSSelectedFeatureManager getInstance(WFSServerExplorer serverExplorer){ |
61 |
if (featureManagers.containsKey(serverExplorer)){
|
62 |
return (WFSSelectedFeatureManager)featureManagers.get(serverExplorer);
|
63 |
} |
64 |
WFSSelectedFeatureManager selectedFeatureManager = new WFSSelectedFeatureManager(serverExplorer);
|
65 |
featureManagers.put(serverExplorer, selectedFeatureManager); |
66 |
return selectedFeatureManager;
|
67 |
} |
68 |
|
69 |
|
70 |
/**
|
71 |
* @param serverExplorer
|
72 |
*/
|
73 |
private WFSSelectedFeatureManager(WFSServerExplorer serverExplorer) {
|
74 |
super();
|
75 |
this.serverExplorer = serverExplorer;
|
76 |
} |
77 |
|
78 |
public WFSSelectedFeature getFeatureInfo(String nameSpace, String layerName){ |
79 |
if (hashFeatures == null){ |
80 |
getLayerList(); |
81 |
} |
82 |
WFSSelectedFeature selectedFeature = (WFSSelectedFeature)hashFeatures.get(layerName); |
83 |
try {
|
84 |
WFSFeature feature = serverExplorer.getFeatureInfo(nameSpace, layerName); |
85 |
selectedFeature.setFeature(feature); |
86 |
} catch (WFSException e) {
|
87 |
// The feature doesn't has fields
|
88 |
LOG.error("Impossible to get the feature", e);
|
89 |
} |
90 |
return selectedFeature;
|
91 |
} |
92 |
|
93 |
public WFSSelectedFeature[] getLayerList(){ |
94 |
if (hashFeatures == null) { |
95 |
hashFeatures = new Hashtable(); |
96 |
Hashtable wfsFeatures = serverExplorer.getFeatures();
|
97 |
|
98 |
StringComparator stringComparator = new StringComparator();
|
99 |
// Set spanish rules and with case sensitive
|
100 |
Collator collator = Collator.getInstance(new Locale("es_ES")); |
101 |
stringComparator.setLocaleRules(stringComparator.new LocaleRules(true, collator));
|
102 |
stringComparator.setCaseSensitive(false);
|
103 |
|
104 |
ArrayList keysList = new ArrayList(wfsFeatures.keySet()); |
105 |
Collections.sort(keysList, stringComparator);
|
106 |
|
107 |
Iterator keys = keysList.iterator();
|
108 |
featuresList = new WFSSelectedFeature[wfsFeatures.size()];
|
109 |
|
110 |
for (int i=0 ; i<wfsFeatures.size() ; i++){ |
111 |
WFSFeature feature = (WFSFeature)wfsFeatures.get(keys.next()); |
112 |
WFSSelectedFeature selectedFeature = new WFSSelectedFeature(feature);
|
113 |
featuresList[i] = selectedFeature; |
114 |
hashFeatures.put(selectedFeature.getName(), selectedFeature); |
115 |
} |
116 |
} |
117 |
return featuresList;
|
118 |
} |
119 |
|
120 |
|
121 |
} |
122 |
|