Clover coverage report - Code Coverage for tapestry release 4.0-beta-10
Coverage timestamp: Sat Oct 8 2005 19:08:05 EDT
file stats: LOC: 72   Methods: 4
NCLOC: 37   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ComponentAddressAdaptor.java 83.3% 93.3% 100% 92%
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 org.apache.hivemind.ApplicationRuntimeException;
 18    import org.apache.tapestry.Tapestry;
 19    import org.apache.tapestry.services.DataSqueezer;
 20    import org.apache.tapestry.util.ComponentAddress;
 21   
 22    /**
 23    * Squeezes a org.apache.tapestry.ComponentAddress.
 24    *
 25    * @author mindbridge
 26    * @since 2.2
 27    */
 28   
 29    public class ComponentAddressAdaptor implements SqueezeAdaptor
 30    {
 31    private static final String PREFIX = "A";
 32   
 33    private static final char SEPARATOR = ',';
 34   
 35  37 public String getPrefix()
 36    {
 37  37 return PREFIX;
 38    }
 39   
 40  37 public Class getDataClass()
 41    {
 42  37 return ComponentAddress.class;
 43    }
 44   
 45  2 public String squeeze(DataSqueezer squeezer, Object data)
 46    {
 47  2 ComponentAddress address = (ComponentAddress) data;
 48   
 49    // a 'null' id path is encoded as an empty string
 50  2 String idPath = address.getIdPath();
 51  2 if (idPath == null)
 52  1 idPath = "";
 53   
 54  2 return PREFIX + address.getPageName() + SEPARATOR + idPath;
 55    }
 56   
 57  2 public Object unsqueeze(DataSqueezer squeezer, String string)
 58    {
 59  2 int separator = string.indexOf(SEPARATOR);
 60  2 if (separator < 0)
 61  0 throw new ApplicationRuntimeException(Tapestry
 62    .getMessage("ComponentAddressAdaptor.no-separator"));
 63   
 64  2 String pageName = string.substring(1, separator);
 65  2 String idPath = string.substring(separator + 1);
 66  2 if (idPath.equals(""))
 67  1 idPath = null;
 68   
 69  2 return new ComponentAddress(pageName, idPath);
 70    }
 71   
 72    }