1 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 ; 18 import java.security.PrivilegedAction ; 19 20 27 28 public class CompressionHelper 29 { 30 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 () 42 { 43 public Object run() 44 { 45 try 46 { 47 Object 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 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 |