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