root / trunk / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / CatalogClient.java @ 3486
History | View | Annotate | Download (5.58 KB)
1 | 2820 | jorpiell | /* 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 | 2047 | luisw | package es.gva.cit.catalogClient; |
42 | 2150 | jorpiell | |
43 | 3213 | jorpiell | import es.gva.cit.catalogClient.csw.drivers.CSWCatalogServiceDriver; |
44 | 2724 | jorpiell | import es.gva.cit.catalogClient.drivers.ICatalogServiceDriver; |
45 | 3213 | jorpiell | import es.gva.cit.catalogClient.srw.drivers.SRWCatalogServiceDriver; |
46 | 3486 | jorpiell | import es.gva.cit.catalogClient.utils.comboServer.ServerData; |
47 | 3213 | jorpiell | import es.gva.cit.catalogClient.z3950.drivers.Z3950CatalogServiceDriver; |
48 | 2724 | jorpiell | |
49 | 2047 | luisw | import java.io.IOException; |
50 | 2724 | jorpiell | |
51 | 2047 | luisw | import java.net.MalformedURLException; |
52 | import java.net.Socket; |
||
53 | import java.net.URL; |
||
54 | import java.net.UnknownHostException; |
||
55 | 2820 | jorpiell | /**
|
56 | 2852 | jorpiell | * This class represents a catalogClient. It must be created to
|
57 | * use the catalog service
|
||
58 | *
|
||
59 | 2820 | jorpiell | * @author Jorge Piera Llodra (piera_jor@gva.es)
|
60 | */
|
||
61 | 2724 | jorpiell | public class CatalogClient { |
62 | private URL url = null; |
||
63 | 3225 | jorpiell | private String sURL = null; |
64 | 2724 | jorpiell | private String protocol = null; |
65 | private ICatalogServiceDriver lnkICatalogServerDriver;
|
||
66 | 2047 | luisw | |
67 | 3454 | jorpiell | /**
|
68 | * Constructor
|
||
69 | * @param url
|
||
70 | * Server url
|
||
71 | * @param protocol
|
||
72 | * Server protocol
|
||
73 | * @param database
|
||
74 | * Database name. This param only is used when the protocol
|
||
75 | * is z39.50
|
||
76 | */
|
||
77 | 2724 | jorpiell | public CatalogClient(String url, String protocol, String database) { |
78 | setProtocol(protocol); |
||
79 | 3225 | jorpiell | setSURL(url); |
80 | 2047 | luisw | |
81 | 2724 | jorpiell | //This is necessary. Otherwise it will throw the exception
|
82 | if (!(url.regionMatches(0, "http://", 0, 7))) { |
||
83 | url = "http://" + url;
|
||
84 | } |
||
85 | |||
86 | try {
|
||
87 | this.setUrl(new URL(url)); |
||
88 | |||
89 | //if protocol is z39.50 we have to add the database to the URL
|
||
90 | 3486 | jorpiell | if (!(protocol.equals(new String(ServerData.SERVER_SUBTYPE_CATALOG_Z3950)))) { |
91 | 2724 | jorpiell | database = getUrl().getPath(); |
92 | } |
||
93 | |||
94 | //if protocol is http, we have to set the port manually
|
||
95 | if (getUrl().getPort() == -1) { |
||
96 | setUrl(new URL("http", getUrl().getHost(), 80, database)); |
||
97 | } else {
|
||
98 | setUrl(new URL("http", getUrl().getHost(), getUrl().getPort(), |
||
99 | database)); |
||
100 | } |
||
101 | } catch (MalformedURLException e) { |
||
102 | // TODO Auto-generated catch block
|
||
103 | System.out.println("La URL no es correcta"); |
||
104 | } |
||
105 | |||
106 | //Casting to the respective driver
|
||
107 | 3486 | jorpiell | if (protocol.equals(new String(ServerData.SERVER_SUBTYPE_CATALOG_SRW))) { |
108 | 2724 | jorpiell | lnkICatalogServerDriver = new SRWCatalogServiceDriver();
|
109 | } |
||
110 | |||
111 | 3486 | jorpiell | if (protocol.equals(new String(ServerData.SERVER_SUBTYPE_CATALOG_CSW))) { |
112 | 2724 | jorpiell | lnkICatalogServerDriver = new CSWCatalogServiceDriver();
|
113 | } |
||
114 | |||
115 | 3486 | jorpiell | if (protocol.equals(new String(ServerData.SERVER_SUBTYPE_CATALOG_Z3950))) { |
116 | 2724 | jorpiell | lnkICatalogServerDriver = new Z3950CatalogServiceDriver();
|
117 | } |
||
118 | 2047 | luisw | } |
119 | |||
120 | /**
|
||
121 | 2724 | jorpiell | * @return Returns the lnkICatalogServerDriver.
|
122 | 2047 | luisw | */
|
123 | 2724 | jorpiell | public ICatalogServiceDriver getLnkICatalogServerDriver() {
|
124 | return lnkICatalogServerDriver;
|
||
125 | } |
||
126 | 2047 | luisw | |
127 | 2724 | jorpiell | /**
|
128 | * @param lnkICatalogServerDriver The lnkICatalogServerDriver to set.
|
||
129 | */
|
||
130 | public void setLnkICatalogServerDriver( |
||
131 | ICatalogServiceDriver lnkICatalogServerDriver) { |
||
132 | this.lnkICatalogServerDriver = lnkICatalogServerDriver;
|
||
133 | } |
||
134 | 2145 | jorpiell | |
135 | 3225 | jorpiell | /**
|
136 | * @return Returns the protocol.
|
||
137 | */
|
||
138 | 2724 | jorpiell | public String getProtocol() { |
139 | return protocol;
|
||
140 | } |
||
141 | 3225 | jorpiell | |
142 | 2724 | jorpiell | |
143 | 3225 | jorpiell | |
144 | 2145 | jorpiell | /**
|
145 | 2724 | jorpiell | * @param protocol The protocol to set.
|
146 | */
|
||
147 | public void setProtocol(String protocol) { |
||
148 | this.protocol = protocol;
|
||
149 | } |
||
150 | |||
151 | /**
|
||
152 | * @return Returns the url.
|
||
153 | */
|
||
154 | public URL getUrl() { |
||
155 | return url;
|
||
156 | } |
||
157 | 3224 | jorpiell | |
158 | 3227 | jorpiell | /**
|
159 | * @return Returns the sUrl.
|
||
160 | */
|
||
161 | 3224 | jorpiell | public String getSUrl(){ |
162 | 3225 | jorpiell | return sURL;
|
163 | 3224 | jorpiell | } |
164 | 2724 | jorpiell | |
165 | /**
|
||
166 | * @param url The url to set.
|
||
167 | */
|
||
168 | public void setUrl(URL url) { |
||
169 | this.url = url;
|
||
170 | } |
||
171 | |||
172 | /**
|
||
173 | 2852 | jorpiell | * It tries if the server is ready
|
174 | 2724 | jorpiell | * @return boolean
|
175 | 2852 | jorpiell | * true --> server is ready
|
176 | 2145 | jorpiell | * false --> server is not ready
|
177 | 2724 | jorpiell | */
|
178 | public boolean serverReady() { |
||
179 | try {
|
||
180 | Socket socket = new Socket(this.getUrl().getHost(), |
||
181 | this.getUrl().getPort());
|
||
182 | } catch (UnknownHostException e) { |
||
183 | // TODO Auto-generated catch block
|
||
184 | return false; |
||
185 | } catch (IOException e) { |
||
186 | // TODO Auto-generated catch block
|
||
187 | return false; |
||
188 | } |
||
189 | 2145 | jorpiell | |
190 | 2724 | jorpiell | return true; |
191 | } |
||
192 | 3225 | jorpiell | /**
|
193 | * @return Returns the sURL.
|
||
194 | */
|
||
195 | public String getSURL() { |
||
196 | return sURL;
|
||
197 | } |
||
198 | /**
|
||
199 | * @param surl The sURL to set.
|
||
200 | */
|
||
201 | public void setSURL(String surl) { |
||
202 | sURL = surl; |
||
203 | } |
||
204 | 2047 | luisw | } |