Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 932a26ebdc9ed57055402b7cba53c6c2a146ee2f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*******************************************************************************
 * Copyright (c) 2006, 2015 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at 
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     Rapicorp, Inc - Default the configuration to Application Support (bug 461725)
 *******************************************************************************/
package org.eclipse.equinox.launcher;

/**
 * <b>Note:</b> This class should not be referenced programmatically by
 * other Java code. This class exists only for the purpose of interacting with
 * a native launcher. To launch Eclipse programmatically, use 
 * org.eclipse.core.runtime.adaptor.EclipseStarter. This class is not API.
 *
 * @noextend This class is not intended to be subclassed by clients.
 * @noinstantiate This class is not intended to be instantiated by clients.
 */
public class JNIBridge {
	//TODO: This class should not be public
	private native void _set_exit_data(String sharedId, String data);

	private native void _set_launcher_info(String launcher, String name);

	private native void _update_splash();

	private native long _get_splash_handle();

	private native void _show_splash(String bitmap);

	private native void _takedown_splash();

	private native String _get_os_recommended_folder();

	private native int OleInitialize(int reserved);

	private native void OleUninitialize();

	private String library;
	private boolean libraryLoaded = false;

	/**
	 * @noreference This constructor is not intended to be referenced by clients.
	 * 
	 * @param library the given library
	 */
	public JNIBridge(String library) {
		this.library = library;
	}

	private void loadLibrary() {
		if (library != null) {
			try {
				if (library.indexOf("wpf") != -1) { //$NON-NLS-1$
					int idx = library.indexOf("eclipse_"); //$NON-NLS-1$
					if (idx != -1) {
						String comLibrary = library.substring(0, idx) + "com_"; //$NON-NLS-1$
						comLibrary += library.substring(idx + 8, library.length());
						Runtime.getRuntime().load(comLibrary);
						OleInitialize(0);
					}
				}
				Runtime.getRuntime().load(library);
			} catch (UnsatisfiedLinkError e) {
				//failed
			}
		}
		libraryLoaded = true;
	}

	/**
	 * @noreference This method is not intended to be referenced by clients.
	 */
	public boolean setExitData(String sharedId, String data) {
		try {
			_set_exit_data(sharedId, data);
			return true;
		} catch (UnsatisfiedLinkError e) {
			if (!libraryLoaded) {
				loadLibrary();
				return setExitData(sharedId, data);
			}
			return false;
		}
	}

	/**
	 * @noreference This method is not intended to be referenced by clients
	 */
	public boolean setLauncherInfo(String launcher, String name) {
		try {
			_set_launcher_info(launcher, name);
			return true;
		} catch (UnsatisfiedLinkError e) {
			if (!libraryLoaded) {
				loadLibrary();
				return setLauncherInfo(launcher, name);
			}
			return false;
		}
	}

	/**
	 * @noreference This method is not intended to be referenced by clients.
	 */
	public boolean showSplash(String bitmap) {
		try {
			_show_splash(bitmap);
			return true;
		} catch (UnsatisfiedLinkError e) {
			if (!libraryLoaded) {
				loadLibrary();
				return showSplash(bitmap);
			}
			return false;
		}
	}

	/**
	 * @noreference This method is not intended to be referenced by clients.
	 */
	public boolean updateSplash() {
		try {
			_update_splash();
			return true;
		} catch (UnsatisfiedLinkError e) {
			if (!libraryLoaded) {
				loadLibrary();
				return updateSplash();
			}
			return false;
		}
	}

	/**
	 * @noreference This method is not intended to be referenced by clients.
	 */
	public long getSplashHandle() {
		try {
			return _get_splash_handle();
		} catch (UnsatisfiedLinkError e) {
			if (!libraryLoaded) {
				loadLibrary();
				return getSplashHandle();
			}
			return -1;
		}
	}

	/**
	 * Whether or not we loaded the shared library here from java.  
	 * False does not imply the library is not available, it could have
	 * been loaded natively by the executable.
	 * 
	 * @return boolean
	 */
	boolean isLibraryLoadedByJava() {
		return libraryLoaded;
	}

	/**
	 * @noreference This method is not intended to be referenced by clients.
	 */
	public boolean takeDownSplash() {
		try {
			_takedown_splash();
			return true;
		} catch (UnsatisfiedLinkError e) {
			if (!libraryLoaded) {
				loadLibrary();
				return takeDownSplash();
			}
			return false;
		}
	}

	/**
	 * @noreference This method is not intended to be referenced by clients.
	 */
	public boolean uninitialize() {
		if (libraryLoaded && library != null) {
			if (library.indexOf("wpf") != -1) { //$NON-NLS-1$
				try {
					OleUninitialize();
				} catch (UnsatisfiedLinkError e) {
					// library not loaded
					return false;
				}
			}
		}
		return true;
	}

	public String getOSRecommendedFolder() {
		try {
			return _get_os_recommended_folder();
		} catch (UnsatisfiedLinkError e) {
			if (!libraryLoaded) {
				loadLibrary();
				return getOSRecommendedFolder();
			}
			return null;
		}
	}
}

Back to the top