Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libCq CMS for java.old / src-ermapper / com / ermapper / ecw / JNCSFile.java @ 143

History | View | Annotate | Download (19.7 KB)

1
// Decompiled by Jad v1.5.8f. Copyright 2001 Pavel Kouznetsov.
2
// Jad home page: http://www.kpdus.com/jad.html
3
// Decompiler options: packimports(3) 
4
// Source File Name:   JNCSFile.java
5

    
6
package com.ermapper.ecw;
7

    
8
import com.ermapper.util.JNCSDatasetPoint;
9
import com.ermapper.util.JNCSWorldPoint;
10
import java.io.FileInputStream;
11
import java.io.PrintStream;
12
import java.lang.reflect.Field;
13
import java.lang.reflect.Method;
14
import java.util.Properties;
15

    
16
// Referenced classes of package com.ermapper.ecw:
17
//            JNCSNativeLibraryException, JNCSFileOpenFailedException, JNCSInvalidSetViewException, JNCSException, 
18
//            JNCSFileNotOpenException, JNCSProgressiveUpdate
19

    
20
public class JNCSFile
21
    implements JNCSProgressiveUpdate
22
{
23

    
24
    private native int ECWOpen(String s, boolean flag);
25

    
26
    private native void ECWClose(boolean flag);
27

    
28
    private native int ECWSetView(int i, int ai[], int j, int k, int l, int i1, double d, double d1, double d2, double d3, 
29
            int j1, int k1);
30

    
31
    private native int ECWReadLineRGBA(int ai[]);
32

    
33
    private native int ECWReadImageRGBA(int ai[], int i, int j);
34

    
35
    private native short ECWGetPercentComplete();
36

    
37
    private static native String ECWGetErrorString(int i);
38

    
39
    private static native int NCSJNIInit();
40

    
41
    private static native String ECWGetLibVersion();
42

    
43
    static void initClass()
44
        throws JNCSNativeLibraryException
45
    {
46
        boolean flag = false;
47
        boolean flag1 = false;
48
        if(bHaveClassInit)
49
            return;
50
        if(System.getSecurityManager() != null)
51
        {
52
            Object obj = null;
53
            String s3 = System.getProperty("java.vendor");
54
            if(s3.startsWith("Netscape Communications Corporation"))
55
                try
56
                {
57
                    Class class1 = Class.forName("netscape.security.PrivilegeManager");
58
                    Class aclass[] = {
59
                        java.lang.String.class
60
                    };
61
                    Method method = class1.getMethod("enablePrivilege", aclass);
62
                    Object obj1 = class1.newInstance();
63
                    Object aobj[] = {
64
                        new String("UniversalLinkAccess")
65
                    };
66
                    Object aobj1[] = {
67
                        new String("UniversalPropertyRead")
68
                    };
69
                    method.invoke(obj1, aobj);
70
                    method.invoke(obj1, aobj1);
71
                }
72
                catch(NoSuchMethodException nosuchmethodexception)
73
                {
74
                    System.out.println("GetMethod : ".concat(String.valueOf(String.valueOf(nosuchmethodexception.getMessage()))));
75
                }
76
                catch(ClassNotFoundException classnotfoundexception)
77
                {
78
                    System.out.println("ClassNotFoundException : ".concat(String.valueOf(String.valueOf(classnotfoundexception.getMessage()))));
79
                }
80
                catch(Exception exception4)
81
                {
82
                    System.out.println("Netscape Privilige Manager Access Exception : ".concat(String.valueOf(String.valueOf(exception4.getMessage()))));
83
                }
84
            else
85
            if(s3.startsWith("Microsoft Corp."))
86
                try
87
                {
88
                    Class class2 = Class.forName("com.ms.security.PolicyEngine");
89
                    Class class3 = Class.forName("com.ms.security.PermissionID");
90
                    Field field = class3.getField("SYSTEM");
91
                    Field field1 = class3.getField("FILEIO");
92
                    Class aclass1[] = {
93
                        class3
94
                    };
95
                    Method method1 = class2.getMethod("assertPermission", aclass1);
96
                    Object aobj2[] = {
97
                        field.get(null)
98
                    };
99
                    Object aobj3[] = {
100
                        field1.get(null)
101
                    };
102
                    method1.invoke(null, aobj2);
103
                    method1.invoke(null, aobj3);
104
                }
105
                catch(NoSuchMethodException nosuchmethodexception1)
106
                {
107
                    System.out.println("Microsoft Policy Engine NoSuchMethodException : ".concat(String.valueOf(String.valueOf(nosuchmethodexception1.getMessage()))));
108
                }
109
                catch(SecurityException securityexception2)
110
                {
111
                    System.out.println("Microsoft Policy Engine SecurityException : ".concat(String.valueOf(String.valueOf(securityexception2.getMessage()))));
112
                }
113
                catch(Exception exception5)
114
                {
115
                    System.out.println("Microsoft Policy Engine Exception : ".concat(String.valueOf(String.valueOf(exception5.getMessage()))));
116
                }
117
        } else
118
        {
119
            flag1 = true;
120
        }
121
        try
122
        {
123
            System.loadLibrary("NCSUtil");
124
            System.loadLibrary("NCScnet");
125
            System.loadLibrary("NCSEcw");
126
            bUseNativeMethods = true;
127
            bUnsatisfiedLink = false;
128
        }
129
        catch(UnsatisfiedLinkError unsatisfiedlinkerror)
130
        {
131
            bUseNativeMethods = false;
132
            bUnsatisfiedLink = true;
133
            bUseNativeMethods = false;
134
            debug("Got UnsatisfiedLinkError looking on PATH");
135
        }
136
        catch(SecurityException securityexception)
137
        {
138
            bSecurityError = true;
139
            bUseNativeMethods = false;
140
            bUnsatisfiedLink = false;
141
            debug("Got SecurityException looking on PATH");
142
        }
143
        catch(Exception exception)
144
        {
145
            System.err.println("Unknown error loading ECW native libraries : ".concat(String.valueOf(String.valueOf(exception.getMessage()))));
146
            bUseNativeMethods = false;
147
            debug("Got Exception looking on PATH");
148
        }
149
        if(bUseNativeMethods)
150
            try
151
            {
152
                int i = NCSJNIInit();
153
                if(i != 0)
154
                {
155
                    System.err.println("JNCSFile classes found on PATH failed to initialize correctly. Attempting to locate other NCS dlls....");
156
                } else
157
                {
158
                    bHaveClassInit = true;
159
                    return;
160
                }
161
            }
162
            catch(UnsatisfiedLinkError unsatisfiedlinkerror1)
163
            {
164
                debug("Native ECW libraries have been found on the PATH, but could not be loaded. This may be because the version is insufficient to support the Java classes.\nAt least version 1,5,2,0 is required. Attempting to locate other NCS dlls....");
165
            }
166
            catch(Exception exception1)
167
            {
168
                debug("Unknown exception occured initialising ECW native libraries found on the PATH.".concat(String.valueOf(String.valueOf(exception1.getMessage()))));
169
            }
170
        if(flag1 && !bUseNativeMethods && !bSecurityError && System.getSecurityManager() != null)
171
        {
172
            Properties properties = new Properties();
173
            String s4 = null;
174
            String s5 = null;
175
            try
176
            {
177
                String s6 = System.getProperty("user.home");
178
                s5 = System.getProperty("file.separator");
179
                FileInputStream fileinputstream = new FileInputStream(String.valueOf(String.valueOf((new StringBuffer(String.valueOf(String.valueOf(s6)))).append(s5).append("jncsclasses.properties"))));
180
                properties.load(fileinputstream);
181
                s4 = properties.getProperty("clientDLLPath");
182
            }
183
            catch(Exception exception6)
184
            {
185
                s4 = null;
186
            }
187
            try
188
            {
189
                if(s4 != null)
190
                {
191
                    System.load(String.valueOf(String.valueOf((new StringBuffer(String.valueOf(String.valueOf(s4)))).append(s5).append("NCSUtil.dll"))));
192
                    System.load(String.valueOf(String.valueOf((new StringBuffer(String.valueOf(String.valueOf(s4)))).append(s5).append("NCScnet.dll"))));
193
                    System.load(String.valueOf(String.valueOf((new StringBuffer(String.valueOf(String.valueOf(s4)))).append(s5).append("NCSEcw.dll"))));
194
                    bUseNativeMethods = true;
195
                    bUnsatisfiedLink = false;
196
                    bSecurityError = false;
197
                }
198
            }
199
            catch(SecurityException securityexception3)
200
            {
201
                bSecurityError = true;
202
                bUseNativeMethods = false;
203
                bUnsatisfiedLink = false;
204
                debug("Got security exception looking on clientDLLPath");
205
            }
206
            catch(RuntimeException runtimeexception1)
207
            {
208
                System.out.println(runtimeexception1.getMessage());
209
                bUseNativeMethods = false;
210
                bUnsatisfiedLink = true;
211
                debug("Got RuntimeException looking on clientDLLPath");
212
            }
213
            catch(UnsatisfiedLinkError unsatisfiedlinkerror4)
214
            {
215
                bUseNativeMethods = false;
216
                bUnsatisfiedLink = true;
217
                debug("Got UnsatisfiedLinkError looking on clientDLLPath");
218
            }
219
            catch(Exception exception7)
220
            {
221
                System.out.println(exception7.getMessage());
222
                bUseNativeMethods = false;
223
                bUnsatisfiedLink = true;
224
                debug("Got Exception looking on clientDLLPath");
225
            }
226
        }
227
        if(!bUseNativeMethods && !bSecurityError)
228
            try
229
            {
230
                System.load("C:\\Program Files\\Earth Resource Mapping\\Image Web Server\\Client\\NCSUtil.dll");
231
                System.load("C:\\Program Files\\Earth Resource Mapping\\Image Web Server\\Client\\NCScnet.dll");
232
                System.load("C:\\Program Files\\Earth Resource Mapping\\Image Web Server\\Client\\NCSEcw.dll");
233
                bUseNativeMethods = true;
234
                bUnsatisfiedLink = false;
235
                bSecurityError = false;
236
                debug("Loaded ECW libraries in C:\\Program Files\\...");
237
            }
238
            catch(SecurityException securityexception1)
239
            {
240
                bSecurityError = true;
241
                bUseNativeMethods = false;
242
                bUnsatisfiedLink = false;
243
                debug("Got security exception looking on C:\\Program Files\\");
244
            }
245
            catch(RuntimeException runtimeexception)
246
            {
247
                System.out.println(runtimeexception.getMessage());
248
                bUseNativeMethods = false;
249
                bUnsatisfiedLink = true;
250
                debug("Got RuntimeException looking on C:\\Program Files\\");
251
            }
252
            catch(UnsatisfiedLinkError unsatisfiedlinkerror2)
253
            {
254
                bUseNativeMethods = false;
255
                bUnsatisfiedLink = true;
256
                debug("Got UnsatisfiedLinkError looking on C:\\Program Files\\");
257
            }
258
            catch(Exception exception2)
259
            {
260
                System.out.println(exception2.getMessage());
261
                bUseNativeMethods = false;
262
                bUnsatisfiedLink = true;
263
                debug("Got Exception looking on C:\\Program Files\\");
264
            }
265
        if(bUseNativeMethods)
266
            try
267
            {
268
                int j = NCSJNIInit();
269
                if(j != 0)
270
                {
271
                    System.err.println("JNCSFile classes failed to initialize correctly. Unrecoverable error.");
272
                    String s = ECWGetErrorString(j);
273
                    throw new JNCSNativeLibraryException(s);
274
                }
275
                bHaveClassInit = true;
276
            }
277
            catch(UnsatisfiedLinkError unsatisfiedlinkerror3)
278
            {
279
                debug("UnsatisfiedLinkError: ".concat(String.valueOf(String.valueOf(unsatisfiedlinkerror3.getMessage()))));
280
                throw new JNCSNativeLibraryException("Native ECW libraries have been found, but could not be loaded. This may be because the version is insufficient to support the Java classes.\nAt least version 1,5,2,0 is required.");
281
            }
282
            catch(Exception exception3)
283
            {
284
                debug("Exception: ".concat(String.valueOf(String.valueOf(exception3.getMessage()))));
285
                throw new JNCSNativeLibraryException("Unknown exception occured initialising ECW native libraries.".concat(String.valueOf(String.valueOf(exception3.getMessage()))));
286
            }
287
        if(bSecurityError)
288
        {
289
            String s1 = "The security manager has denied loading of native libraries. Only trusted classes and signed JAR files can access native libraries.";
290
            System.out.println(s1);
291
            throw new JNCSNativeLibraryException(s1);
292
        }
293
        if(bUnsatisfiedLink)
294
        {
295
            String s2 = "JNCSFile class failed to resolve some or all of the native ECW libraries.\nCheck that the NCSUtil, NCSCnet, and NCSUtil shared libraries are on the PATH environment variable (Win32),\nor the LD_LIBRARY_PATH (Unix), or that the parameters to the virtual machine specify their location,\nby setting the property : -Djava.library.path=<path_to_ncs_libraries>\nAlternatively, the file jncsclasses.properties in the user's home directory can specify the location.\n\nRefer to the ECW Java SDK documentation for more information on native library search paths.";
296
            throw new JNCSNativeLibraryException(s2);
297
        } else
298
        {
299
            return;
300
        }
301
    }
302

    
303
    public JNCSFile()
304
        throws JNCSException
305
    {
306
        bSetViewIsWorld = false;
307
        progImageClient = null;
308
        initClass();
309
        cellSizeUnits = 0;
310
        bIsOpen = false;
311
    }
312

    
313
    public JNCSFile(String s, boolean flag)
314
        throws JNCSException
315
    {
316
        bSetViewIsWorld = false;
317
        progImageClient = null;
318
        initClass();
319
        open(s, flag);
320
    }
321

    
322
    protected void finalize()
323
        throws Throwable
324
    {
325
        if(bIsOpen)
326
            ECWClose(false);
327
        super.finalize();
328
    }
329

    
330
    public int open(String s, boolean flag)
331
        throws JNCSFileOpenFailedException
332
    {
333
        if(s == null)
334
            throw new IllegalArgumentException();
335
        int i = ECWOpen(s, flag);
336
        if(i != 0)
337
        {
338
            bIsOpen = false;
339
            String s1 = ECWGetErrorString(i);
340
            throw new JNCSFileOpenFailedException(s1);
341
        } else
342
        {
343
            bIsOpen = true;
344
            progressive = flag;
345
            return 0;
346
        }
347
    }
348

    
349
    public void close(boolean flag)
350
    {
351
        ECWClose(flag);
352
        if(!flag);
353
    }
354

    
355
    public void addProgressiveUpdateListener(JNCSProgressiveUpdate jncsprogressiveupdate)
356
    {
357
        progImageClient = jncsprogressiveupdate;
358
    }
359

    
360
    public void refreshUpdate(int i, int j, double d, double d1, double d2, double d3)
361
    {
362
        if(progImageClient != null)
363
            progImageClient.refreshUpdate(i, j, d, d1, d2, d3);
364
    }
365

    
366
    public void refreshUpdate(int i, int j, int k, int l, int i1, int j1)
367
    {
368
        if(progImageClient != null)
369
            progImageClient.refreshUpdate(i, j, k, l, i1, j1);
370
    }
371

    
372
    public int setView(int i, int ai[], int j, int k, int l, int i1, int j1, 
373
            int k1)
374
        throws JNCSFileNotOpenException, JNCSInvalidSetViewException
375
    {
376
        int l1 = ECWSetView(i, ai, j, k, l, i1, 0.0D, 0.0D, 0.0D, 0.0D, j1, k1);
377
        if(l1 != 0)
378
        {
379
            String s = ECWGetErrorString(l1);
380
            throw new JNCSInvalidSetViewException(s);
381
        } else
382
        {
383
            bSetViewIsWorld = false;
384
            return 0;
385
        }
386
    }
387

    
388
    public int setView(int i, int ai[], double d, double d1, double d2, double d3, int j, int k)
389
        throws JNCSFileNotOpenException, JNCSInvalidSetViewException
390
    {
391
        JNCSDatasetPoint jncsdatasetpoint = convertWorldToDataset(d, d1);
392
        JNCSDatasetPoint jncsdatasetpoint1 = convertWorldToDataset(d2, d3);
393
        int l = ECWSetView(i, ai, jncsdatasetpoint.x, jncsdatasetpoint.y, jncsdatasetpoint1.x, jncsdatasetpoint1.y, d, d1, d2, d3, j, k);
394
        if(l != 0)
395
        {
396
            String s = ECWGetErrorString(l);
397
            throw new JNCSInvalidSetViewException(s);
398
        } else
399
        {
400
            bSetViewIsWorld = true;
401
            return 0;
402
        }
403
    }
404

    
405
    public int readLineRGBA(int ai[])
406
        throws JNCSException
407
    {
408
        int i = ECWReadLineRGBA(ai);
409
        if(i != 0)
410
        {
411
            String s = ECWGetErrorString(i);
412
            throw new JNCSException(s);
413
        } else
414
        {
415
            return 0;
416
        }
417
    }
418

    
419
    public int readLineBGRA(int ai[])
420
        throws JNCSException
421
    {
422
        throw new JNCSException("Not Yet Implemented!");
423
    }
424

    
425
    public int readLineBIL(int ai[])
426
        throws JNCSException
427
    {
428
        throw new JNCSException("Not Yet Implemented!");
429
    }
430

    
431
    public int readLineBIL(double ad[])
432
        throws JNCSException
433
    {
434
        throw new JNCSException("Not Yet Implemented!");
435
    }
436

    
437
    public int readImageRGBA(int ai[], int i, int j)
438
        throws JNCSException
439
    {
440
        int k = ECWReadImageRGBA(ai, i, j);
441
        if(k != 0)
442
        {
443
            String s = ECWGetErrorString(k);
444
            throw new JNCSException(s);
445
        } else
446
        {
447
            return 0;
448
        }
449
    }
450

    
451
    public String getLastErrorText(int i)
452
    {
453
        return ECWGetErrorString(i);
454
    }
455

    
456
    public JNCSDatasetPoint convertWorldToDataset(double d, double d1)
457
        throws JNCSFileNotOpenException
458
    {
459
        int i;
460
        int j;
461
        if(bIsOpen)
462
        {
463
            i = (int)Math.round((d - originX) / cellIncrementX);
464
            j = (int)Math.round((d1 - originY) / cellIncrementY);
465
        } else
466
        {
467
            throw new JNCSFileNotOpenException();
468
        }
469
        return new JNCSDatasetPoint(i, j);
470
    }
471

    
472
    public JNCSWorldPoint convertDatasetToWorld(int i, int j)
473
        throws JNCSFileNotOpenException
474
    {
475
        double d;
476
        double d1;
477
        if(bIsOpen)
478
        {
479
            d = originX + (double)i * cellIncrementX;
480
            d1 = originY + (double)j * cellIncrementY;
481
        } else
482
        {
483
            throw new JNCSFileNotOpenException();
484
        }
485
        return new JNCSWorldPoint(d, d1);
486
    }
487

    
488
    public short getPercentComplete()
489
    {
490
        return ECWGetPercentComplete();
491
    }
492

    
493
    public static String getLibVersion()
494
    {
495
        return ECWGetLibVersion();
496
    }
497

    
498
    private static void debug(String s)
499
    {
500
        if(debug)
501
            System.out.println(s);
502
    }
503

    
504
    private static boolean bUseNativeMethods = false;
505
    private static boolean bSecurityError = false;
506
    private static boolean bUnsatisfiedLink = false;
507
    static boolean bHaveClassInit = false;
508
    static boolean debug = false;
509
    public static final int ECW_CELL_UNITS_INVALID = 0;
510
    public static final int ECW_CELL_UNITS_METERS = 1;
511
    public static final int ECW_CELL_UNITS_DEGREES = 2;
512
    public static final int ECW_CELL_UNITS_FEET = 3;
513
    public int numBands;
514
    public int width;
515
    public int height;
516
    public double originX;
517
    public double originY;
518
    public double cellIncrementX;
519
    public double cellIncrementY;
520
    public int cellSizeUnits;
521
    public double compressionRate;
522
    public boolean progressive;
523
    public String fileName;
524
    public String datum;
525
    public String projection;
526
    public boolean bIsOpen;
527
    private long nativeDataPointer;
528
    private static final boolean doGarbageCollectionOnClose = false;
529
    private static final int ECW_OK = 0;
530
    private int nFileSetViewDatasetTLX;
531
    private int nFileSetViewDatasetTLY;
532
    private int nFileSetViewDatasetBRX;
533
    private int nFileSetViewDatasetBRY;
534
    private int nFileSetViewWidth;
535
    private int nFileSetViewHeight;
536
    private double dFileSetViewWorldTLX;
537
    private double dFileSetViewWorldTLY;
538
    private double dFileSetViewWorldBRX;
539
    private double dFileSetViewWorldBRY;
540
    private boolean bSetViewIsWorld;
541
    protected JNCSProgressiveUpdate progImageClient;
542

    
543
}