svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.image.extension / src / main / java / org / gvsig / arcims / image / gui / panels / utils / ServicesTableDataSource.java @ 32321
History | View | Annotate | Download (6.7 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 |
* 2010 Prodevelop S.L. main development
|
26 |
* http://www.prodevelop.es
|
27 |
*/
|
28 |
|
29 |
package org.gvsig.arcims.image.gui.panels.utils; |
30 |
|
31 |
import java.net.URL; |
32 |
import java.util.ArrayList; |
33 |
import java.util.Iterator; |
34 |
import java.util.List; |
35 |
import java.util.TreeSet; |
36 |
import java.util.Vector; |
37 |
|
38 |
import org.slf4j.Logger; |
39 |
import org.slf4j.LoggerFactory; |
40 |
import org.gvsig.andami.PluginServices; |
41 |
import org.gvsig.remoteclient.arcims.ArcImsProtocolHandler; |
42 |
import org.gvsig.remoteclient.arcims.exceptions.ArcImsException; |
43 |
import org.gvsig.remoteclient.arcims.utils.ServiceInfoTags; |
44 |
|
45 |
|
46 |
/**
|
47 |
* This class is used to get and use the data model of the
|
48 |
* available services table.
|
49 |
|
50 |
* @author jldominguez
|
51 |
*/
|
52 |
public class ServicesTableDataSource { |
53 |
protected static Logger logger = LoggerFactory.getLogger(ServicesTableDataSource.class.getName()); |
54 |
private Vector colNames; |
55 |
private Vector data; // vector of vectors |
56 |
private String nameColString = PluginServices.getText(this, "name"); |
57 |
private String typeColString = PluginServices.getText(this, |
58 |
"arcims_server_type_col_name");
|
59 |
private String statusColString = PluginServices.getText(this, |
60 |
"arcims_server_status_col_name");
|
61 |
|
62 |
/**
|
63 |
* The constructor is called with the server's URL as a parameter.
|
64 |
* Sets the columns names to "Name", "Type" and
|
65 |
* "Status" and gets the table data by sending a request to the server.
|
66 |
* @throws ArcImsException
|
67 |
*/
|
68 |
public ServicesTableDataSource(URL svrURL, boolean overrride) |
69 |
throws ArcImsException {
|
70 |
colNames = new Vector(); |
71 |
loadDataAndColNames(svrURL, overrride); |
72 |
|
73 |
if (data.size() > 0) { |
74 |
colNames.addElement(nameColString); |
75 |
colNames.addElement(typeColString); |
76 |
colNames.addElement(statusColString); |
77 |
} |
78 |
} |
79 |
|
80 |
/**
|
81 |
* Gets a vector with the column names.
|
82 |
*
|
83 |
* @return the vector with the column names.
|
84 |
*/
|
85 |
public Vector getColNamesVector() { |
86 |
return colNames;
|
87 |
} |
88 |
|
89 |
/**
|
90 |
* Gets a vector with the table's data.
|
91 |
*
|
92 |
* @return the table's data is a vector of vectors
|
93 |
*/
|
94 |
public Vector getDataVector() { |
95 |
return data;
|
96 |
} |
97 |
|
98 |
/**
|
99 |
* Sends a request to the server (ServiceName=catalog)
|
100 |
* and loads the private vectors (data and column names)
|
101 |
* @param tmpDriver
|
102 |
*
|
103 |
* @param serverURL server's URL
|
104 |
* @throws ArcImsException
|
105 |
*/
|
106 |
private void loadDataAndColNames(URL serverURL, boolean override) |
107 |
throws ArcImsException {
|
108 |
List<List<String>> _services = ArcImsProtocolHandler.getCatalog(serverURL, |
109 |
override); |
110 |
|
111 |
ArrayList services = leaveKnownServices(_services);
|
112 |
|
113 |
data = new Vector(); |
114 |
|
115 |
TreeSet auxTree = new TreeSet(); |
116 |
|
117 |
for (int i = 0; i < services.size(); i++) { |
118 |
ArrayList item = (ArrayList) services.get(i); |
119 |
auxTree.add(item.get(0));
|
120 |
} |
121 |
|
122 |
Iterator iter = auxTree.iterator();
|
123 |
|
124 |
while (iter.hasNext()) {
|
125 |
String name = (String) iter.next(); |
126 |
data.add(getItemWithName(services, name)); |
127 |
} |
128 |
|
129 |
// for (int i=0; i<services.size(); i++) {
|
130 |
// ArrayList item = (ArrayList) services.get(i);
|
131 |
// Vector vv = new Vector();
|
132 |
// vv.addElement( item.get(0) );
|
133 |
// vv.addElement( item.get(1) );
|
134 |
// vv.addElement( item.get(2) );
|
135 |
// // int insert = getInsertPosition(String str, data);
|
136 |
// // data.insertElementAt(vv); //, insert);
|
137 |
// }
|
138 |
} |
139 |
|
140 |
private ArrayList leaveKnownServices(List<List<String>> list) { |
141 |
ArrayList resp = new ArrayList(); |
142 |
ArrayList item;
|
143 |
String type;
|
144 |
String enabled;
|
145 |
|
146 |
for (int i = 0; i < list.size(); i++) { |
147 |
item = (ArrayList) list.get(i);
|
148 |
type = (String) item.get(1); |
149 |
enabled = (String) item.get(2); |
150 |
|
151 |
if (isKnownServiceType(type) && (isEnabled(enabled))) {
|
152 |
resp.add((ArrayList) item.clone());
|
153 |
} |
154 |
} |
155 |
|
156 |
return resp;
|
157 |
} |
158 |
|
159 |
private boolean isEnabled(String str) { |
160 |
if (str.compareToIgnoreCase("enabled") == 0) { |
161 |
return true; |
162 |
} |
163 |
|
164 |
return false; |
165 |
} |
166 |
|
167 |
private boolean isKnownServiceType(String type) { |
168 |
if (type.compareToIgnoreCase(ServiceInfoTags.vIMAGESERVICE) == 0) { |
169 |
return true; |
170 |
} |
171 |
|
172 |
// if (type.compareToIgnoreCase(ServiceInfoTags.vFEATURESERVICE) == 0) {
|
173 |
// return true;
|
174 |
// }
|
175 |
|
176 |
return false; |
177 |
} |
178 |
|
179 |
private Vector getItemWithName(ArrayList allitems, String name) { |
180 |
for (int i = 0; i < allitems.size(); i++) { |
181 |
if (((String) ((ArrayList) allitems.get(i)).get(0)).compareToIgnoreCase( |
182 |
name) == 0) {
|
183 |
Vector vv = new Vector(); |
184 |
vv.addElement(((ArrayList) allitems.get(i)).get(0)); |
185 |
vv.addElement(((ArrayList) allitems.get(i)).get(1)); |
186 |
vv.addElement(((ArrayList) allitems.get(i)).get(2)); |
187 |
|
188 |
return vv;
|
189 |
} |
190 |
} |
191 |
|
192 |
logger.error("Service name not found ");
|
193 |
|
194 |
return null; |
195 |
} |
196 |
|
197 |
private int getInsertPosition(String str, Vector data) { |
198 |
for (int i = 0; i < data.size(); i++) { |
199 |
String aux = (String) ((ArrayList) data.get(i)).get(0); |
200 |
|
201 |
if (aux.compareToIgnoreCase(str) > 0) { |
202 |
return i;
|
203 |
} |
204 |
} |
205 |
|
206 |
return data.size();
|
207 |
} |
208 |
|
209 |
/**
|
210 |
* Gets the name of the <i>n</i>th column (<i>n</i> = columnIndex)
|
211 |
*
|
212 |
* @return column name
|
213 |
*/
|
214 |
public String getColumnName(int columnIndex) { |
215 |
if (columnIndex == 0) { |
216 |
return nameColString;
|
217 |
} |
218 |
|
219 |
if (columnIndex == 1) { |
220 |
return typeColString;
|
221 |
} |
222 |
|
223 |
if (columnIndex == 2) { |
224 |
return statusColString;
|
225 |
} |
226 |
|
227 |
return "(Columna desconocida)"; |
228 |
} |
229 |
} |