Revision 22616 branches/v10/extensions/extPublishGeoserver/src/org/gvsig/publish/geoserver/model/GeoserverFeature.java

View differences:

GeoserverFeature.java
47 47
import java.net.URL;
48 48

  
49 49
import org.gvsig.publish.PublishLogger;
50
import org.gvsig.publish.exceptions.LayerInfoNotAvailableException;
51 50
import org.gvsig.publish.exceptions.PublishException;
52 51
import org.gvsig.publish.geoserver.conf.GSDatastore;
53 52
import org.gvsig.publish.geoserver.conf.GSFeature;
......
76 75
	private String namespacePrefix =null;
77 76
	public static final String REGISTER_TAG="geoserver_feature";
78 77
	private boolean cacheEnabled=true;
79
    private int cacheMaxage=3600;
80
    private int numDecimals=0;
81
    
78
	private int cacheMaxage=3600;
79
	private int numDecimals=0;
80

  
82 81
	/**
83 82
	 * constructor
84 83
	 * @param service
......
93 92
	 * Also overrides the method in order to avoid the creation of nested resources 
94 93
	 * @see org.gvsig.publish.serversmodel.RemoteResource#setLayerInfo(org.gvsig.publish.infoproject.ILayerInfo)
95 94
	 */
96
	
95

  
97 96
	public void setLayerInfo(ILayerInfo ilayer) {
98 97
		super.setLayerInfo(ilayer);
99
		try {
100
			setNamespacePrefix(getLayerInfo().getDataSource().getNamespacePrefix());
101
			setName(getFeatureTypeName());
102
			setTitle(getLayerInfo().getTitle());
103
			setAbstract("generated by gvSIG");
104
		} catch (LayerInfoNotAvailableException e) {
105
			PublishLogger.getLog().error("ERROR " + getClassName() + " :Cannot initialize the Remote resurce" , e);
106
		}
107
		
98
		setNamespacePrefix(getLayerInfo().getDataSource().getNamespacePrefix());
99
		setName(getFeatureTypeName());
100
		setTitle(getLayerInfo().getTitle());
101
		setAbstract("generated by gvSIG");
108 102
	}
109 103
	/**
110 104
	 * 
111 105
	 * @return feature name in Geoserver. It's the filename without extension for files or tablename for databases
112
	 * @throws LayerInfoNotAvailableException 
106
	 * 
113 107
	 */
114
	private String getFeatureTypeName() throws LayerInfoNotAvailableException{
108
	private String getFeatureTypeName() {
115 109
		String aux="unknowfeature";
116 110
		IDataSourceInfo ds = getLayerInfo().getDataSource();
117 111
		if (ds instanceof IFileInfo){
......
132 126
	public String getClassName() {		
133 127
		return "GeoserverFeature";
134 128
	}
135
		
129

  
136 130
	/**
137 131
	 * 
138 132
	 * @see org.gvsig.publish.serversmodel.RemoteResource#publish()
139 133
	 */
140 134
	public void publish() throws PublishException{		
141
		//adds this feature to the server configuration
142
		try {
143
			addFeatureToConfig();
144
		} catch (LayerInfoNotAvailableException e) {			
145
			remove();
146
			throw new PublishException("publish_infolayer_not_available");			
147
		}
135
		//adds this feature to the server configuration		
136
		addFeatureToConfig(); 
148 137
		//adds its childs to the server configuration
149 138
		super.publish();
150 139
	}
151 140
	/**
152 141
	 * Adds this remote resource into the server configuration
153
	 * @throws PublishException 
154
	 * @throws LayerInfoNotAvailableException 
142
	 * @throws PublishException  
155 143
	 */
156
	private void addFeatureToConfig() throws PublishException, LayerInfoNotAvailableException {
144
	private void addFeatureToConfig() throws PublishException{
157 145
		GSFeature config = new GSFeature(this);
158 146
		//create namespace
159 147
		GSNamespace ns = create_namespace();
......
165 153
		config.setDatastore(ds);
166 154
		config.setNamespace(ns);
167 155
		config.setStyle(st);
168
		
156

  
169 157
		//adds feature
170 158
		Geoserver server= (Geoserver) getService().getServer();
171
		
159

  
172 160
		boolean isadded = server.getConfiguration().addFeatureType(config);
173 161
		if (isadded == false && getLayerInfo().getDataSource().getType()==IDataSourceInfo.SHAPE_TYPE){
174 162
			PublishLogger.getLog().error("ERROR GeoserverFeature: cannot add a feature because you can't have two features with the same shapefile in the same namespace");
......
195 183
	 * 
196 184
	 * @param ns
197 185
	 * @return
198
	 * @throws LayerInfoNotAvailableException 
199 186
	 */
200
	private GSDatastore create_datastore(GSFeature feature, GSNamespace ns) throws LayerInfoNotAvailableException{
187
	private GSDatastore create_datastore(GSFeature feature, GSNamespace ns) {
201 188
		GSDatastore ds = new GSDatastore();
202 189
		ds.setNamespace(ns);
203 190
		IDataSourceInfo dataSrc = getLayerInfo().getDataSource();		
......
209 196
		}
210 197
		return ds;
211 198
	}
212
	
213
	private void config_datastore_postgis(GSFeature feature, GSDatastore ds) throws LayerInfoNotAvailableException {
199
	/**
200
	 * Creates the datastore configuration for Geoserver
201
	 * 
202
	 * @param feature
203
	 * @param ds
204
	 */
205
	private void config_datastore_postgis(GSFeature feature, GSDatastore ds) {
214 206
		String ds_id  = ((IDataBaseInfo)getLayerInfo().getDataSource()).getConnectionName();
215 207
		ds_id  = ds_id + "_" + ((IDataBaseInfo)getLayerInfo().getDataSource()).getSchemaName();
216 208
		ds.setId(ds_id);
......
228 220
		String id = getLayerInfo().getDataSource().getNamespacePrefix() + "_" + ((IDataBaseInfo)getLayerInfo().getDataSource()).getTableName();
229 221
		feature.setId(id);
230 222
	}
231
	private void config_datastore_shape(GSFeature feature, GSDatastore ds) throws LayerInfoNotAvailableException {
232
		
223
	/**
224
	 * Creates the datastore configuration for Geoserver
225
	 * @param feature
226
	 * @param ds
227
	 * 
228
	 */
229
	private void config_datastore_shape(GSFeature feature, GSDatastore ds) {
230

  
233 231
		ds.setId(((IFileInfo)getLayerInfo().getDataSource()).getFilenameWithoutExtension());
234 232
		//TODO: get this from IDatasourceInfo
235 233
		ds.setCharset("UTF-8");		
......
245 243
		feature.setId(id);
246 244
	}
247 245
	/**
246
	 * Creates the style configuration for Geoserver 
248 247
	 * 
249 248
	 * @return
250
	 * @throws LayerInfoNotAvailableException 
249
	 * 
251 250
	 */
252
	private GSStyle create_style() throws LayerInfoNotAvailableException{
251
	private GSStyle create_style(){
253 252
		//create style
254 253
		GSStyle st = new GSStyle();
255 254
		st.setId(getId());
......
258 257
		}
259 258
		return st;
260 259
	}
261
	
260

  
262 261
	/*
263 262
	 * (non-Javadoc)
264 263
	 * @see org.gvsig.publish.serversmodel.RemoteResource#getRegisterTag()
265 264
	 */
266 265
	public String getRegisterTag() {
267
		
266

  
268 267
		return REGISTER_TAG;
269 268
	}
270 269
	/*
......
272 271
	 * @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#getAbstract()
273 272
	 */
274 273
	public String getAbstract() {
275
		
274

  
276 275
		return ogcMetadata.getAbstract();
277 276
	}
278 277
	/*
......
280 279
	 * @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#getName()
281 280
	 */
282 281
	public String getName() {
283
		
282

  
284 283
		return ogcMetadata.getName();
285 284
	}
286 285
	/*
......
288 287
	 * @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#getTitle()
289 288
	 */
290 289
	public String getTitle() {
291
		
290

  
292 291
		return ogcMetadata.getTitle();
293 292
	}
294 293
	/*
......
304 303
	 */
305 304
	public void setName(String name) {
306 305
		ogcMetadata.setName(name);
307
		
306

  
308 307
	}
309 308
	/*
310 309
	 * (non-Javadoc)
......
324 323
	 * (non-Javadoc)
325 324
	 * @see java.lang.Object#toString()
326 325
	 */
327
    public String toString(){
328
    	return getTitle();
329
    }
330
    /* (non-Javadoc)
326
	public String toString(){
327
		return getTitle();
328
	}
329
	/* (non-Javadoc)
331 330
	 * @see org.gvsig.publish.serversmodel.RemoteResource#getXMLEntity()
332 331
	 */
333
	
332

  
334 333
	public XMLEntity getXMLEntity() {
335 334
		XMLEntity xml=super.getXMLEntity();
336 335
		//put version and name
......
351 350
	/* (non-Javadoc)
352 351
	 * @see org.gvsig.publish.serversmodel.RemoteResource#setXMLEntity(com.iver.utiles.XMLEntity)
353 352
	 */
354
	
353

  
355 354
	public void setXMLEntity(XMLEntity xml) {
356 355
		//check version
357 356
		int version = xml.getIntProperty("version");
......
368 367
		setCacheEnabled(xml.getBooleanProperty("is_cached"));
369 368
		setCacheMaxage(xml.getIntProperty("cache_maxage"));
370 369
	}
371
	
370

  
372 371
	/**
373 372
	 * @return the cacheEnabled
374 373
	 */
......
424 423
	public void setNamespacePrefix(String namespacePrefix) {
425 424
		this.namespacePrefix = namespacePrefix;
426 425
	}
427
		
426

  
428 427
}

Also available in: Unified diff