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 {
36
37 }
38
39
40
41
42
43
44 public static URL getResource(final String resourceName, final Class callingClass) throws Exception
45 {
46 Class clazz = ClassUtils.class;
47 Method m = clazz.getMethod("getResource", new Class[] {String.class, Class.class});
48 Object result = m.invoke(null, new Object[] { resourceName, callingClass});
49 return (URL) result;
50 }
51
52
53
54
55
56
57
58 public static boolean isClassOnPath(String className, Class currentClass) throws Exception
59 {
60 Class clazz = ClassUtils.class;
61 Method m = clazz.getMethod("isClassOnPath", new Class[] {String.class, Class.class});
62 Object result = m.invoke(null, new Object[] { className, currentClass});
63 return ((Boolean) result).booleanValue();
64 }
65
66
67
68
69
70 public static String[][] getCliOptions() throws Exception
71 {
72 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 Class clazz = SystemUtils.class;
81 Method m = clazz.getMethod("getCommandLineOption", new Class[] {String.class, String[].class, String[][].class});
82 Object result = m.invoke(null, new Object[] { option, args, opts});
83 return (String) result;
84 }
85
86
87
88
89 public static void wrapperMain(String[] args) throws Exception
90 {
91 Class clazz = WrapperSimpleApp.class;
92 Method m = clazz.getMethod("main", new Class[] {String[].class});
93 m.invoke(null, new Object[] {args});
94 }
95
96
97
98
99 public static void wrapperStop(int exitCode) throws Exception
100 {
101 Class clazz = WrapperSimpleApp.class;
102 Method m = clazz.getMethod("stop", new Class[] {int.class});
103 m.invoke(null, new Object[] {new Integer(exitCode)});
104 }
105
106 }