Revision 21390 branches/v10/extensions/extPublish/src/org/gvsig/publish/serversmodel/Publication.java

View differences:

Publication.java
46 46
import org.gvsig.publish.IPublishPersistence;
47 47
import org.gvsig.publish.PublishLogger;
48 48
import org.gvsig.publish.PublishRegister;
49
import org.gvsig.publish.infoproject.IDataSourceInfo;
49 50
import org.gvsig.publish.infoproject.IProjectInfo;
51
import org.gvsig.publish.infoproject.datasources.IFileInfo;
50 52

  
51 53
import com.iver.utiles.XMLEntity;
54
/**
55
 * Represents a publication, that is, a project information that can be accessible through a server  
56
 * 
57
 * @author jvhigon
58
 *
59
 */
60
public class Publication extends Observable implements IPublishPersistence, Observer {
61
	//Access methods
62
	public final int LOCAL_ACCESS=0;
63
	public final int REMOTE_MOUNT_POINT_ACCESS=1;
52 64

  
53
public class Publication extends Observable implements IPublishPersistence, Observer {
54
	
55 65
	/*
56 66
	 * Associations
57 67
	 */
......
59 69
	private IProjectInfo iproject = null;
60 70
	/*
61 71
	 * Properties
62
	 */
72
	 */	
63 73
	private String title = null;
74
	private int accessFileMethod = LOCAL_ACCESS;
75
	private String localMountPoint;
76
	private String remoteMountPoint;
77
	
64 78
	/**
65 79
	 * Sets the name of the publication
66 80
	 * @param name
......
87 101
		if (server == null){
88 102
			s.addObserver(this);
89 103
		}			
90
		
104
		//set associations
105
		s.setPublication(this);
91 106
		//init variables
92 107
		this.server = s;
93 108
		this.server.setProjectInfo(getProjectInfo());
94
		
109

  
95 110
		//notify publication observers
96 111
		setChanged();
97 112
		notifyObservers();	
......
109 124
	public String toString(){
110 125
		return getTitle();
111 126
	}
112
	
113
	
127

  
128
	/**
129
	 * Sets the information about the project to publish
130
	 * @param projectInfo
131
	 */
114 132
	public void setProjectInfo(IProjectInfo projectInfo) {
115 133
		iproject = projectInfo;		
116 134
	}
135
	/**
136
	 * 
137
	 * @return information about the project resources to publish
138
	 */
117 139
	public IProjectInfo getProjectInfo() {
118
		
119 140
		return iproject;
120 141
	}
142
	/*
143
	 * (non-Javadoc)
144
	 * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
145
	 */
121 146
	public void update(Observable o, Object arg) {
122 147
		if (o instanceof Server){
123 148
			setServer((Server)o);
124 149
		}else{
125 150
			PublishLogger.getLog().error("ERROR Publication: The observable object must be a server");
126 151
		}
127
		
152

  
128 153
	}
129
	/**
130
	 * Classid for persitence
154

  
155
	/*
156
	 * (non-Javadoc)
157
	 * @see com.iver.utiles.IPersistance#getXMLEntity()
131 158
	 */
132
	public static final String CLASSID_VALUE ="Publication";
133
	/**
134
	 * TODO: docu
135
	 */
136 159
	public XMLEntity getXMLEntity() {
137 160
		XMLEntity xml=new XMLEntity();
138 161
		//put version and name		
......
140 163
		xml.putProperty("version", getVersion());
141 164
		//put properties
142 165
		xml.putProperty("title", getTitle());
143
		//TODO: check if getserver() is null
144
		xml.addChild(getServer().getXMLEntity());
166
		xml.putProperty("accessfilemethod", getAccessFileMethod());
167
		xml.putProperty("localmountpoint", getLocalMountPoint());
168
		xml.putProperty("remotemountpoint", getRemoteMountPoint());
169
		
170
		if (getServer() != null){
171
			xml.addChild(getServer().getXMLEntity());
172
		}
145 173
		return xml;
146 174
	}
147
	/**
148
	 * TODO: Only gets the first server!!
149
	 * @param xml
175
	/*
176
	 * (non-Javadoc)
177
	 * @see com.iver.utiles.IPersistance#setXMLEntity(com.iver.utiles.XMLEntity)
150 178
	 */
151 179
	public void setXMLEntity(XMLEntity xml) {
152 180
		//check version
......
154 182
		if (version != getVersion()){
155 183
			PublishLogger.getLog().error("ERROR: " + getVersion() + ": the version doesn't match!");
156 184
			return;
157
		}	
158
		//creates only the first server
159
		XMLEntity xmlChild=xml.getChild(0);		
160
		String server_type = xmlChild.getStringProperty("registertag");
161
		Server s = PublishRegister.register().getServer(server_type);		
162
		if (s==null){			
163
			PublishLogger.getLog().error("ERROR " + getVersion()+ ": I can't create the server from persistence");
164
		}else{
165
			s.setProjectInfo(iproject);			
166
			s.setXMLEntity(xmlChild);
167
			setServer(s);
168
		}				
185
		}
186
		//set properties		
187
		setAccessFileMethod(xml.getIntProperty("accessfilemethod"));
188
		setLocalMountPoint(xml.getStringProperty("localmountpoint"));
189
		setRemoteMountPoint(xml.getStringProperty("remotemountpoint"));
190
		//creates only the first server if exists
191
		if (xml.getChildrenCount() > 0){
192
			XMLEntity xmlChild=xml.getChild(0);		
193
			String server_type = xmlChild.getStringProperty("registertag");
194
			Server s = PublishRegister.register().getServer(server_type);		
195
			if (s==null){			
196
				PublishLogger.getLog().error("ERROR " + getVersion()+ ": I can't create the server from persistence");
197
			}else{
198
				s.setProjectInfo(iproject);			
199
				s.setXMLEntity(xmlChild);
200
				setServer(s);
201
			}	
202
		}
203
						
169 204
	}
170 205
	/*
171 206
	 * (non-Javadoc)
172 207
	 * @see com.iver.utiles.IPersistance#getClassName()
173 208
	 */
174 209
	public String getClassName() {		
175
		return "Publication";
210
		return "Publication_v1";
176 211
	}
177 212
	/*
178 213
	 * (non-Javadoc)
179 214
	 * @see org.gvsig.publish.IPublishPersistence#getVersion()
180 215
	 */
181 216
	public int getVersion() {
182

  
183 217
		return 1;
184 218
	}
219
	/**
220
	 * Gets the method in which the publication has been set. 
221
	 * It can be Publication.LOCAL_ACCESS or Publication.REMOTE_MOUNT_POINT_ACCESS <p>
222
	 * LOCAL_ACCESS: the files to publish are located in the local filesystem. <br>
223
	 * REMOTE_MOUNT_POINT_ACCESS: the files are located in remote filesystem but are accessible through a remote mount point  
224
	 * 
225
	 * @return the accessFileMethod
226
	 */
227
	public int getAccessFileMethod() {
228
		return accessFileMethod;
229
	}
230
	/**
231
	 * Sets the method in which the files are been accessed. It can be Publication.LOCAL_ACCESS or Publication.REMOTE_MOUNT_POINT_ACCESS.
232
	 * LOCAL_ACCESS: the files to publish are located in the local filesystem. <br>
233
	 * REMOTE_MOUNT_POINT_ACCESS: the files are located in remote filesystem but are accessible through a remote mount point   
234
	 * @param accessFileMethod the accessFileMethod to set
235
	 */
236
	public void setAccessFileMethod(int accessFileMethod) {		
237
		this.accessFileMethod = accessFileMethod;
238
//		if (accessFileMethod == LOCAL_ACCESS){
239
//			setLocalMountPoint(null);
240
//			setRemoteMountPoint(null);
241
//		}
242
		setChanged();
243
	}
244
	
245
	/**
246
	 * If the publication uses a REMOTE_MOUNT_POINT_ACCESS, this method change the path to a file in order
247
	 * to be accessible by a server. 
248
	 * 
249
	 * @return 
250
	 */
251
	public String getServerSideFilePath(IDataSourceInfo ds){
252
		if (getAccessFileMethod() == REMOTE_MOUNT_POINT_ACCESS){
253
			String aux = ((IFileInfo)ds).getAbsolutePath();
254
			return aux.replace(localMountPoint, remoteMountPoint);
255
		}else{	
256
			return  ((IFileInfo)ds).getAbsolutePath();
257
		}
258
	}
259
	/**
260
	 * @param localMountPoint the localMountPoint to set
261
	 */
262
	public void setLocalMountPoint(String localMountPoint) {				
263
		this.localMountPoint = localMountPoint;
264
		setChanged();	
265
	}
266
	/**
267
	 * @param remoteMountPoint the remoteMountPoint to set
268
	 */
269
	public void setRemoteMountPoint(String remoteMountPoint) {				
270
		this.remoteMountPoint = remoteMountPoint;
271
		setChanged();
272
	}
273
	/**
274
	 * @return the localMountPoint
275
	 */
276
	public String getLocalMountPoint() {
277
		return localMountPoint;
278
	}
279
	/**
280
	 * @return the remoteMountPoint
281
	 */
282
	public String getRemoteMountPoint() {
283
		return remoteMountPoint;
284
	}
185 285
}

Also available in: Unified diff