|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ComponentAddress.java | 37.5% | 50% | 50% | 47.4% |
|
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.tapestry.IComponent;
|
|
20 |
import org.apache.tapestry.INamespace;
|
|
21 |
import org.apache.tapestry.IPage;
|
|
22 |
import org.apache.tapestry.IRequestCycle;
|
|
23 |
|
|
24 |
/**
|
|
25 |
* The ComponentAddress class contains the path to a component, allowing it to
|
|
26 |
* locate an instance of that component in a different
|
|
27 |
* {@link org.apache.tapestry.IRequestCycle}.
|
|
28 |
*
|
|
29 |
* <p>This class needs to be used mostly when working with components
|
|
30 |
* accessed via the {@link org.apache.tapestry.IRender} interface.
|
|
31 |
* It allows those components to serialize and
|
|
32 |
* pass as a service parameter information about what component they have to
|
|
33 |
* talk to if control returns back to them.
|
|
34 |
*
|
|
35 |
* <p>This situation often occurs when the component used via IRender contains
|
|
36 |
* Direct or Action links.
|
|
37 |
*
|
|
38 |
* @author mindbridge
|
|
39 |
* @since 2.2
|
|
40 |
*
|
|
41 |
*/
|
|
42 |
public class ComponentAddress implements Serializable |
|
43 |
{ |
|
44 |
private String _pageName;
|
|
45 |
private String _idPath;
|
|
46 |
|
|
47 |
/**
|
|
48 |
* Creates a new ComponentAddress object that carries the identification
|
|
49 |
* information of the given component (the page name and the ID path).
|
|
50 |
* @param component 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 |
* @param pageName the name of the page that contains the component
|
|
60 |
* @param idPath the ID Path of the component
|
|
61 |
*/
|
|
62 | 4 |
public ComponentAddress(String pageName, String idPath)
|
63 |
{ |
|
64 | 4 |
_pageName = pageName; |
65 | 4 |
_idPath = idPath; |
66 |
} |
|
67 |
|
|
68 |
/**
|
|
69 |
* Creates a new ComponentAddress using the given Page Name and ID Path
|
|
70 |
* relative on the provided Namespace
|
|
71 |
* @param namespace the namespace of the page that contains the component
|
|
72 |
* @param pageName the name of the page that contains the component
|
|
73 |
* @param idPath the ID Path of the component
|
|
74 |
*/
|
|
75 | 0 |
public ComponentAddress(
|
76 |
INamespace namespace, |
|
77 |
String pageName, |
|
78 |
String idPath) |
|
79 |
{ |
|
80 | 0 |
this(namespace.constructQualifiedName(pageName), idPath);
|
81 |
} |
|
82 |
|
|
83 |
/**
|
|
84 |
* Finds a component with the current address using the given RequestCycle.
|
|
85 |
* @param cycle the RequestCycle to use to locate the component
|
|
86 |
* @return IComponent a component that has been initialized for the given RequestCycle
|
|
87 |
*/
|
|
88 | 0 |
public IComponent findComponent(IRequestCycle cycle)
|
89 |
{ |
|
90 | 0 |
IPage objPage = cycle.getPage(_pageName); |
91 | 0 |
return objPage.getNestedComponent(_idPath);
|
92 |
} |
|
93 |
|
|
94 |
/**
|
|
95 |
* Returns the idPath of the component.
|
|
96 |
* @return String the ID path of the component
|
|
97 |
*/
|
|
98 | 6 |
public String getIdPath()
|
99 |
{ |
|
100 | 6 |
return _idPath;
|
101 |
} |
|
102 |
|
|
103 |
/**
|
|
104 |
* Returns the Page Name of the component.
|
|
105 |
* @return String the Page Name of the component
|
|
106 |
*/
|
|
107 | 6 |
public String getPageName()
|
108 |
{ |
|
109 | 6 |
return _pageName;
|
110 |
} |
|
111 |
|
|
112 |
/**
|
|
113 |
* @see java.lang.Object#hashCode()
|
|
114 |
*/
|
|
115 | 0 |
public int hashCode() |
116 |
{ |
|
117 | 0 |
int hash = _pageName.hashCode() * 31;
|
118 | 0 |
if (_idPath != null) |
119 | 0 |
hash += _idPath.hashCode(); |
120 | 0 |
return hash;
|
121 |
} |
|
122 |
|
|
123 |
/**
|
|
124 |
* @see java.lang.Object#equals(Object)
|
|
125 |
*/
|
|
126 | 2 |
public boolean equals(Object obj) |
127 |
{ |
|
128 | 2 |
if (!(obj instanceof ComponentAddress)) |
129 | 0 |
return false; |
130 |
|
|
131 | 2 |
if (obj == this) |
132 | 0 |
return true; |
133 |
|
|
134 | 2 |
ComponentAddress objAddress = (ComponentAddress) obj; |
135 | 2 |
if (!getPageName().equals(objAddress.getPageName()))
|
136 | 0 |
return false; |
137 |
|
|
138 | 2 |
String idPath1 = getIdPath(); |
139 | 2 |
String idPath2 = objAddress.getIdPath(); |
140 | 2 |
return (idPath1 == idPath2)
|
141 |
|| (idPath1 != null && idPath1.equals(idPath2));
|
|
142 |
} |
|
143 |
|
|
144 |
} |
|
145 |
|
|