1 | class JavahAdapterFactory {↵ | | 1 | class Native2AsciiAdapterFactory {↵
|
|
2 | /**↵ | | 2 | /**↵
|
3 | * Determines the default choice of adapter based on the VM↵ | | 3 | * Determines the default choice of adapter based on the VM↵
|
4 | * vendor.↵ | | 4 | * vendor.↵
|
5 | *↵ | | 5 | *↵
|
6 | * @return the default choice of adapter based on the VM↵ | | 6 | * @return the default choice of adapter based on the VM↵
|
7 | * vendor↵ | | 7 | * vendor↵
|
8 | */↵ | | 8 | */↵
|
9 | public static String getDefault() {↵ | | 9 | public static String getDefault() {↵
|
10 | if (JavaEnvUtils.isKaffe()) {↵ | | 10 | if (JavaEnvUtils.isKaffe()) {↵
|
11 | return Kaffeh.IMPLEMENTATION_NAME;↵ | | 11 | return KaffeNative2Ascii.IMPLEMENTATION_NAME;↵
|
12 | }↵ | | 12 | }↵
|
13 | return SunJavah.IMPLEMENTATION_NAME;↵ | | 13 | return SunNative2Ascii.IMPLEMENTATION_NAME;↵
|
14 | }↵ | | 14 | }↵
|
|
15 | /**↵ | | 15 | /**↵
|
16 | * Creates the JavahAdapter based on the user choice and↵ | | 16 | * Creates the Native2AsciiAdapter based on the user choice and *↵
|
17 | * potentially the VM vendor.↵ | | 17 | * potentially the VM vendor.↵
|
18 | *↵ | | 18 | *↵
|
19 | * @param choice the user choice (if any).↵ | | 19 | * @param choice the user choice (if any).↵
|
20 | * @param log a ProjectComponent instance used to access Ant's↵ | | 20 | * @param log a ProjectComponent instance used to access Ant's↵
|
21 | * logging system.↵ | | 21 | * logging system.↵
|
22 | * @return The adapter to use.↵ | | 22 | * @return The adapter to use.↵
|
23 | * @throws BuildException if there is an error.↵ | | 23 | * @throws BuildException if there was a problem.↵
|
24 | */↵ | | 24 | */↵
|
25 | public static JavahAdapter getAdapter(String choice,↵ | | 25 | public static Native2AsciiAdapter getAdapter(String choice,↵
|
26 | ProjectComponent log)↵ | | 26 | ProjectComponent log)↵
|
27 | throws BuildException {↵ | | 27 | throws BuildException {↵
|
28 | if ((JavaEnvUtils.isKaffe() && choice == null)↵ | | 28 | if ((JavaEnvUtils.isKaffe() && choice == null)↵
|
29 | || Kaffeh.IMPLEMENTATION_NAME.equals(choice)) {↵ | | 29 | || KaffeNative2Ascii.IMPLEMENTATION_NAME.equals(choice)) {↵
|
30 | return new Kaffeh();↵ | | 30 | return new KaffeNative2Ascii();↵
|
31 | } else if (SunJavah.IMPLEMENTATION_NAME.equals(choice)) {↵ | | 31 | } else if (SunNative2Ascii.IMPLEMENTATION_NAME.equals(choice)) {↵
|
32 | return new SunJavah();↵ | | 32 | return new SunNative2Ascii();↵
|
33 | } else if (choice != null) {↵ | | 33 | } else if (choice != null) {↵
|
34 | return resolveClassName(choice);↵ | | 34 | return resolveClassName(choice);↵
|
35 | }↵ | | 35 | }↵
|
|
36 | // This default has been good enough until Ant 1.6.3, so stick↵ | | 36 | // This default has been good enough until Ant 1.6.3, so stick↵
|
37 | // with it↵ | | 37 | // with it↵
|
38 | return new SunJavah();↵ | | 38 | return new SunNative2Ascii();↵
|
39 | }↵ | | 39 | }↵
|
|
40 | /**↵ | | 40 | /**↵
|
41 | * Tries to resolve the given classname into a javah adapter.↵ | | 41 | * Tries to resolve the given classname into a native2ascii adapter.↵
|
42 | * Throws a fit if it can't.↵ | | 42 | * Throws a fit if it can't.↵
|
43 | *↵ | | 43 | *↵
|
44 | * @param className The fully qualified classname to be created.↵ | | 44 | * @param className The fully qualified classname to be created.↵
|
45 | * @throws BuildException This is the fit that is thrown if className↵ | | 45 | * @throws BuildException This is the fit that is thrown if className↵
|
46 | * isn't an instance of JavahAdapter.↵ | | 46 | * isn't an instance of Native2AsciiAdapter.↵
|
47 | */↵ | | 47 | */↵
|
48 | private static JavahAdapter resolveClassName(String className)↵ | | 48 | private static Native2AsciiAdapter resolveClassName(String className)↵
|
49 | throws BuildException {↵ | | 49 | throws BuildException {↵
|
50 | return (JavahAdapter) ClasspathUtils.newInstance(className,↵ | | 50 | return (Native2AsciiAdapter) ClasspathUtils.newInstance(className,↵
|
51 | JavahAdapterFactory.class.getClassLoader(), Javah↵ | | 51 | Native2AsciiAdapterFactory.class.getClassLoader(),↵
|
52 | Adapter.class);↵ | | 52 | Native2AsciiAdapter.class);↵
|
53 | } | | 53 | }
|