CVS: Tapestry/framework/src/net/sf/tapestry ComponentAddress.java,1.4,1.5

Mind Bridge <[email protected]>
Newsgroups gmane.comp.java.tapestry.cvs
Message-ID <[email protected]>
Update of /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry
In directory sc8-pr-cvs1:/tmp/cvs-serv1370/framework/src/net/sf/tapestry

Modified Files:
	ComponentAddress.java 
Log Message:
modifications of ComponentAddress to work well with pages 
and addition of corresponding unit tests

Index: ComponentAddress.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry/ComponentAddress.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** ComponentAddress.java	23 Dec 2002 12:47:47 -0000	1.4
--- ComponentAddress.java	3 Jan 2003 17:53:14 -0000	1.5
***************
*** 24,126 ****
  public class ComponentAddress implements Serializable
  {
! 	private String _pageName;
! 	private String _idPath;
  
! 	/**
! 	 * Creates a new ComponentAddress object that carries the identification 
! 	 * information of the given component (the page name and the ID path).
! 	 * @param component the component to get the address of
! 	 */
! 	public ComponentAddress(IComponent component)
! 	{
! 		init(component);
! 	}
  
! 	/**
! 	 * Creates a new ComponentAddress using the given Page Name and ID Path
! 	 * @param pageName the name of the page that contains the component
! 	 * @param idPath the ID Path of the component
! 	 */
! 	public ComponentAddress(String pageName, String idPath)
! 	{
! 		_pageName = pageName;
! 		_idPath = idPath;
! 	}
  
! 	/**
! 	 * Creates a new ComponentAddress using the given Page Name and ID Path
! 	 * relative on the provided Namespace
! 	 * @param namespace the namespace of the page that contains the component
! 	 * @param pageName the name of the page that contains the component
! 	 * @param idPath the ID Path of the component
! 	 */
! 	public ComponentAddress(
! 		INamespace namespace,
! 		String pageName,
! 		String idPath)
! 	{
!         _pageName = namespace.constructQualifiedName(pageName);
! 		_idPath = idPath;
! 	}
  
! 	private void init(IComponent component)
! 	{
! 		IPage objPage = component.getPage();
  
! 		_pageName = objPage.getName();
! 		_idPath = component.getIdPath();
! 	}
  
! 	/**
! 	 * Finds a component with the current address using the given RequestCycle.
! 	 * @param objCycle the RequestCycle to use to locate the component
! 	 * @return IComponent a component that has been initialized for the given RequestCycle
! 	 */
! 	public IComponent findComponent(IRequestCycle cycle)
! 	{
! 		IPage objPage = cycle.getPage(_pageName);
! 		return objPage.getNestedComponent(_idPath);
! 	}
! 	/**
! 	 * Returns the idPath of the component.
! 	 * @return String the ID path of the component
! 	 */
! 	public String getIdPath()
! 	{
! 		return _idPath;
! 	}
  
! 	/**
! 	 * Returns the Page Name of the component.
! 	 * @return String the Page Name of the component
! 	 */
! 	public String getPageName()
! 	{
! 		return _pageName;
! 	}
  
! 	/**
! 	 * @see java.lang.Object#hashCode()
! 	 */
! 	public int hashCode()
! 	{
! 		return _pageName.hashCode() * 31 + _idPath.hashCode();
! 	}
  
! 	/**
! 	 * @see java.lang.Object#equals(Object)
! 	 */
! 	public boolean equals(Object obj)
! 	{
! 		if (!(obj instanceof ComponentAddress))
! 			return false;
  
! 		if (obj == this)
! 			return true;
  
! 		ComponentAddress objAddress = (ComponentAddress) obj;
! 		return getPageName().equals(objAddress.getPageName())
! 			&& getIdPath().equals(objAddress.getIdPath());
! 	}
  
  }
--- 24,126 ----
  public class ComponentAddress implements Serializable
  {
!     private String _pageName;
!     private String _idPath;
  
!     /**
!      * Creates a new ComponentAddress object that carries the identification 
!      * information of the given component (the page name and the ID path).
!      * @param component the component to get the address of
!      */
!     public ComponentAddress(IComponent component)
!     {
!         this(component.getPage().getName(), component.getIdPath());
!     }
  
!     /**
!      * Creates a new ComponentAddress using the given Page Name and ID Path
!      * @param pageName the name of the page that contains the component
!      * @param idPath the ID Path of the component
!      */
!     public ComponentAddress(String pageName, String idPath)
!     {
!         _pageName = pageName;
!         _idPath = idPath;
!     }
  
!     /**
!      * Creates a new ComponentAddress using the given Page Name and ID Path
!      * relative on the provided Namespace
!      * @param namespace the namespace of the page that contains the component
!      * @param pageName the name of the page that contains the component
!      * @param idPath the ID Path of the component
!      */
!     public ComponentAddress(
!         INamespace namespace,
!         String pageName,
!         String idPath)
!     {
!         this(namespace.constructQualifiedName(pageName), idPath);
!     }
  
!     /**
!      * Finds a component with the current address using the given RequestCycle.
!      * @param objCycle the RequestCycle to use to locate the component
!      * @return IComponent a component that has been initialized for the given RequestCycle
!      */
!     public IComponent findComponent(IRequestCycle cycle)
!     {
!         IPage objPage = cycle.getPage(_pageName);
!         return objPage.getNestedComponent(_idPath);
!     }
  
!     /**
!      * Returns the idPath of the component.
!      * @return String the ID path of the component
!      */
!     public String getIdPath()
!     {
!         return _idPath;
!     }
  
!     /**
!      * Returns the Page Name of the component.
!      * @return String the Page Name of the component
!      */
!     public String getPageName()
!     {
!         return _pageName;
!     }
  
!     /**
!      * @see java.lang.Object#hashCode()
!      */
!     public int hashCode()
!     {
!         int hash = _pageName.hashCode() * 31;
!         if (_idPath != null)
!             hash += _idPath.hashCode();
!         return hash;
!     }
  
!     /**
!      * @see java.lang.Object#equals(Object)
!      */
!     public boolean equals(Object obj)
!     {
!         if (!(obj instanceof ComponentAddress))
!             return false;
  
!         if (obj == this)
!             return true;
  
!         ComponentAddress objAddress = (ComponentAddress) obj;
!         if (!getPageName().equals(objAddress.getPageName()))
!             return false;
  
!         String idPath1 = getIdPath();
!         String idPath2 = objAddress.getIdPath();
!         return (idPath1 == idPath2)
!             || (idPath1 != null && idPath1.equals(idPath2));
!     }
  
  }



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.