1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.modules.boot; |
12 | |
|
13 | |
import org.mule.MuleServer; |
14 | |
import org.mule.util.ClassUtils; |
15 | |
import org.mule.util.SystemUtils; |
16 | |
|
17 | |
import java.lang.reflect.Method; |
18 | |
import java.net.URL; |
19 | |
|
20 | |
import org.tanukisoftware.wrapper.WrapperSimpleApp; |
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
public class ReflectionHelper |
31 | |
{ |
32 | |
|
33 | |
|
34 | |
private ReflectionHelper() |
35 | 0 | { |
36 | |
|
37 | 0 | } |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
public static URL getResource(final String resourceName, final Class callingClass) throws Exception |
45 | |
{ |
46 | 0 | Class clazz = ClassUtils.class; |
47 | 0 | Method m = clazz.getMethod("getResource", new Class[] {String.class, Class.class}); |
48 | 0 | Object result = m.invoke(null, new Object[] { resourceName, callingClass}); |
49 | 0 | return (URL) result; |
50 | |
} |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
public static boolean isClassOnPath(String className, Class currentClass) throws Exception |
59 | |
{ |
60 | 0 | Class clazz = ClassUtils.class; |
61 | 0 | Method m = clazz.getMethod("isClassOnPath", new Class[] {String.class, Class.class}); |
62 | 0 | Object result = m.invoke(null, new Object[] { className, currentClass}); |
63 | 0 | return ((Boolean) result).booleanValue(); |
64 | |
} |
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
public static String[][] getCliOptions() throws Exception |
71 | |
{ |
72 | 0 | return (String[][]) MuleServer.class.getField("CLI_OPTIONS").get(null); |
73 | |
} |
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
public static String getCommandLineOption(String option, String args[], String opts[][]) throws Exception |
79 | |
{ |
80 | 0 | Class clazz = SystemUtils.class; |
81 | 0 | Method m = clazz.getMethod("getCommandLineOption", new Class[] {String.class, String[].class, String[][].class}); |
82 | 0 | Object result = m.invoke(null, new Object[] { option, args, opts}); |
83 | 0 | return (String) result; |
84 | |
} |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
public static void wrapperMain(String[] args) throws Exception |
90 | |
{ |
91 | 0 | Class clazz = WrapperSimpleApp.class; |
92 | 0 | Method m = clazz.getMethod("main", new Class[] {String[].class}); |
93 | 0 | m.invoke(null, new Object[] {args}); |
94 | 0 | } |
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
public static void wrapperStop(int exitCode) throws Exception |
100 | |
{ |
101 | 0 | Class clazz = WrapperSimpleApp.class; |
102 | 0 | Method m = clazz.getMethod("stop", new Class[] {int.class}); |
103 | 0 | m.invoke(null, new Object[] {new Integer(exitCode)}); |
104 | 0 | } |
105 | |
|
106 | |
} |