root / branches / v10 / extensions / extPublish / src / com / iver / cit / gvsig / publish / serversModel / Server.java @ 13570
History | View | Annotate | Download (4.21 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 |
/**
|
42 |
* @author Jos? Vicente Hig?n (josevicente.higon@iver.es)
|
43 |
*/
|
44 |
package com.iver.cit.gvsig.publish.serversModel; |
45 |
|
46 |
import java.util.Collection; |
47 |
import java.util.Iterator; |
48 |
import java.util.LinkedHashMap; |
49 |
import java.util.Set; |
50 |
|
51 |
import com.iver.cit.gvsig.publish.infoProject.IViewInfo; |
52 |
|
53 |
public abstract class Server { |
54 |
/*
|
55 |
* HashMap with its Services
|
56 |
*/
|
57 |
private LinkedHashMap services = null; |
58 |
/*
|
59 |
* Server constants
|
60 |
*/
|
61 |
//constant to identify the server extension point
|
62 |
public static String PUBLISH_SERVERS = "publish_servers"; |
63 |
/*
|
64 |
* Server register
|
65 |
*/
|
66 |
public static ServerRegister register = new ServerRegister(); |
67 |
/*
|
68 |
* Server relations
|
69 |
*/
|
70 |
private IViewInfo view = null; |
71 |
|
72 |
/**
|
73 |
* Constructor
|
74 |
*
|
75 |
* Creates all the services of the server
|
76 |
*/
|
77 |
public Server(){
|
78 |
//creates a hashmap with its services
|
79 |
services = new LinkedHashMap(); |
80 |
Set set = Service.register.getServicesNames(this.getType()); |
81 |
Iterator i = set.iterator();
|
82 |
while(i.hasNext()){
|
83 |
String serviceName = (String)i.next(); |
84 |
Service service = (Service) Service.register.getInstance(this.getType(),serviceName);
|
85 |
addService(serviceName, service); |
86 |
} |
87 |
} |
88 |
|
89 |
/**
|
90 |
* Adds one remote resource by any layerInfo in each service
|
91 |
*
|
92 |
* TODO: I must check if services are null . That implies no one server are been registered
|
93 |
*
|
94 |
* @param view
|
95 |
*/
|
96 |
public void initialize(IViewInfo view){ |
97 |
this.view = view;
|
98 |
//clear all the services
|
99 |
//services.clear();
|
100 |
Set set = services.keySet();
|
101 |
Iterator i = set.iterator();
|
102 |
while(i.hasNext()){
|
103 |
String serviceName = (String)i.next(); |
104 |
Service s = (Service) services.get(serviceName); |
105 |
s.initialize(view); |
106 |
} |
107 |
} |
108 |
|
109 |
/**
|
110 |
* Gets a service identified by a name
|
111 |
* @param serviceName
|
112 |
* @return
|
113 |
*/
|
114 |
public Service getService(String serviceName){ |
115 |
Service s = null;
|
116 |
s = (Service) services.get(serviceName); |
117 |
return s;
|
118 |
} |
119 |
/**
|
120 |
* Usefull for generate a tree model
|
121 |
* @return
|
122 |
*/
|
123 |
public Service getService(int position){ |
124 |
Collection collection = services.values();
|
125 |
Object[] objects = collection.toArray(); |
126 |
return (Service) objects[position];
|
127 |
} |
128 |
public int getServicesCount(){ |
129 |
Set set = services.entrySet();
|
130 |
Object[] objects = set.toArray(); |
131 |
return objects.length;
|
132 |
} |
133 |
/**
|
134 |
* Adds a service into the server
|
135 |
* @param serviceName
|
136 |
* @param service
|
137 |
*/
|
138 |
private void addService(String serviceName, Service service){ |
139 |
services.put(serviceName, service); |
140 |
} |
141 |
|
142 |
/**
|
143 |
* String to identify the type of server
|
144 |
*
|
145 |
* @return
|
146 |
*/
|
147 |
public abstract String getType(); |
148 |
|
149 |
/**
|
150 |
*
|
151 |
* Call the method publish of its services
|
152 |
* @throws PublishException
|
153 |
*/
|
154 |
public void publish() throws PublishException{ |
155 |
Collection allServices = services.values();
|
156 |
Iterator i = allServices.iterator();
|
157 |
while(i.hasNext()){
|
158 |
Service s = (Service) i.next(); |
159 |
s.publish(); |
160 |
} |
161 |
System.err.println("ELIMINAR: publish():" + this.getType()); |
162 |
} |
163 |
/**
|
164 |
* Each server must verify if its remote resources are compatible
|
165 |
*/
|
166 |
public abstract void postInitialize(); |
167 |
|
168 |
public String toString(){ |
169 |
return getType();
|
170 |
} |
171 |
|
172 |
} |