svn-gvsig-desktop / branches / v10 / extensions / extPublish / src / org / gvsig / publish / PublishRegister.java @ 19900
History | View | Annotate | Download (9.43 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004-2006 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 Iba?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 |
package org.gvsig.publish; |
42 |
|
43 |
import java.lang.reflect.InvocationTargetException; |
44 |
import java.util.ArrayList; |
45 |
import java.util.Iterator; |
46 |
import java.util.Set; |
47 |
|
48 |
import org.gvsig.publish.gui.publish.IPublishPluginController; |
49 |
import org.gvsig.publish.serversmodel.RemoteResource; |
50 |
import org.gvsig.publish.serversmodel.Server; |
51 |
import org.gvsig.publish.serversmodel.Service; |
52 |
|
53 |
import com.iver.utiles.extensionPoints.ExtensionPoint; |
54 |
import com.iver.utiles.extensionPoints.ExtensionPoints; |
55 |
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
56 |
|
57 |
/**
|
58 |
* This class represents the register of the publish extension.
|
59 |
* A publish plugin can register controllers, servers, services
|
60 |
* and remote resources.
|
61 |
* <p>
|
62 |
* Design pattern used: Singleton
|
63 |
* @author Jos? Vicente Hig?n (josevicente.higon@iver.es)
|
64 |
*
|
65 |
* TODO: I must put the prefix into each string constant
|
66 |
*
|
67 |
*/
|
68 |
public class PublishRegister { |
69 |
// static private String prefix = "publish";
|
70 |
static private PublishRegister instance = null; |
71 |
private ExtensionPoints extensionPoints = null; |
72 |
|
73 |
/**
|
74 |
*
|
75 |
* @return the publish's register
|
76 |
*/
|
77 |
static public PublishRegister register(){ |
78 |
if(instance ==null){ |
79 |
instance = new PublishRegister();
|
80 |
} |
81 |
return instance;
|
82 |
} |
83 |
/**
|
84 |
* Constructor:
|
85 |
*
|
86 |
* Creates an Extension Point in order to register new servers
|
87 |
*
|
88 |
* TODO: Is not necessary to create a extension point with "new"
|
89 |
*
|
90 |
*/
|
91 |
protected PublishRegister(){
|
92 |
extensionPoints = ExtensionPointsSingleton.getInstance(); |
93 |
} |
94 |
/**
|
95 |
* Add a server to the register
|
96 |
* @param key
|
97 |
* @param clase
|
98 |
*/
|
99 |
public void addServer(String key, Class clase){ |
100 |
extensionPoints.add("publish_servers",key,clase);
|
101 |
} |
102 |
/**
|
103 |
* Get the names of the registered servers
|
104 |
* @return
|
105 |
*/
|
106 |
public ArrayList getServerNames(){ |
107 |
Set set = null; |
108 |
Object o = extensionPoints.get("publish_servers"); |
109 |
if (o == null){ |
110 |
PublishLogger.getLog().error("ERROR PublishRegister: there isn't any server registered");
|
111 |
return null; |
112 |
}else{
|
113 |
ExtensionPoint ep = (ExtensionPoint) o; |
114 |
set = ep.keySet(); |
115 |
} |
116 |
ArrayList list = new ArrayList(); |
117 |
Iterator i = set.iterator();
|
118 |
while (i.hasNext()){
|
119 |
list.add(i.next()); |
120 |
} |
121 |
return list;
|
122 |
} |
123 |
// public Collection getServers(){
|
124 |
// Collection collection = null;
|
125 |
// Object o = extensionPoints.get(Server.PUBLISH_SERVERS);
|
126 |
// if (o == null){
|
127 |
// PublishLogger.getLog().error("ERROR PublishRegister: there isn't any server registered");
|
128 |
// }else{
|
129 |
// ExtensionPoint ep = (ExtensionPoint) o;
|
130 |
// collection = ep.values();
|
131 |
// }
|
132 |
// return collection;
|
133 |
// }
|
134 |
/**
|
135 |
* Gets a server instance.
|
136 |
* The name of the extension point is "publish_servers".
|
137 |
* @param key
|
138 |
* @return
|
139 |
*
|
140 |
*/
|
141 |
public Server getServer(String key){ |
142 |
Server s = null;
|
143 |
ExtensionPoint ep = null;
|
144 |
ep = (ExtensionPoint) extensionPoints.get("publish_servers");
|
145 |
try {
|
146 |
s = (Server) ep.create(key); |
147 |
} catch (InstantiationException e) { |
148 |
PublishLogger.getLog().error("ERROR PublishRegister", e);
|
149 |
} catch (IllegalAccessException e) { |
150 |
PublishLogger.getLog().error("ERROR PublishRegister", e);
|
151 |
} |
152 |
return s;
|
153 |
} |
154 |
/**
|
155 |
* Adds service to the register
|
156 |
* @param server
|
157 |
* @param service
|
158 |
* @param clase
|
159 |
*/
|
160 |
public void addService(String server, String service, Class clase){ |
161 |
extensionPoints.add(server,service,clase); |
162 |
} |
163 |
/**
|
164 |
*
|
165 |
* @param server string which identifies a server (server.REGISTER_TAG or server.getRegisterTag())
|
166 |
* @return names of the services registered by a server
|
167 |
*
|
168 |
*/
|
169 |
public ArrayList getServicesNames(String server){ |
170 |
ExtensionPoint ep = (ExtensionPoint) extensionPoints.get(server); |
171 |
Set set = ep.keySet();
|
172 |
Iterator i = set.iterator();
|
173 |
ArrayList list = new ArrayList(); |
174 |
while (i.hasNext()){
|
175 |
String aux = (String)i.next(); |
176 |
//aux = aux.split(server + "_")[1];
|
177 |
list.add(aux); |
178 |
} |
179 |
return list;
|
180 |
} |
181 |
|
182 |
// public Collection getServices(Server server){
|
183 |
// ExtensionPoint ep = (ExtensionPoint) extensionPoints.get(server.getType());
|
184 |
// Collection collection = ep.values();
|
185 |
// return collection;
|
186 |
// }
|
187 |
|
188 |
/**
|
189 |
* Gets a service instance. The steps are: to register the server,
|
190 |
* to register the service implemented by a server, finally, to get the servevice
|
191 |
*
|
192 |
* @param server string which identifies the server which registered the service
|
193 |
* @param service string which identifies the service to get (service.REGISTER_TAG or service.getRegisterTag())
|
194 |
* @return
|
195 |
*/
|
196 |
public Service getService(Server server, String service){ |
197 |
Service s = null;
|
198 |
ExtensionPoint ep = null;
|
199 |
ep = (ExtensionPoint) extensionPoints.get(server.getRegisterTag()); |
200 |
try {
|
201 |
Object[] objects = new Object[1]; |
202 |
objects[0] = server;
|
203 |
s = (Service) ep.create(service, objects); |
204 |
} catch (InstantiationException e) { |
205 |
PublishLogger.getLog().error("ERROR PublishRegister", e);
|
206 |
} catch (IllegalAccessException e) { |
207 |
PublishLogger.getLog().error("ERROR PublishRegister", e);
|
208 |
} catch (SecurityException e) { |
209 |
PublishLogger.getLog().error("ERROR PublishRegister", e);
|
210 |
} catch (IllegalArgumentException e) { |
211 |
PublishLogger.getLog().error("ERROR PublishRegister", e);
|
212 |
} catch (NoSuchMethodException e) { |
213 |
PublishLogger.getLog().error("ERROR PublishRegister", e);
|
214 |
} catch (InvocationTargetException e) { |
215 |
PublishLogger.getLog().error("ERROR PublishRegister", e);
|
216 |
} |
217 |
return s;
|
218 |
|
219 |
} |
220 |
/**
|
221 |
* Register a new remote resource.
|
222 |
* @param service
|
223 |
* @param remoteResource
|
224 |
* @param clase
|
225 |
*/
|
226 |
public void addRemoteResource(String server, String service, String remoteResource, Class clase ){ |
227 |
|
228 |
//extensionPoints = ExtensionPointsSingleton.getInstance();
|
229 |
String aux = server + "#" + service; |
230 |
extensionPoints.add(aux,remoteResource,clase); |
231 |
} |
232 |
/**
|
233 |
* @param server
|
234 |
* @param service
|
235 |
* @return names of the remote resources registered by a service.
|
236 |
* Null if no one remote resource has been registered.
|
237 |
*/
|
238 |
public Set getRemoteResourcesNames(String server, String service){ |
239 |
String aux= server + "#" + service; |
240 |
ExtensionPoint ep = (ExtensionPoint) extensionPoints.get(aux); |
241 |
Set set = null; |
242 |
if (ep !=null){ |
243 |
set = ep.keySet(); |
244 |
} |
245 |
return set;
|
246 |
} |
247 |
/**
|
248 |
* Gets a remote resource instance
|
249 |
*
|
250 |
* @param service
|
251 |
* @param remoteReosurceName
|
252 |
* @return
|
253 |
*/
|
254 |
public RemoteResource getRemoteResource(Service service, String remoteReosurceName){ |
255 |
RemoteResource r = null;
|
256 |
String aux = service.getServer().getRegisterTag() + "#" + service.getRegisterTag(); |
257 |
ExtensionPoint ep = (ExtensionPoint) extensionPoints.get(aux); |
258 |
try {
|
259 |
Object[] objects = new Object[1]; |
260 |
objects[0] = service;
|
261 |
r = (RemoteResource) ep.create(remoteReosurceName,objects); |
262 |
} catch (InstantiationException e) { |
263 |
PublishLogger.getLog().error("ERROR PublishRegister", e);
|
264 |
} catch (IllegalAccessException e) { |
265 |
PublishLogger.getLog().error("ERROR PublishRegister", e);
|
266 |
} catch (SecurityException e) { |
267 |
PublishLogger.getLog().error("ERROR PublishRegister", e);
|
268 |
} catch (IllegalArgumentException e) { |
269 |
PublishLogger.getLog().error("ERROR PublishRegister", e);
|
270 |
} catch (NoSuchMethodException e) { |
271 |
PublishLogger.getLog().error("ERROR PublishRegister", e);
|
272 |
} catch (InvocationTargetException e) { |
273 |
PublishLogger.getLog().error("ERROR PublishRegister", e);
|
274 |
} |
275 |
return r;
|
276 |
} |
277 |
/**
|
278 |
* Register a new gui controller
|
279 |
* @param key
|
280 |
* @param clase
|
281 |
*/
|
282 |
public void addController(String key, Class clase){ |
283 |
extensionPoints.add(IPublishPluginController.PUBLISH_PLUGIN_CONTROLLERS,key,clase); |
284 |
} |
285 |
/**
|
286 |
* Get the names of the registered gui controllers
|
287 |
* @return Set
|
288 |
*/
|
289 |
public Set getControllersNames(){ |
290 |
ExtensionPoint ep = (ExtensionPoint) extensionPoints.get(IPublishPluginController.PUBLISH_PLUGIN_CONTROLLERS); |
291 |
Set set = ep.keySet();
|
292 |
return set;
|
293 |
} |
294 |
/**
|
295 |
*
|
296 |
* @param key
|
297 |
* @return
|
298 |
* TODO: This method should throw a PublishException
|
299 |
*/
|
300 |
public IPublishPluginController getController(String key){ |
301 |
IPublishPluginController ctr = null;
|
302 |
ExtensionPoint ep = (ExtensionPoint) extensionPoints.get(IPublishPluginController.PUBLISH_PLUGIN_CONTROLLERS); |
303 |
try {
|
304 |
ctr = (IPublishPluginController) ep.create(key); |
305 |
} catch (InstantiationException e) { |
306 |
PublishLogger.getLog().error("ERROR PublishRegister", e);
|
307 |
} catch (IllegalAccessException e) { |
308 |
PublishLogger.getLog().error("ERROR PublishRegister", e);
|
309 |
} |
310 |
return ctr;
|
311 |
} |
312 |
|
313 |
} |