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