001: /*
002: * ====================================================================
003: * JAFFA - Java Application Framework For All
004: *
005: * Copyright (C) 2002 JAFFA Development Group
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: * Redistribution and use of this software and associated documentation ("Software"),
022: * with or without modification, are permitted provided that the following conditions are met:
023: * 1. Redistributions of source code must retain copyright statements and notices.
024: * Redistributions must also contain a copy of this document.
025: * 2. Redistributions in binary form must reproduce the above copyright notice,
026: * this list of conditions and the following disclaimer in the documentation
027: * and/or other materials provided with the distribution.
028: * 3. The name "JAFFA" must not be used to endorse or promote products derived from
029: * this Software without prior written permission. For written permission,
030: * please contact mail to: jaffagroup@yahoo.com.
031: * 4. Products derived from this Software may not be called "JAFFA" nor may "JAFFA"
032: * appear in their names without prior written permission.
033: * 5. Due credit should be given to the JAFFA Project (http://jaffa.sourceforge.net).
034: *
035: * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
036: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
037: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
038: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
039: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
040: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
041: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
042: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
043: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
044: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
045: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
046: * SUCH DAMAGE.
047: * ====================================================================
048: */
049:
050: package org.jaffa.presentation.portlet;
051:
052: import java.io.Serializable;
053:
054: /** This object is returned by the event handlers. It indicates the form to which control should be passed & the corresponding Component's id. Ensure that a 'forward' mapping exists for the formName in the struts-config file.
055: * The formName and componentId are immutable properties and can only be passed in the constructor.
056: * The title can be set at any time and is mainly for use in the historyNav.jsp, for displaying the history bar links.
057: */
058: public class FormKey implements Cloneable, Comparable, Serializable {
059:
060: private String m_formName = null;
061: private String m_componentId = null;
062: private String m_title = null;
063: private static FormKey c_closeBrowserFormKey = null;
064:
065: /** Constructs an instance of the FormKey class
066: * @param formName The formName
067: * @param componentId The componentId
068: */
069: public FormKey(String formName, String componentId) {
070: m_formName = formName;
071: m_componentId = componentId;
072: }
073:
074: /** Returns the formName
075: * @return The formName
076: */
077: public String getFormName() {
078: return m_formName;
079: }
080:
081: /** Returns the componentId
082: * @return The componentId
083: */
084: public String getComponentId() {
085: return m_componentId;
086: }
087:
088: /** Getter for property title.
089: * @return Value of property title.
090: *
091: */
092: public String getTitle() {
093: return m_title;
094: }
095:
096: /** Setter for property title.
097: * @param title New value of property title.
098: *
099: */
100: public void setTitle(String title) {
101: m_title = title;
102: }
103:
104: /** Returns a clone of the object.
105: * @return a clone of the object.
106: */
107: public Object clone() {
108: try {
109: return super .clone();
110: // no more processing required since the fields are immutable
111: } catch (CloneNotSupportedException e) {
112: // this shouldn't happen, since we are Cloneable
113: return null;
114: }
115: }
116:
117: /** Compares this object with another FormKey object.
118: * It compares the fields componentId, formName of the 2 objects.
119: * @param obj the other FormKey object.
120: * @return a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
121: */
122: public int compareTo(Object obj) {
123: FormKey target = (FormKey) obj;
124: int i = 0;
125:
126: // First compare the componentId
127: if (m_componentId != null && target.m_componentId != null)
128: i = m_componentId.compareTo(target.m_componentId);
129: else if (m_componentId != null)
130: i = 1;
131: else if (target.m_componentId != null)
132: i = -1;
133:
134: // Compare the formName if the componentIds are same
135: if (i == 0) {
136: if (m_formName != null && target.m_formName != null)
137: i = m_formName.compareTo(target.m_formName);
138: else if (m_formName != null)
139: i = 1;
140: else if (target.m_formName != null)
141: i = -1;
142: }
143:
144: return i;
145: }
146:
147: /** Returns an int which will be the sum of the of the hashcodes of componentId, formName.
148: * @return an int which will be the sum of the of the hashcodes of componentId, formName.
149: */
150: public int hashCode() {
151: return m_componentId != null ? m_componentId.hashCode()
152: : 0 + m_formName != null ? m_formName.hashCode() : 0;
153: }
154:
155: /** Compares this object with another FormKey object.
156: * Returns a true if both the objects have the same formName, componentId.
157: * @param obj the other FormKey object.
158: * @return a true if both the objects have the same formName, componentId.
159: */
160: public boolean equals(Object obj) {
161: if (obj != null && obj instanceof FormKey) {
162: FormKey target = (FormKey) obj;
163: return (m_formName != null ? m_formName
164: .equals(target.m_formName)
165: : target.m_formName == null)
166: && (m_componentId != null ? m_componentId
167: .equals(target.m_componentId)
168: : target.m_componentId == null);
169: } else {
170: return false;
171: }
172: }
173:
174: /** Returns the debug information for the object
175: * @return The debug information
176: */
177: public String toString() {
178: return "FormName=" + m_formName + ", ComponentId="
179: + m_componentId + ", Title=" + m_title;
180: }
181:
182: /** Returns the FormKey that will render the JSP used for closing a browser window.
183: * The JSP to be rendered is found by the forward mapping 'jaffa_closeBrowser' specified in the struts-config.xml file.
184: * @return The FormKey that will render the JSP used for closing a browser window.
185: */
186: public static FormKey getCloseBrowserFormKey() {
187: if (c_closeBrowserFormKey == null)
188: c_closeBrowserFormKey = new FormKey("jaffa_closeBrowser",
189: null);
190: return c_closeBrowserFormKey;
191: }
192:
193: }
|