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