Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libjni-gdal / src / main / java / org / gvsig / jogr / JNIBase.java @ 27485

History | View | Annotate | Download (7.26 KB)

1
/**********************************************************************
2
 * $Id: JNIBase.java 7765 2006-10-03 07:05:18Z nacho $
3
 *
4
 * Name:     JNIBase.java
5
 * Project:  JGDAL. Interfaz java to gdal (Frank Warmerdam).
6
 * Purpose:  Base class for classes that use JNI.
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

    
28
/**
29
 * @author Nacho Brodin <brodin_ign@gva.es>.<BR> Equipo de desarrollo gvSIG.<BR> http://www.gvsig.gva.es
30
 * @version 0.0
31
 * @link http://www.gvsig.gva.es
32
 */
33

    
34
package org.gvsig.jogr;
35

    
36

    
37

    
38
public class JNIBase{
39
        
40
        protected long cPtr;
41
        
42

    
43
        private native int getDriverCountNat(long cPtr);
44
        private native int getLayerCountNat(long cPtr);
45
        private native int getFeatureCountNat(long cPtr);
46
        private native int getFieldCountNat(long cPtr);
47
        private native int getWidthNat(long cPtr);
48
        private native int getPrecisionNat(long cPtr);
49
        
50
        private native int referenceNat(long cPtr);
51
        private native int dereferenceNat(long cPtr);
52
        private native int getRefCountNat(long cPtr);
53
        private native int getSummaryRefCountNat(long cPtr);
54
        
55
        private native int referenceFeatureDefnNat(long cPtr);
56
        private native int dereferenceFeatureDefnNat(long cPtr);
57
        private native int getReferenceCountNat(long cPtr);
58
        
59
        private native int getFieldCountFeatureNat(long cPtr);
60
        
61
        //private native int syncToDiskNat(long cPtr);//Excepciones
62
        //private native int startTransactionNat(long cPtr);//Excepciones
63
        //private native int commitTransactionNat(long cPtr);//Excepciones
64
        //private native int rollbackTransactionNat(long cPtr);//Excepciones
65
        private native int referenceLayerNat(long cPtr);
66
        private native int dereferenceLayerNat(long cPtr);
67
        private native int getRefCountLayerNat(long cPtr);
68
        
69
        private native int getOpenDSCountNat(long cPtr);
70
        
71
        //Geometry
72
        private native int getDimensionNat( long cPtr);
73
        private native int isSimpleNat( long cPtr );
74
        private native int wkbSizeNat( long cPtr );
75
        
76
        //Point
77
        private native int isEmptyPointNat( long cPtr ); //return OGRBoolean
78
        private native int getCoordinateDimensionPointNat( long cPtr );
79
        
80
        //Line String
81
        private native int isEmptyLineStringNat( long cPtr ); //return OGRBoolean
82
        private native int getCoordinateDimensionLineStringNat( long cPtr );
83
        private native int getNumPointsNat( long cPtr );
84
        
85
        //Linear Ring
86
        private native int isClockwiseNat(long cPtr);
87
        private native int WkbSizeNat(long cPtr);
88
        
89
        //Polygon
90
        private native int getNumInteriorRingsNat( long cPtr );
91
        private native int wkbSizePolygonNat( long cPtr );
92
        private native int getDimensionPolygonNat( long cPtr );
93
        private native int getCoordinateDimensionNat( long cPtr );
94
        
95
        //GeometryCollection
96
        private native int getDimensionGeometryCollectionNat( long cPtr );
97
        private native int getCoordinateDimensionGeometryCollectionNat( long cPtr );
98
        
99
         /**
100
         * Funci?n que sirve como base para funcionalidades de ogr que admiten como par?metro un long y devuelven un entero.
101
         * 
102
         * @throws OGRException.
103
         * @param msg1        Mensaje de error que se muestra cuando el puntero a objeto pasado es vacio.
104
         * @param msg2        Mensaje de error que se muestra cuando el resultado de la llamada a la funci?n de gdal es menor o igual que 0.
105
         */
106
         
107
         
108
        protected int baseSimpleFunctions(int n,String msg1,String msg2)throws OGRException{
109
                        
110
                int res = 0;
111
                if(cPtr <= 0)
112
                        throw new OGRException(msg1);
113
                        
114
                switch(n){
115
                        case 0: res = getDriverCountNat(cPtr);break;
116
                        case 1: res = getLayerCountNat(cPtr);break;
117
                        case 2: res = getFeatureCountNat(cPtr);break;
118
                        case 3: res = getFieldCountNat(cPtr);break;
119
                        case 4: res = getWidthNat(cPtr);break;
120
                        case 5: res = getPrecisionNat(cPtr);break;
121
                        case 6: res = referenceNat(cPtr);break;
122
                        case 7: res = dereferenceNat(cPtr);break;
123
                        case 8: res = getRefCountNat(cPtr);break;
124
                        case 9: res = getSummaryRefCountNat(cPtr);break;
125
                        case 10: res = referenceFeatureDefnNat(cPtr);break;
126
                        case 11: res = dereferenceFeatureDefnNat(cPtr);break;
127
                        case 12: res = getReferenceCountNat(cPtr);break;
128
                        case 13: res = getFieldCountFeatureNat(cPtr);break;
129
                        //case 14: res = syncToDiskNat(cPtr);break;//Excepciones
130
                        //case 15: res = startTransactionNat( cPtr);break;//Excepciones
131
                        //case 16: res = commitTransactionNat( cPtr);break;//Excepciones
132
                        //case 17: res = rollbackTransactionNat( cPtr);break;//Excepciones
133
                        case 18: res = referenceLayerNat( cPtr);break;
134
                        case 19: res = dereferenceLayerNat( cPtr);break;
135
                        case 20: res = getRefCountLayerNat( cPtr);break;
136
                        case 21: res = getOpenDSCountNat(cPtr);break;
137
                        case 22: res = getDimensionNat(cPtr);break;
138
                        case 23: res = isSimpleNat(cPtr );break;
139
                        case 24: res = wkbSizeNat(cPtr );break;
140
                        case 25: res = isEmptyPointNat( cPtr );break; //return OGRBoolean
141
                        case 26: res = getCoordinateDimensionPointNat( cPtr );break;
142
                        case 27: res = getNumPointsNat( cPtr );break;
143
                        case 28: res = isEmptyLineStringNat( cPtr );break; //return OGRBoolean
144
                        case 29: res = getCoordinateDimensionLineStringNat( cPtr );break;
145
                        case 30: res = isClockwiseNat(cPtr);break;
146
                        case 31: res = WkbSizeNat(cPtr);break;
147
                        case 32: res = getNumInteriorRingsNat( cPtr );break;
148
                        case 33: res = wkbSizeNat( cPtr );break;
149
                        case 34: res = getDimensionNat( cPtr );break;
150
                        case 35: res = getCoordinateDimensionNat( cPtr );break;
151
                }
152
                        
153
                if(res<0)
154
                         throw new OGRException(msg2);
155
                else return res;
156
        }
157
        
158
        /**
159
         * Lanza una excepci?n dependiendo del tipo de error pasado
160
         * @param err
161
         * @param mensaje
162
         * @throws OGRCorruptDataException
163
         * @throws OGRFailureException
164
         * @throws OGRNotEnoughDataException
165
         * @throws OGRNotEnoughMemoryException
166
         * @throws OGRUnsupportedGeometryTypeException
167
         * @throws OGRUnsupportedOperationException
168
         * @throws OGRUnsupportedSRSException
169
         */
170
        protected void throwException(int err, String mensaje)
171
                throws OGRCorruptDataException, OGRFailureException, OGRNotEnoughDataException, OGRNotEnoughMemoryException, OGRUnsupportedGeometryTypeException, OGRUnsupportedOperationException, OGRUnsupportedSRSException{
172
                
173
                switch(err){
174
                        case 1:throw new OGRNotEnoughDataException(mensaje);
175
                        case 2:throw new OGRNotEnoughMemoryException(mensaje);
176
                        case 3:throw new OGRUnsupportedGeometryTypeException(mensaje);
177
                        case 4:throw new OGRUnsupportedOperationException(mensaje);
178
                        case 5:throw new OGRCorruptDataException(mensaje);
179
                        case 6:throw new OGRFailureException(mensaje);
180
                        case 7:throw new OGRUnsupportedSRSException(mensaje);
181
                        default : return;
182
                }
183
        }
184
        
185
        /**
186
         * Obtiene el puntero a C del objeto
187
         * @param cPtr long con la direcci?n de memoria del objeto
188
         */
189
        public long getPtro() {
190
                return cPtr;
191
        }
192

    
193
        static {
194
                System.loadLibrary("jgdal2.0.0");
195
        }
196
}