Revision 27477 trunk/extensions/extRasterTools-SE/src/org/gvsig/fmap/raster/layers/FLyrRasterSE.java

View differences:

FLyrRasterSE.java
33 33
import java.lang.reflect.InvocationTargetException;
34 34
import java.util.ArrayList;
35 35
import java.util.HashMap;
36
import java.util.Hashtable;
36 37

  
37 38
import javax.print.attribute.PrintRequestAttributeSet;
38 39
import javax.swing.ImageIcon;
39 40

  
40 41
import org.cresques.cts.IProjection;
41 42
import org.gvsig.fmap.raster.legend.ColorTableLegend;
43
import org.gvsig.raster.FileNotFoundSolve;
42 44
import org.gvsig.raster.RasterLibrary;
43 45
import org.gvsig.raster.buffer.BufferFactory;
44 46
import org.gvsig.raster.dataset.CompositeDataset;
......
141 143
	static private IConfiguration configuration       = new DefaultLayerConfiguration();
142 144
	
143 145
	private BufferedImage         image               = null;
146
	private static Hashtable<Class, ISolveErrorListener> 
147
	                              solveListeners      = new Hashtable<Class, ISolveErrorListener>();
144 148

  
145 149
	/**
146 150
	 * Tipo de valor no data asociado a la capa.
......
158 162

  
159 163
	static {
160 164
		 RasterLibrary.wakeUp();
165
		 //TODO: Problema de dependencia entre appgvSIG y libFMap. La resoluci?n de errores en la ruta de las capas deber?a ser un mecanismo general.
166
		 FLyrRasterSE.addSolveErrorForLayer(NotSupportedExtensionException.class, new FileNotFoundSolve());
161 167
	}
162 168

  
163 169
	/**
......
180 186
		return capa;
181 187
	}
182 188

  
189
	private static FLyrRasterSE tryToSolveError(Exception e, FLayer layer) {
190
		ISolveErrorListener sel = solveListeners.get(e.getClass());
191
		if (sel != null) {
192
			FLyrRasterSE solvedLayer = null;
193
			solvedLayer = (FLyrRasterSE)sel.solve(layer, null);
194
			if (solvedLayer != null && sel != null){
195
				return solvedLayer;
196
			}
197
		}
198
		layer.setAvailable(false);
199
		return (FLyrRasterSE)layer;
200
	}
201
	
183 202
	/**
203
	 * A?ade un gestor de errores en la carga de la capa
204
	 * @param exception
205
	 * @param sel
206
	 */
207
	public static void addSolveErrorForLayer(Class exception, ISolveErrorListener sel) {
208
		solveListeners.put(exception, sel);
209
	}
210
	
211
	/**
184 212
	 * Asigna los par?metros para la carga de la capa
185 213
	 * @param param Par?metros.
186 214
	 */
......
290 318
				} else
291 319
					dataset = MultiRasterDataset.open(getProjection(), params);
292 320
		} catch (NotSupportedExtensionException e) {
293
			throw new LoadLayerException("Formato no valido", e);
321
			FLyrRasterSE lyr = tryToSolveError(e, this);
322
			if(lyr != null)
323
				dataset = lyr.getDataSource();
324
			else
325
				throw new LoadLayerException("Formato no valido", e);
294 326
		} catch (MosaicNotValidException e) {
295 327
			throw new LoadLayerException("Error en el mosaico", e);
296 328
		} catch (Exception e) {
......
920 952
	 */
921 953
	public void setXMLEntity(XMLEntity xml) throws XMLException {
922 954
		super.setXMLEntity(xml);
923

  
955
		
924 956
		try {
925 957
			params = new File(xml.getStringProperty("file"));
926 958

  

Also available in: Unified diff