1
2
3
4
5
6
7
8
9
10
11 package org.mule.module.launcher;
12
13 import org.mule.api.MuleContext;
14
15
16
17
18
19
20
21 public class ApplicationWrapper implements Application
22 {
23
24 private Application delegate;
25
26 public ApplicationWrapper(Application delegate)
27 {
28 this.delegate = delegate;
29 }
30
31 public void dispose()
32 {
33 final ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
34 try
35 {
36 ClassLoader appCl = getDeploymentClassLoader();
37
38 if (appCl != null)
39 {
40 Thread.currentThread().setContextClassLoader(appCl);
41 }
42 delegate.dispose();
43 if (appCl != null)
44 {
45
46 if (appCl instanceof GoodCitizenClassLoader)
47 {
48 GoodCitizenClassLoader classLoader = (GoodCitizenClassLoader) appCl;
49 classLoader.close();
50 }
51 }
52 }
53 finally
54 {
55 Thread.currentThread().setContextClassLoader(originalCl);
56 }
57 }
58
59 public ClassLoader getDeploymentClassLoader()
60 {
61 return delegate.getDeploymentClassLoader();
62 }
63
64 public MuleContext getMuleContext()
65 {
66 return delegate.getMuleContext();
67 }
68
69 public void init()
70 {
71 final ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
72 try
73 {
74 ClassLoader appCl = getDeploymentClassLoader();
75
76 if (appCl != null)
77 {
78 Thread.currentThread().setContextClassLoader(appCl);
79 }
80 delegate.init();
81 }
82 finally
83 {
84 Thread.currentThread().setContextClassLoader(originalCl);
85 }
86 }
87
88 public void install() throws InstallException
89 {
90 final ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
91 try
92 {
93 ClassLoader appCl = getDeploymentClassLoader();
94
95 if (appCl != null)
96 {
97 Thread.currentThread().setContextClassLoader(appCl);
98 }
99 delegate.install();
100 }
101 finally
102 {
103 Thread.currentThread().setContextClassLoader(originalCl);
104 }
105 }
106
107 public void redeploy()
108 {
109 delegate.redeploy();
110 }
111
112 public void start() throws DeploymentStartException
113 {
114 final ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
115 try
116 {
117 ClassLoader appCl = getDeploymentClassLoader();
118
119 if (appCl != null)
120 {
121 Thread.currentThread().setContextClassLoader(appCl);
122 }
123 delegate.start();
124 }
125 finally
126 {
127 Thread.currentThread().setContextClassLoader(originalCl);
128 }
129 }
130
131 public void stop()
132 {
133 final ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
134 try
135 {
136 ClassLoader appCl = getDeploymentClassLoader();
137
138 if (appCl != null)
139 {
140 Thread.currentThread().setContextClassLoader(appCl);
141 }
142 delegate.stop();
143 }
144 finally
145 {
146 Thread.currentThread().setContextClassLoader(originalCl);
147 }
148 }
149
150 public String getAppName()
151 {
152 return delegate.getAppName();
153 }
154
155 @Override
156 public String toString()
157 {
158 return String.format("%s(%s)@%s", getClass().getName(),
159 delegate,
160 Integer.toHexString(System.identityHashCode(this)));
161
162 }
163 }