svn-gvsig-desktop / branches / v10 / extensions / extPublish / src / org / gvsig / publish / serversmodel / Publication.java @ 22616
History | View | Annotate | Download (8.94 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.serversmodel; |
42 |
|
43 |
import java.io.File; |
44 |
import java.util.ArrayList; |
45 |
import java.util.Observable; |
46 |
import java.util.Observer; |
47 |
|
48 |
import org.gvsig.publish.IPublishPersistence; |
49 |
import org.gvsig.publish.PublishLogger; |
50 |
import org.gvsig.publish.PublishRegister; |
51 |
import org.gvsig.publish.infoproject.IDataSourceInfo; |
52 |
import org.gvsig.publish.infoproject.ILayerInfo; |
53 |
import org.gvsig.publish.infoproject.IProjectInfo; |
54 |
import org.gvsig.publish.infoproject.datasources.IFileInfo; |
55 |
|
56 |
import com.iver.utiles.XMLEntity; |
57 |
/**
|
58 |
* Represents a publication, that is, a project information that can be accessible through a server
|
59 |
*
|
60 |
* @author jvhigon
|
61 |
*
|
62 |
*/
|
63 |
public class Publication extends Observable implements IPublishPersistence, Observer { |
64 |
//Access methods
|
65 |
public final int LOCAL_ACCESS=0; |
66 |
public final int REMOTE_MOUNT_POINT_ACCESS=1; |
67 |
|
68 |
/*
|
69 |
* Associations
|
70 |
*/
|
71 |
private Server server = null; |
72 |
private IProjectInfo iproject = null; |
73 |
/*
|
74 |
* Properties
|
75 |
*/
|
76 |
private String title = null; |
77 |
private int accessFileMethod = LOCAL_ACCESS; |
78 |
private String localMountPoint; |
79 |
private String remoteMountPoint; |
80 |
|
81 |
/**
|
82 |
* Sets the name of the publication
|
83 |
* @param name
|
84 |
*/
|
85 |
public void setTitle(String title){ |
86 |
this.title = title;
|
87 |
setChanged(); |
88 |
notifyObservers(); |
89 |
} |
90 |
/**
|
91 |
* Gets the publication's name
|
92 |
* @param name
|
93 |
* @return
|
94 |
*/
|
95 |
public String getTitle(){ |
96 |
return title;
|
97 |
} |
98 |
/**
|
99 |
* Sets the server of the publication
|
100 |
* TODO: Is not clear. Should I use the method addObserver here?
|
101 |
* @param s Server
|
102 |
*/
|
103 |
public void setServer(Server s) { |
104 |
//set this like a observer the first time
|
105 |
if (server == null){ |
106 |
s.addObserver(this);
|
107 |
} |
108 |
//set associations
|
109 |
s.setPublication(this);
|
110 |
//init variables
|
111 |
this.server = s;
|
112 |
//this.server.setProjectInfo(getProjectInfo());
|
113 |
|
114 |
//notify publication observers
|
115 |
setChanged(); |
116 |
notifyObservers(); |
117 |
} |
118 |
/**
|
119 |
* Gets the server of the publication
|
120 |
* @return
|
121 |
*/
|
122 |
public Server getServer(){
|
123 |
return server;
|
124 |
} |
125 |
/**
|
126 |
* @return name of the publication
|
127 |
*/
|
128 |
public String toString(){ |
129 |
return getTitle();
|
130 |
} |
131 |
|
132 |
/**
|
133 |
* Sets the information about the project to publish.
|
134 |
* If a remote resource hasn't layerinfo it will be
|
135 |
* removed from the publication
|
136 |
*
|
137 |
* @param projectInfo
|
138 |
* @return an array of strings with the name of the layers
|
139 |
* that have been renamed or deleted
|
140 |
*/
|
141 |
public ArrayList setProjectInfo(IProjectInfo projectInfo) { |
142 |
iproject = projectInfo; |
143 |
ArrayList aux = new ArrayList(); |
144 |
Server s = getServer(); |
145 |
if (s !=null){ |
146 |
for (int i = 0; i < s.getServicesCount(); i++){ |
147 |
Service ss = s.getService(i); |
148 |
for (int j = 0; j < ss.getRemoteResourcesCount(); j++ ){ |
149 |
RemoteResource rr = ss.getRemoteResource(j); |
150 |
ILayerInfo ilayerinfo=null;
|
151 |
ilayerinfo = projectInfo.findLayer(rr.getId()); |
152 |
if (ilayerinfo == null){ |
153 |
aux.add(rr.getId()); |
154 |
rr.remove(); |
155 |
PublishLogger.getLog().error("Cannot find the layer with name " + rr.getId());
|
156 |
} |
157 |
} |
158 |
} |
159 |
} |
160 |
return aux;
|
161 |
} |
162 |
/**
|
163 |
*
|
164 |
* @return information about the project resources to publish
|
165 |
*/
|
166 |
public IProjectInfo getProjectInfo() {
|
167 |
return iproject;
|
168 |
} |
169 |
/*
|
170 |
* (non-Javadoc)
|
171 |
* @see java.util.Observer#update(java.util.Observable, java.lang.Object)
|
172 |
*/
|
173 |
public void update(Observable o, Object arg) { |
174 |
if (o instanceof Server){ |
175 |
setServer((Server)o); |
176 |
}else{
|
177 |
PublishLogger.getLog().error("ERROR Publication: The observable object must be a server");
|
178 |
} |
179 |
|
180 |
} |
181 |
|
182 |
/*
|
183 |
* (non-Javadoc)
|
184 |
* @see com.iver.utiles.IPersistance#getXMLEntity()
|
185 |
*/
|
186 |
public XMLEntity getXMLEntity() {
|
187 |
XMLEntity xml=new XMLEntity();
|
188 |
//put version and name
|
189 |
xml.setName(getClassName()); |
190 |
xml.putProperty("version", getVersion());
|
191 |
//put properties
|
192 |
xml.putProperty("title", getTitle());
|
193 |
xml.putProperty("accessfilemethod", getAccessFileMethod());
|
194 |
xml.putProperty("localmountpoint", getLocalMountPoint());
|
195 |
xml.putProperty("remotemountpoint", getRemoteMountPoint());
|
196 |
|
197 |
if (getServer() != null){ |
198 |
xml.addChild(getServer().getXMLEntity()); |
199 |
} |
200 |
return xml;
|
201 |
} |
202 |
/*
|
203 |
* (non-Javadoc)
|
204 |
* @see com.iver.utiles.IPersistance#setXMLEntity(com.iver.utiles.XMLEntity)
|
205 |
*/
|
206 |
public void setXMLEntity(XMLEntity xml) { |
207 |
//check version
|
208 |
int version = xml.getIntProperty("version"); |
209 |
if (version != getVersion()){
|
210 |
PublishLogger.getLog().error("ERROR: " + getVersion() + ": the version doesn't match!"); |
211 |
return;
|
212 |
} |
213 |
//set properties
|
214 |
setAccessFileMethod(xml.getIntProperty("accessfilemethod"));
|
215 |
setLocalMountPoint(xml.getStringProperty("localmountpoint"));
|
216 |
setRemoteMountPoint(xml.getStringProperty("remotemountpoint"));
|
217 |
//creates only the first server if exists
|
218 |
if (xml.getChildrenCount() > 0){ |
219 |
XMLEntity xmlChild=xml.getChild(0);
|
220 |
String server_type = xmlChild.getStringProperty("registertag"); |
221 |
Server s = PublishRegister.register().getServer(server_type); |
222 |
if (s==null){ |
223 |
PublishLogger.getLog().error("ERROR " + getVersion()+ ": I can't create the server from persistence"); |
224 |
}else{
|
225 |
//s.setProjectInfo(iproject);
|
226 |
s.setXMLEntity(xmlChild); |
227 |
setServer(s); |
228 |
} |
229 |
} |
230 |
|
231 |
} |
232 |
/*
|
233 |
* (non-Javadoc)
|
234 |
* @see com.iver.utiles.IPersistance#getClassName()
|
235 |
*/
|
236 |
public String getClassName() { |
237 |
return "Publication_v1"; |
238 |
} |
239 |
/*
|
240 |
* (non-Javadoc)
|
241 |
* @see org.gvsig.publish.IPublishPersistence#getVersion()
|
242 |
*/
|
243 |
public int getVersion() { |
244 |
return 1; |
245 |
} |
246 |
/**
|
247 |
* Gets the method in which the publication has been set.
|
248 |
* It can be Publication.LOCAL_ACCESS or Publication.REMOTE_MOUNT_POINT_ACCESS <p>
|
249 |
* LOCAL_ACCESS: the files to publish are located in the local filesystem. <br>
|
250 |
* REMOTE_MOUNT_POINT_ACCESS: the files are located in remote filesystem but are accessible through a remote mount point
|
251 |
*
|
252 |
* @return the accessFileMethod
|
253 |
*/
|
254 |
public int getAccessFileMethod() { |
255 |
return accessFileMethod;
|
256 |
} |
257 |
/**
|
258 |
* Sets the method in which the files are been accessed. It can be Publication.LOCAL_ACCESS or Publication.REMOTE_MOUNT_POINT_ACCESS.
|
259 |
* LOCAL_ACCESS: the files to publish are located in the local filesystem. <br>
|
260 |
* REMOTE_MOUNT_POINT_ACCESS: the files are located in remote filesystem but are accessible through a remote mount point
|
261 |
* @param accessFileMethod the accessFileMethod to set
|
262 |
*/
|
263 |
public void setAccessFileMethod(int accessFileMethod) { |
264 |
this.accessFileMethod = accessFileMethod;
|
265 |
// if (accessFileMethod == LOCAL_ACCESS){
|
266 |
// setLocalMountPoint(null);
|
267 |
// setRemoteMountPoint(null);
|
268 |
// }
|
269 |
setChanged(); |
270 |
} |
271 |
|
272 |
/**
|
273 |
* If the publication uses a REMOTE_MOUNT_POINT_ACCESS, this method change the path to a file in order
|
274 |
* to be accessible by a server.
|
275 |
*
|
276 |
* @return
|
277 |
*/
|
278 |
public String getServerSideFilePath(IDataSourceInfo ds){ |
279 |
String aux = ((IFileInfo)ds).getAbsolutePath();
|
280 |
return getServerSideFilePath(aux);
|
281 |
} |
282 |
/**
|
283 |
* If the publication uses a REMOTE_MOUNT_POINT_ACCESS, this method change the path to a file in order
|
284 |
*
|
285 |
* @param path changed
|
286 |
* @return
|
287 |
*/
|
288 |
public String getServerSideFilePath(String path){ |
289 |
if (getAccessFileMethod() == REMOTE_MOUNT_POINT_ACCESS){
|
290 |
if(remoteMountPoint.charAt(remoteMountPoint.length()-1)!= '/'){ |
291 |
remoteMountPoint = remoteMountPoint + "/";
|
292 |
} |
293 |
path = path.replace(localMountPoint, remoteMountPoint); |
294 |
path = path.replace(File.separator, "/"); |
295 |
} |
296 |
return path;
|
297 |
} |
298 |
|
299 |
/**
|
300 |
* @param localMountPoint the localMountPoint to set
|
301 |
*/
|
302 |
public void setLocalMountPoint(String localMountPoint) { |
303 |
this.localMountPoint = localMountPoint;
|
304 |
setChanged(); |
305 |
} |
306 |
/**
|
307 |
* @param remoteMountPoint the remoteMountPoint to set
|
308 |
*/
|
309 |
public void setRemoteMountPoint(String remoteMountPoint) { |
310 |
this.remoteMountPoint = remoteMountPoint;
|
311 |
setChanged(); |
312 |
} |
313 |
/**
|
314 |
* @return the localMountPoint
|
315 |
*/
|
316 |
public String getLocalMountPoint() { |
317 |
return localMountPoint;
|
318 |
} |
319 |
/**
|
320 |
* @return the remoteMountPoint
|
321 |
*/
|
322 |
public String getRemoteMountPoint() { |
323 |
return remoteMountPoint;
|
324 |
} |
325 |
} |