Statistics
| Revision:

svn-gvsig-desktop / tags / v1_11_0_Build_1306 / extensions / extArcims / src / es / prodevelop / cit / gvsig / arcims / gui / panels / utils / ServicesTableDataSource.java @ 35731

History | View | Annotate | Download (6.93 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 Prodevelop 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
 *   Prodevelop Integraci?n de Tecnolog?as SL
34
 *   Conde Salvatierra de ?lava , 34-10
35
 *   46004 Valencia
36
 *   Spain
37
 *
38
 *   +34 963 510 612
39
 *   +34 963 510 968
40
 *   gis@prodevelop.es
41
 *   http://www.prodevelop.es
42
 */
43
package es.prodevelop.cit.gvsig.arcims.gui.panels.utils;
44

    
45
import java.net.URL;
46
import java.util.ArrayList;
47
import java.util.Iterator;
48
import java.util.TreeSet;
49
import java.util.Vector;
50

    
51
import org.apache.log4j.Logger;
52
import org.gvsig.remoteClient.arcims.ArcImsProtocolHandler;
53
import org.gvsig.remoteClient.arcims.exceptions.ArcImsException;
54
import org.gvsig.remoteClient.arcims.utils.ServiceInfoTags;
55

    
56
import com.iver.andami.PluginServices;
57

    
58

    
59
/**
60
* This class is used to get and use the data model of the
61
* available services table.
62

63
* @author jldominguez
64
*/
65
public class ServicesTableDataSource {
66
    protected static Logger logger = Logger.getLogger(ServicesTableDataSource.class.getName());
67
    private Vector colNames;
68
    private Vector data; // vector of vectors
69
    private String nameColString = PluginServices.getText(this, "name");
70
    private String typeColString = PluginServices.getText(this,
71
            "arcims_server_type_col_name");
72
    private String statusColString = PluginServices.getText(this,
73
            "arcims_server_status_col_name");
74

    
75
    /**
76
    * The constructor is called with the server's URL as a parameter.
77
    * Sets the columns names to "Name", "Type" and
78
    * "Status" and gets the table data by sending a request to the server.
79
     * @throws ArcImsException
80
    */
81
    public ServicesTableDataSource(URL svrURL, boolean overrride)
82
        throws ArcImsException {
83
        colNames = new Vector();
84
        loadDataAndColNames(svrURL, overrride);
85

    
86
        if (data.size() > 0) {
87
            colNames.addElement(nameColString);
88
            colNames.addElement(typeColString);
89
            colNames.addElement(statusColString);
90
        }
91
    }
92

    
93
    /**
94
    * Gets a vector with the column names.
95
    *
96
    * @return the vector with the column names.
97
    */
98
    public Vector getColNamesVector() {
99
        return colNames;
100
    }
101

    
102
    /**
103
    * Gets a vector with the table's data.
104
    *
105
    * @return the table's data is a vector of vectors
106
    */
107
    public Vector getDataVector() {
108
        return data;
109
    }
110

    
111
    /**
112
    * Sends a request to the server (ServiceName=catalog)
113
    * and loads the private vectors (data and column names)
114
     * @param tmpDriver
115
    *
116
    * @param serverURL server's URL
117
     * @throws ArcImsException
118
    */
119
    private void loadDataAndColNames(URL serverURL, boolean override)
120
        throws ArcImsException {
121
        ArrayList _services = ArcImsProtocolHandler.getCatalog(serverURL,
122
                override);
123

    
124
        ArrayList services = leaveKnownServices(_services);
125

    
126
        data = new Vector();
127

    
128
        TreeSet auxTree = new TreeSet();
129

    
130
        for (int i = 0; i < services.size(); i++) {
131
            ArrayList item = (ArrayList) services.get(i);
132
            auxTree.add(item.get(0));
133
        }
134

    
135
        Iterator iter = auxTree.iterator();
136

    
137
        while (iter.hasNext()) {
138
            String name = (String) iter.next();
139
            data.add(getItemWithName(services, name));
140
        }
141

    
142
        //                for (int i=0; i<services.size(); i++) {
143
        //                        ArrayList item = (ArrayList) services.get(i);
144
        //                        Vector vv = new Vector();
145
        //                        vv.addElement( item.get(0) );
146
        //                        vv.addElement( item.get(1) );
147
        //                        vv.addElement( item.get(2) );
148
        //                        // int insert = getInsertPosition(String str, data);
149
        //                        // data.insertElementAt(vv); //, insert);
150
        //                }
151
    }
152

    
153
    private ArrayList leaveKnownServices(ArrayList list) {
154
        ArrayList resp = new ArrayList();
155
        ArrayList item;
156
        String type;
157
        String enabled;
158

    
159
        for (int i = 0; i < list.size(); i++) {
160
            item = (ArrayList) list.get(i);
161
            type = (String) item.get(1);
162
            enabled = (String) item.get(2);
163

    
164
            if (isKnownServiceType(type) && (isEnabled(enabled))) {
165
                resp.add((ArrayList) item.clone());
166
            }
167
        }
168

    
169
        return resp;
170
    }
171

    
172
    private boolean isEnabled(String str) {
173
        if (str.compareToIgnoreCase("enabled") == 0) {
174
            return true;
175
        }
176

    
177
        return false;
178
    }
179

    
180
    private boolean isKnownServiceType(String type) {
181
        if (type.compareToIgnoreCase(ServiceInfoTags.vIMAGESERVICE) == 0) {
182
            return true;
183
        }
184

    
185
        if (type.compareToIgnoreCase(ServiceInfoTags.vFEATURESERVICE) == 0) {
186
            return true;
187
        }
188

    
189
        return false;
190
    }
191

    
192
    private Vector getItemWithName(ArrayList allitems, String name) {
193
        for (int i = 0; i < allitems.size(); i++) {
194
            if (((String) ((ArrayList) allitems.get(i)).get(0)).compareToIgnoreCase(
195
                        name) == 0) {
196
                Vector vv = new Vector();
197
                vv.addElement(((ArrayList) allitems.get(i)).get(0));
198
                vv.addElement(((ArrayList) allitems.get(i)).get(1));
199
                vv.addElement(((ArrayList) allitems.get(i)).get(2));
200

    
201
                return vv;
202
            }
203
        }
204

    
205
        logger.error("Service name not found ");
206

    
207
        return null;
208
    }
209

    
210
    private int getInsertPosition(String str, Vector data) {
211
        for (int i = 0; i < data.size(); i++) {
212
            String aux = (String) ((ArrayList) data.get(i)).get(0);
213

    
214
            if (aux.compareToIgnoreCase(str) > 0) {
215
                return i;
216
            }
217
        }
218

    
219
        return data.size();
220
    }
221

    
222
    /**
223
    * Gets the name of the <i>n</i>th column (<i>n</i> = columnIndex)
224
    *
225
    * @return column name
226
    */
227
    public String getColumnName(int columnIndex) {
228
        if (columnIndex == 0) {
229
            return nameColString;
230
        }
231

    
232
        if (columnIndex == 1) {
233
            return typeColString;
234
        }
235

    
236
        if (columnIndex == 2) {
237
            return statusColString;
238
        }
239

    
240
        return "(Columna desconocida)";
241
    }
242
}