KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > equinox > launcher > JNIBridge


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.equinox.launcher;
12
13
14 /**
15  * <b>Note:</b> This class should not be referenced programmatically by
16  * other Java code. This class exists only for the purpose of interacting with
17  * a native launcher. To launch Eclipse programmatically, use
18  * org.eclipse.core.runtime.adaptor.EclipseStarter. This class is not API.
19  */

20 public class JNIBridge {
21     //TODO: This class should not be public
22
private native void _set_exit_data(String JavaDoc sharedId, String JavaDoc data);
23     private native void _update_splash();
24     private native long _get_splash_handle();
25     private native void _show_splash(String JavaDoc bitmap);
26     private native void _takedown_splash();
27     
28     private native int OleInitialize(int reserved);
29     private native void OleUninitialize();
30     
31     private String JavaDoc library;
32     private boolean libraryLoaded = false;
33     public JNIBridge(String JavaDoc library) {
34         this.library = library;
35     }
36     
37     private void loadLibrary() {
38         if (library != null) {
39             try {
40                 if (library.indexOf("wpf") != -1) { //$NON-NLS-1$
41
int idx = library.indexOf("eclipse_"); //$NON-NLS-1$
42
if (idx != -1) {
43                         String JavaDoc comLibrary = library.substring(0, idx) + "com_"; //$NON-NLS-1$
44
comLibrary += library.substring(idx + 8, library.length());
45                         Runtime.getRuntime().load(comLibrary);
46                         OleInitialize(0);
47                     }
48                 }
49                 Runtime.getRuntime().load(library);
50             } catch (UnsatisfiedLinkError JavaDoc e) {
51                 //failed
52
}
53         }
54         libraryLoaded = true;
55     }
56
57     public boolean setExitData(String JavaDoc sharedId, String JavaDoc data) {
58         try {
59             _set_exit_data(sharedId, data);
60             return true;
61         } catch (UnsatisfiedLinkError JavaDoc e) {
62             if(!libraryLoaded){
63                 loadLibrary();
64                 return setExitData(sharedId, data);
65             }
66             return false;
67         }
68     }
69
70     public boolean showSplash(String JavaDoc bitmap) {
71         try {
72             _show_splash(bitmap);
73             return true;
74         } catch (UnsatisfiedLinkError JavaDoc e) {
75             if(!libraryLoaded){
76                 loadLibrary();
77                 return showSplash(bitmap);
78             }
79             return false;
80         }
81     }
82     
83     public boolean updateSplash() {
84         try {
85             _update_splash();
86             return true;
87         } catch (UnsatisfiedLinkError JavaDoc e) {
88             if(!libraryLoaded){
89                 loadLibrary();
90                 return updateSplash();
91             }
92             return false;
93         }
94     }
95
96     public long getSplashHandle() {
97         try {
98             return _get_splash_handle();
99         } catch (UnsatisfiedLinkError JavaDoc e) {
100             if(!libraryLoaded){
101                 loadLibrary();
102                 return getSplashHandle();
103             }
104             return -1;
105         }
106     }
107     
108     public boolean takeDownSplash() {
109         try {
110             _takedown_splash();
111             return true;
112         } catch (UnsatisfiedLinkError JavaDoc e) {
113             if(!libraryLoaded){
114                 loadLibrary();
115                 return takeDownSplash();
116             }
117             return false;
118         }
119     }
120     
121     public boolean uninitialize() {
122         if (libraryLoaded && library != null) {
123             if (library.indexOf("wpf") != -1) { //$NON-NLS-1$
124
try {
125                     OleUninitialize();
126                 } catch (UnsatisfiedLinkError JavaDoc e) {
127                     // library not loaded
128
return false;
129                 }
130             }
131         }
132         return true;
133     }
134 }
135
Popular Tags