1 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 39 public class ComponentAddress implements Serializable 40 { 41 private String _pageName; 42 43 private String _idPath; 44 45 52 public ComponentAddress(IComponent component) 53 { 54 this(component.getPage().getPageName(), component.getIdPath()); 55 } 56 57 65 public ComponentAddress(String pageName, String idPath) 66 { 67 Defense.notNull(pageName, "pageName"); 68 69 _pageName = pageName; 70 _idPath = idPath; 71 } 72 73 84 public ComponentAddress(INamespace namespace, String pageName, String idPath) 85 { 86 this(namespace.constructQualifiedName(pageName), idPath); 87 } 88 89 96 public IComponent findComponent(IRequestCycle cycle) 97 { 98 IPage objPage = cycle.getPage(_pageName); 99 return objPage.getNestedComponent(_idPath); 100 } 101 102 108 public String getIdPath() 109 { 110 return _idPath; 111 } 112 113 118 public String getPageName() 119 { 120 return _pageName; 121 } 122 123 126 public int hashCode() 127 { 128 int hash = _pageName.hashCode() * 31; 129 if (_idPath != null) 130 hash += _idPath.hashCode(); 131 return hash; 132 } 133 134 137 public boolean equals(Object obj) 138 { 139 if (!(obj instanceof ComponentAddress)) 140 return false; 141 142 if (obj == this) 143 return true; 144 145 ComponentAddress objAddress = (ComponentAddress) obj; 146 if (!getPageName().equals(objAddress.getPageName())) 147 return false; 148 149 String idPath1 = getIdPath(); 150 String idPath2 = objAddress.getIdPath(); 151 return (idPath1 == idPath2) || (idPath1 != null && idPath1.equals(idPath2)); 152 } 153 154 } | Popular Tags |