Statistics
| Revision:

root / trunk / libraries / libRaster / src / org / gvsig / raster / buffer / cache / CacheDataFromDriverServer.java @ 11081

History | View | Annotate | Download (3.68 KB)

1

    
2
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
 *
4
 * Copyright (C) 2006 IVER T.I. and Generalitat Valenciana.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 */
20
package org.gvsig.raster.buffer.cache;
21

    
22
import java.io.File;
23
import java.io.FileNotFoundException;
24
import java.io.IOException;
25

    
26
import org.gvsig.raster.dataset.Band;
27
import org.gvsig.raster.dataset.BandFoundInListException;
28
import org.gvsig.raster.dataset.BandList;
29
import org.gvsig.raster.dataset.NotSupportedExtensionException;
30
import org.gvsig.raster.dataset.RasterDataset;
31
import org.gvsig.raster.dataset.RasterDriverException;
32
import org.gvsig.raster.shared.Extent;
33

    
34

    
35
/** 
36
 * Servidor de datos de cach?. Esta clase es la encargada de recuperar las p?ginas
37
 * cuando le son solicitadas. Implementar? el interfaz ICacheDataSource, aunque esta
38
 * clase se encargar? de servir p?ginas de solo lectura. Las p?ginas son servidas directamente desde
39
 * un RasterDataset y un objeto de este tipo representa a una sola p?gina, por lo que tendr? asociado
40
 * el extent correspondiente al trozo de p?gina que sirve.
41
 * 
42
 * @author Nacho Brodin (nachobrodin@gmail.com)
43
 *
44
 */
45
public class CacheDataFromDriverServer implements ICacheDataSource{
46
        
47
        private int                                        numPag = -1;
48
        private RasterDataset                        dataset = null;
49
        private Extent                                        pageExtent = null; 
50
        
51
        /**
52
         * Constructor. 
53
         * Crea el identificador para todos los trozos de cach? que se guardar?n en disco. 
54
         * @param id Identificador de fichero. Si este es null se calcula uno autom?ticamente
55
         * @param numBand N?mero de banda
56
         * @param numPag N?mero de p?gina
57
         * @throws RasterDriverException 
58
         * @throws NotSupportedExtensionException 
59
         */
60
        public CacheDataFromDriverServer(RasterDataset dataset, int numPag, Extent extent) {
61
                this.numPag = numPag;
62
                this.dataset = dataset;
63
                pageExtent = extent;
64
        }
65

    
66
        /* (non-Javadoc)
67
         * @see org.gvsig.fmap.dataaccess.cache.ICacheDataSource#loadPage(int, org.gvsig.fmap.dataaccess.cache.PageBuffer)
68
         */
69
        public void loadPage(PageBandBuffer pageBuffer) {
70
                //Creamos un BandList con todas las bandas del fichero
71
                BandList bandList = new BandList();
72
                for(int i = 0; i < dataset.getBandCount();i++){
73
                        try{
74
                                Band band = new Band(dataset.getFName(), i, dataset.getDataType());
75
                                bandList.addBand(band, i);
76
                        }catch(BandFoundInListException ex){
77
                                //No a?adimos la banda
78
                        }
79
                }
80
                dataset.getWindowRaster(pageExtent.getMin().getX(), pageExtent.getMax().getY(), pageExtent.width(), pageExtent.height(), bandList, pageBuffer, true);
81
        }
82

    
83
        /* (non-Javadoc)
84
         * @see org.gvsig.fmap.dataaccess.cache.ICacheDataSource#savePage(int, org.gvsig.fmap.dataaccess.cache.PageBuffer)
85
         */
86
        public void savePage(PageBandBuffer pageBuffer) throws IOException {
87
                //Read Only                
88
        }
89

    
90
        /*
91
         * (non-Javadoc)
92
         * @see org.gvsig.raster.dataaccess.cache.ICacheDataSource#delete()
93
         */
94
        public void delete() {
95
                //Read Only
96
        }
97
        
98
        /*
99
         *  (non-Javadoc)
100
         * @see org.gvsig.raster.dataaccess.cache.ICacheDataSource#getPath()
101
         */
102
        public String getPath() {
103
                if(dataset != null)
104
                        return dataset.getFName();
105
                return null;
106
        }
107
}
108