Coverage Report - org.trails.io.ClassAdaptor
 
Classes in this File Line Coverage Branch Coverage Complexity
ClassAdaptor
69% 
100% 
2.25
 
 1  
 package org.trails.io;
 2  
 
 3  
 import org.apache.commons.logging.Log;
 4  
 import org.apache.commons.logging.LogFactory;
 5  
 import org.apache.tapestry.services.DataSqueezer;
 6  
 import org.apache.tapestry.util.io.SqueezeAdaptor;
 7  
 import org.trails.exception.TrailsRuntimeException;
 8  
 import org.trails.util.Utils;
 9  
 
 10  
 /**
 11  
  * Squeezes a {@link Class}
 12  
  */
 13  28
 public class ClassAdaptor implements SqueezeAdaptor
 14  
 {
 15  
 
 16  4
         private static final Log LOG = LogFactory.getLog(ClassAdaptor.class);
 17  
 
 18  
         public static final String PREFIX = "D";
 19  
 
 20  
         public Class getDataClass()
 21  
         {
 22  8
                 return Class.class;
 23  
         }
 24  
 
 25  
         public String getPrefix()
 26  
         {
 27  8
                 return PREFIX;
 28  
         }
 29  
 
 30  
         public String squeeze(DataSqueezer squeezer, Object object)
 31  
         {
 32  8
                 if (LOG.isDebugEnabled())
 33  
                 {
 34  0
                         LOG.debug("squeezing: " + object.toString());
 35  
                 }
 36  
 
 37  
 
 38  8
                 return PREFIX + ((Class) object).getName();
 39  
         }
 40  
 
 41  
         public Object unsqueeze(DataSqueezer squeezer, String string)
 42  
         {
 43  8
                 if (LOG.isDebugEnabled())
 44  
                 {
 45  0
                         LOG.debug("unsqueezing: " + string);
 46  
                 }
 47  
 
 48  8
                 final String className = string.substring(PREFIX.length());
 49  
 
 50  
                 try
 51  
                 {
 52  8
                         return Utils.classForName(className);
 53  
 
 54  0
                 } catch (TrailsRuntimeException cnfe)
 55  
                 {
 56  0
                         throw new TrailsRuntimeException("decode-failure", cnfe);
 57  
                 }
 58  
         }
 59  
 }