Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libjni-gdal / src / es / gva / cit / jogr / OGRSFDriverRegistrar.java @ 945

History | View | Annotate | Download (3.14 KB)

1
/**********************************************************************
2
 * $Id: OGRSFDriverRegistrar.java 945 2005-01-12 18:05:23Z igbrotru $
3
 *
4
 * Name:     OGRSFDriverRegistrar.java
5
 * Project:  JGDAL. Interface java to gdal (Frank Warmerdam).
6
 * Purpose:   
7
 * Author:   Nacho Brodin, brodin_ign@gva.es
8
 *
9
 **********************************************************************/
10
/*Copyright (C) 2004  Nacho Brodin <brodin_ign@gva.es>
11

12
 This program is free software; you can redistribute it and/or
13
 modify it under the terms of the GNU General Public License
14
 as published by the Free Software Foundation; either version 2
15
 of the License, or (at your option) any later version.
16

17
 This program is distributed in the hope that it will be useful,
18
 but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 GNU General Public License for more details.
21

22
 You should have received a copy of the GNU General Public License
23
 along with this program; if not, write to the Free Software
24
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
 */
26

    
27
package es.gva.cit.jogr;
28

    
29

    
30
/** 
31
 * Gestor de drivers
32
 * 
33
 * @author Nacho Brodin <brodin_ign@gva.es>.<BR> Equipo de desarrollo gvSIG.<BR> http://www.gvsig.gva.es
34
 * @version 0.0
35
 * @link http://www.gvsig.gva.es
36
 */
37

    
38
public class OGRSFDriverRegistrar extends JNIBase{
39
        
40
        private long driver;
41
        public native long openNat(String fte, int bUpdate);
42
        public native long getRegistrarNat();
43
        public native long getDriverNat(long cPtr, int i);
44
        private native void FreeOGRSFDriverRegistrarNat(long cPtr);
45
        
46
        /**
47
         * Abre un fichero de im?gen
48
         * @throws OGRException
49
         * @param fte        fichero fuente
50
         * @param bUpdate
51
         * @param pdriver
52
         * @return OGRDataSource
53
         */
54
        
55
        public OGRDataSource open(String fte, boolean bUpdate, OGRSFDriver pdriver)throws OGRException{
56
                
57
                OGRDataSource ds;
58
                OGRSFDriver drv;
59
                driver=-1;
60
                int bU=0;
61
                
62
                if(bUpdate)bU=1;
63
                
64
                long res = openNat(fte, bU);
65
                                
66
                if(res<=0 || driver<=0)
67
                        throw new OGRException("Error en open(). No se ha podido abrir la im?gen.");
68
                else{
69
                        ds = new OGRDataSource(res);
70
                        drv = new OGRSFDriver(driver);
71
                }
72
                
73
                pdriver=drv;                
74
                return ds;
75
        }
76
        
77
        /**
78
         * Obtiene el n?mero de drivers registrados en el gestor
79
         * @throws OGRException
80
         * @return N?mero de drivers
81
         */
82
        
83
         public int getDriverCount()throws OGRException{
84
                
85
                 if(cPtr<=0)cPtr=getRegistrarNat();
86
                         
87
                String msg1="Error en getDriverCount. . La llamada getRegistrar de OGR no tuvo exito";
88
                String msg2="Error en la cuenta de drivers";
89
                return baseSimpleFunctions(0,msg1,msg2);
90
         }
91
         
92
         /**
93
         * Obtiene el driver indicado por el ?ndice
94
         * @throws OGRException
95
         * @return un driver
96
         */
97
                
98
         public OGRSFDriver getDriver(int i)throws OGRException{
99
                        
100
                 if(cPtr<=0)cPtr=getRegistrarNat();
101
                 if(cPtr <= 0)
102
                        throw new OGRException("Error en getDriver(). La llamada getRegistrar() no tuvo exito");
103
                            
104
                long drv = getDriverNat(cPtr, i);
105
                
106
                if(drv<=0)
107
                        throw new OGRException("Error en getDriver(). No se ha podido obtener el driver indicado.");
108
                                        
109
                return new OGRSFDriver(drv);
110
                
111
         }
112
         
113
        /**
114
        * Destructor 
115
        */
116
                
117
        protected void finalize(){
118
                if(cPtr > 0)
119
                        FreeOGRSFDriverRegistrarNat(cPtr);
120
        }
121
}