Clover coverage report - Code Coverage for tapestry release 4.0-alpha-3
Coverage timestamp: Mon May 16 2005 09:05:49 EDT
file stats: LOC: 66   Methods: 3
NCLOC: 34   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
EnumAdaptor.java - 90% 100% 92.3%
coverage coverage
 1   
 // Copyright 2004, 2005 The Apache Software Foundation
 2   
 //
 3   
 // Licensed under the Apache License, Version 2.0 (the "License");
 4   
 // you may not use this file except in compliance with the License.
 5   
 // You may obtain a copy of the License at
 6   
 //
 7   
 //     http://www.apache.org/licenses/LICENSE-2.0
 8   
 //
 9   
 // Unless required by applicable law or agreed to in writing, software
 10   
 // distributed under the License is distributed on an "AS IS" BASIS,
 11   
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12   
 // See the License for the specific language governing permissions and
 13   
 // limitations under the License.
 14   
 
 15   
 package org.apache.tapestry.util.io;
 16   
 
 17   
 import java.io.IOException;
 18   
 
 19   
 import org.apache.commons.lang.enum.Enum;
 20   
 import org.apache.commons.lang.enum.EnumUtils;
 21   
 import org.apache.tapestry.services.DataSqueezer;
 22   
 
 23   
 /**
 24   
  *  Adaptor for {@link Enum} classes.
 25   
  *
 26   
  *  @author Howard Lewis Ship
 27   
  *  @since 3.0
 28   
  *
 29   
  **/
 30   
 public class EnumAdaptor implements ISqueezeAdaptor
 31   
 {
 32   
     private static final String PREFIX = "E";
 33   
     private static final char SEPARATOR = '@';
 34   
 
 35  1
     public String squeeze(DataSqueezer squeezer, Object o) throws IOException
 36   
     {
 37  1
         Enum e = (Enum) o;
 38  1
         return PREFIX + e.getClass().getName() + SEPARATOR + e.getName();
 39   
     }
 40   
 
 41  1
     public Object unsqueeze(DataSqueezer squeezer, String str) throws IOException
 42   
     {
 43  1
         int pos = str.indexOf(SEPARATOR);
 44   
 
 45  1
         String className = str.substring(1, pos);
 46  1
         String name = str.substring(pos + 1, str.length());
 47   
 
 48  1
         Class enumClass = squeezer.getResolver().findClass(className);
 49   
         
 50  1
         try
 51   
         {            
 52  1
             return EnumUtils.getEnum(enumClass, name);
 53   
         }
 54   
         catch (IllegalArgumentException ex)
 55   
         {
 56  0
             throw new IOException(ex.getMessage());
 57   
         }
 58   
     }
 59   
 
 60  34
     public void register(DataSqueezer squeezer)
 61   
     {
 62  34
         squeezer.register(PREFIX, Enum.class, this);
 63   
     }
 64   
 
 65   
 }
 66