Clover coverage report - Code Coverage for tapestry release 4.0-beta-2
Coverage timestamp: Sat Jul 9 2005 22:02:17 EDT
file stats: LOC: 154   Methods: 8
NCLOC: 58   Classes: 1
30 day Evaluation License registered to hlship@comcast.net Your 30 day evaluation period has expired. Please visit http://www.cenqua.com to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
ComponentAddress.java 37.5% 52.2% 50% 48.7%
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;
 16   
 17    import java.io.Serializable;
 18   
 19    import org.apache.hivemind.util.Defense;
 20    import org.apache.tapestry.IComponent;
 21    import org.apache.tapestry.INamespace;
 22    import org.apache.tapestry.IPage;
 23    import org.apache.tapestry.IRequestCycle;
 24   
 25    /**
 26    * The ComponentAddress class contains the path to a component, allowing it to locate an instance of
 27    * that component in a different {@link org.apache.tapestry.IRequestCycle}.
 28    * <p>
 29    * This class needs to be used mostly when working with components accessed via the
 30    * {@link org.apache.tapestry.IRender}interface. It allows those components to serialize and pass
 31    * as a service parameter information about what component they have to talk to if control returns
 32    * back to them.
 33    * <p>
 34    * This situation often occurs when the component used via IRender contains Direct or Action links.
 35    *
 36    * @author mindbridge
 37    * @since 2.2
 38    */
 39    public class ComponentAddress implements Serializable
 40    {
 41    private String _pageName;
 42   
 43    private String _idPath;
 44   
 45    /**
 46    * Creates a new ComponentAddress object that carries the identification information of the
 47    * given component (the page name and the ID path).
 48    *
 49    * @param component
 50    * the component to get the address of
 51    */
 52  0 public ComponentAddress(IComponent component)
 53    {
 54  0 this(component.getPage().getPageName(), component.getIdPath());
 55    }
 56   
 57    /**
 58    * Creates a new ComponentAddress using the given Page Name and ID Path
 59    *
 60    * @param pageName
 61    * the name of the page that contains the component
 62    * @param idPath
 63    * the ID Path of the component (which may be null)
 64    */
 65  4 public ComponentAddress(String pageName, String idPath)
 66    {
 67  4 Defense.notNull(pageName, "pageName");
 68   
 69  4 _pageName = pageName;
 70  4 _idPath = idPath;
 71    }
 72   
 73    /**
 74    * Creates a new ComponentAddress using the given Page Name and ID Path relative on the provided
 75    * Namespace
 76    *
 77    * @param namespace
 78    * the namespace of the page that contains the component
 79    * @param pageName
 80    * the name of the page that contains the component
 81    * @param idPath
 82    * the ID Path of the component
 83    */
 84  0 public ComponentAddress(INamespace namespace, String pageName, String idPath)
 85    {
 86  0 this(namespace.constructQualifiedName(pageName), idPath);
 87    }
 88   
 89    /**
 90    * Finds a component with the current address using the given RequestCycle.
 91    *
 92    * @param cycle
 93    * the RequestCycle to use to locate the component
 94    * @return IComponent a component that has been initialized for the given RequestCycle
 95    */
 96  0 public IComponent findComponent(IRequestCycle cycle)
 97    {
 98  0 IPage objPage = cycle.getPage(_pageName);
 99  0 return objPage.getNestedComponent(_idPath);
 100    }
 101   
 102    /**
 103    * Returns the idPath of the component.
 104    *
 105    * @return String the ID path of the component, or null if the address references a page, not a
 106    * component within a page.
 107    */
 108  6 public String getIdPath()
 109    {
 110  6 return _idPath;
 111    }
 112   
 113    /**
 114    * Returns the Page Name of the component.
 115    *
 116    * @return String the Page Name of the component
 117    */
 118  6 public String getPageName()
 119    {
 120  6 return _pageName;
 121    }
 122   
 123    /**
 124    * @see java.lang.Object#hashCode()
 125    */
 126  0 public int hashCode()
 127    {
 128  0 int hash = _pageName.hashCode() * 31;
 129  0 if (_idPath != null)
 130  0 hash += _idPath.hashCode();
 131  0 return hash;
 132    }
 133   
 134    /**
 135    * @see java.lang.Object#equals(Object)
 136    */
 137  2 public boolean equals(Object obj)
 138    {
 139  2 if (!(obj instanceof ComponentAddress))
 140  0 return false;
 141   
 142  2 if (obj == this)
 143  0 return true;
 144   
 145  2 ComponentAddress objAddress = (ComponentAddress) obj;
 146  2 if (!getPageName().equals(objAddress.getPageName()))
 147  0 return false;
 148   
 149  2 String idPath1 = getIdPath();
 150  2 String idPath2 = objAddress.getIdPath();
 151  2 return (idPath1 == idPath2) || (idPath1 != null && idPath1.equals(idPath2));
 152    }
 153   
 154    }