|
1 /******************************************************************************* |
|
2 * Copyright (c) 2000, 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.swt.internal; |
|
12 |
|
13 public class Library { |
|
14 |
|
15 /* SWT Version - Mmmm (M=major, mmm=minor) */ |
|
16 |
|
17 /** |
|
18 * SWT Major version number (must be >= 0) |
|
19 */ |
|
20 static int MAJOR_VERSION = 3; |
|
21 |
|
22 /** |
|
23 * SWT Minor version number (must be in the range 0..999) |
|
24 */ |
|
25 static int MINOR_VERSION = 426; |
|
26 |
|
27 /** |
|
28 * SWT revision number (must be >= 0) |
|
29 */ |
|
30 static int REVISION = 0; |
|
31 |
|
32 /** |
|
33 * The JAVA and SWT versions |
|
34 */ |
|
35 public static final int JAVA_VERSION, SWT_VERSION; |
|
36 |
|
37 static { |
|
38 JAVA_VERSION = parseVersion(System.getProperty("java.version")); |
|
39 SWT_VERSION = SWT_VERSION(MAJOR_VERSION, MINOR_VERSION); |
|
40 } |
|
41 |
|
42 static int parseVersion(String version) { |
|
43 if (version == null) return 0; |
|
44 int major = 0, minor = 0, micro = 0; |
|
45 int length = version.length(), index = 0, start = 0; |
|
46 while (index < length && Character.isDigit(version.charAt(index))) index++; |
|
47 try { |
|
48 if (start < length) major = Integer.parseInt(version.substring(start, index)); |
|
49 } catch (NumberFormatException e) {} |
|
50 start = ++index; |
|
51 while (index < length && Character.isDigit(version.charAt(index))) index++; |
|
52 try { |
|
53 if (start < length) minor = Integer.parseInt(version.substring(start, index)); |
|
54 } catch (NumberFormatException e) {} |
|
55 start = ++index; |
|
56 while (index < length && Character.isDigit(version.charAt(index))) index++; |
|
57 try { |
|
58 if (start < length) micro = Integer.parseInt(version.substring(start, index)); |
|
59 } catch (NumberFormatException e) {} |
|
60 return JAVA_VERSION(major, minor, micro); |
|
61 } |
|
62 |
|
63 /** |
|
64 * Returns the Java version number as an integer. |
|
65 * |
|
66 * @param major |
|
67 * @param minor |
|
68 * @param micro |
|
69 * @return the version |
|
70 */ |
|
71 public static int JAVA_VERSION (int major, int minor, int micro) { |
|
72 return (major << 16) + (minor << 8) + micro; |
|
73 } |
|
74 |
|
75 /** |
|
76 * Returns the SWT version number as an integer. |
|
77 * |
|
78 * @param major |
|
79 * @param minor |
|
80 * @return the version |
|
81 */ |
|
82 public static int SWT_VERSION (int major, int minor) { |
|
83 return major * 1000 + minor; |
|
84 } |
|
85 |
|
86 /** |
|
87 * Loads the shared library that matches the version of the |
|
88 * Java code which is currently running. SWT shared libraries |
|
89 * follow an encoding scheme where the major, minor and revision |
|
90 * numbers are embedded in the library name and this along with |
|
91 * <code>name</code> is used to load the library. If this fails, |
|
92 * <code>name</code> is used in another attempt to load the library, |
|
93 * this time ignoring the SWT version encoding scheme. |
|
94 * |
|
95 * @param name the name of the library to load |
|
96 */ |
|
97 public static void loadLibrary (String name) { |
|
98 loadLibrary (name, true); |
|
99 } |
|
100 |
|
101 /** |
|
102 * Loads the shared library that matches the version of the |
|
103 * Java code which is currently running. SWT shared libraries |
|
104 * follow an encoding scheme where the major, minor and revision |
|
105 * numbers are embedded in the library name and this along with |
|
106 * <code>name</code> is used to load the library. If this fails, |
|
107 * <code>name</code> is used in another attempt to load the library, |
|
108 * this time ignoring the SWT version encoding scheme. |
|
109 * |
|
110 * @param name the name of the library to load |
|
111 * @param mapName true if the name should be mapped, false otherwise |
|
112 */ |
|
113 public static void loadLibrary (String name, boolean mapName) { |
|
114 com.nokia.mj.impl.rt.support.Jvm.loadSystemLibrary(name); |
|
115 } |
|
116 |
|
117 } |