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