1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.util.compression; |
12 | |
|
13 | |
import org.mule.util.ClassUtils; |
14 | |
|
15 | |
import java.security.AccessController; |
16 | |
import java.security.PrivilegedAction; |
17 | |
|
18 | |
import org.apache.commons.logging.Log; |
19 | |
import org.apache.commons.logging.LogFactory; |
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | 2 | public final class CompressionHelper |
27 | |
{ |
28 | |
|
29 | |
|
30 | |
|
31 | 2 | private static Log logger = LogFactory.getLog(CompressionHelper.class); |
32 | |
|
33 | |
private static CompressionStrategy defaultStrategy; |
34 | |
|
35 | |
|
36 | |
private CompressionHelper () |
37 | 0 | { |
38 | |
|
39 | 0 | } |
40 | |
|
41 | |
public static synchronized CompressionStrategy getDefaultCompressionStrategy() |
42 | |
{ |
43 | 14 | if (defaultStrategy == null) |
44 | |
{ |
45 | 2 | defaultStrategy = (CompressionStrategy) AccessController.doPrivileged(new PrivilegedAction() |
46 | |
{ |
47 | 2 | public Object run() |
48 | |
{ |
49 | |
try |
50 | |
{ |
51 | 2 | Object o = ClassUtils.loadClass(CompressionStrategy.COMPRESSION_DEFAULT, |
52 | |
CompressionHelper.class).newInstance(); |
53 | 2 | if (logger.isDebugEnabled()) |
54 | |
{ |
55 | 0 | logger.debug("Found CompressionStrategy: " + o.getClass().getName()); |
56 | |
} |
57 | 2 | return o; |
58 | |
} |
59 | 0 | catch (Exception e) |
60 | |
{ |
61 | |
|
62 | 0 | logger.warn("Failed to build compression strategy: " + e.getMessage()); |
63 | |
} |
64 | 0 | return null; |
65 | |
} |
66 | |
}); |
67 | |
} |
68 | 14 | return defaultStrategy; |
69 | |
} |
70 | |
|
71 | |
} |