Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  // Copyright 2004, 2005 The Apache Software Foundation
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  //     http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
 // distributed under the License is distributed on an "AS IS" BASIS,
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
 package org.apache.tapestry.util;
 
 
 import  org.apache.hivemind.util.Defense;
The ComponentAddress class contains the path to a component, allowing it to locate an instance of that component in a different org.apache.tapestry.IRequestCycle.

This class needs to be used mostly when working with components accessed via the org.apache.tapestry.IRenderinterface. It allows those components to serialize and pass as a service parameter information about what component they have to talk to if control returns back to them.

This situation often occurs when the component used via IRender contains Direct or Action links.

Author(s):
mindbridge
Since:
2.2
 
 public class ComponentAddress implements Serializable
 {
     private static final long serialVersionUID = 533068199722072804L;
 
     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).

Parameters:
component the component to get the address of
 
     public ComponentAddress(IComponent component)
     {
         this(component.getPage().getPageName(), component.getIdPath());
     }

    
Creates a new ComponentAddress using the given Page Name and ID Path.

Parameters:
pageName the name of the page that contains the component
idPath the ID Path of the component (which may be null)
 
     public ComponentAddress(String pageNameString idPath)
     {
         Defense.notNull(pageName"pageName");
 
          = pageName;
          = idPath;
     }

    
Creates a new ComponentAddress using the given Page Name and ID Path relative on the provided Namespace.

Parameters:
namespace the namespace of the page that contains the component
pageName the name of the page that contains the component
idPath the ID Path of the component
 
     public ComponentAddress(INamespace namespaceString pageNameString idPath)
     {
         this(namespace.constructQualifiedName(pageName), idPath);
     }

    
Finds a component with the current address using the given RequestCycle.

Parameters:
cycle the RequestCycle to use to locate the component
Returns:
IComponent a component that has been initialized for the given RequestCycle
 
     public IComponent findComponent(IRequestCycle cycle)
     {
        IPage objPage = cycle.getPage();
        return objPage.getNestedComponent();
    }

    
Returns the idPath of the component.

Returns:
String the ID path of the component, or null if the address references a page, not a component within a page.
    public String getIdPath()
    {
        return ;
    }

    
Returns the Page Name of the component.

Returns:
String the Page Name of the component
    public String getPageName()
    {
        return ;
    }

    

See also:
java.lang.Object.hashCode()
    public int hashCode()
    {
        int hash = .hashCode() * 31;
        if ( != null)
            hash += .hashCode();
        return hash;
    }

    

See also:
java.lang.Object.equals(Object)
    public boolean equals(Object obj)
    {
        if (!(obj instanceof ComponentAddress))
            return false;
        if (obj == this)
            return true;
        ComponentAddress objAddress = (ComponentAddressobj;
        if (!getPageName().equals(objAddress.getPageName()))
            return false;
        String idPath1 = getIdPath();
        String idPath2 = objAddress.getIdPath();
        return (idPath1 == idPath2) || (idPath1 != null && idPath1.equals(idPath2));
    }
New to GrepCode? Check out our FAQ X