KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > util > compression > CompressionHelper


1 /*
2  * $Id: CompressionHelper.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.util.compression;
12
13 import org.apache.commons.logging.Log;
14 import org.apache.commons.logging.LogFactory;
15 import org.mule.util.ClassUtils;
16
17 import java.security.AccessController JavaDoc;
18 import java.security.PrivilegedAction JavaDoc;
19
20 /**
21  * <code>CompressionHelper</code> a static class that provides facilities for
22  * compressing and uncompressing byte arrays
23  *
24  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
25  * @version $Revision: 3798 $
26  */

27
28 public class CompressionHelper
29 {
30     /**
31      * logger used by this class
32      */

33     private static Log logger = LogFactory.getLog(CompressionHelper.class);
34
35     private static CompressionStrategy defaultStrategy;
36
37     synchronized public static CompressionStrategy getDefaultCompressionStrategy()
38     {
39         if (defaultStrategy == null)
40         {
41             defaultStrategy = (CompressionStrategy)AccessController.doPrivileged(new PrivilegedAction JavaDoc()
42             {
43                 public Object JavaDoc run()
44                 {
45                     try
46                     {
47                         Object JavaDoc o = ClassUtils.loadClass(CompressionStrategy.COMPRESSION_DEFAULT,
48                             CompressionHelper.class).newInstance();
49                         if (logger.isDebugEnabled())
50                         {
51                             logger.debug("Found CompressionStrategy: " + o.getClass().getName());
52                         }
53                         return o;
54                     }
55                     catch (Exception JavaDoc e)
56                     {
57                         logger.warn("Failed to build compression strategy: " + e.getMessage());
58                     }
59                     return null;
60                 }
61             });
62         }
63         return defaultStrategy;
64     }
65
66 }
67
Popular Tags