001: /*
002: * $Id: ListenerInterfaceRequestTarget.java,v 1.1 2005/11/27 23:22:45 eelco12
003: * Exp $ $Revision: 459416 $ $Date: 2006-02-17 21:56:58 +0100 (Fri, 17 Feb 2006) $
004: *
005: * ==============================================================================
006: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
007: * use this file except in compliance with the License. You may obtain a copy of
008: * the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
014: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
015: * License for the specific language governing permissions and limitations under
016: * the License.
017: */
018: package wicket.request.target.component.listener;
019:
020: import wicket.Application;
021: import wicket.Component;
022: import wicket.Page;
023: import wicket.RequestCycle;
024: import wicket.RequestListenerInterface;
025: import wicket.request.RequestParameters;
026: import wicket.request.target.IEventProcessor;
027: import wicket.request.target.component.PageRequestTarget;
028: import wicket.settings.IRequestCycleSettings;
029:
030: /**
031: * The abstract implementation of
032: * {@link wicket.request.target.component.listener.IListenerInterfaceRequestTarget}. Target that denotes
033: * a page instance and a call to a component on that page using an listener
034: * interface method.
035: *
036: * @author Eelco Hillenius
037: * @author Johan Compagner
038: */
039: public abstract class AbstractListenerInterfaceRequestTarget extends
040: PageRequestTarget implements IListenerInterfaceRequestTarget,
041: IEventProcessor {
042: /** The request parameters. */
043: private final RequestParameters requestParameters;
044:
045: /** the target component. */
046: private final Component component;
047:
048: /** the listener method. */
049: private final RequestListenerInterface listener;
050:
051: /**
052: * Construct.
053: *
054: * @param page
055: * the page instance
056: * @param component
057: * the target component
058: * @param listener
059: * the listener interface
060: */
061: public AbstractListenerInterfaceRequestTarget(final Page page,
062: final Component component, RequestListenerInterface listener) {
063: this (page, component, listener, null);
064: }
065:
066: /**
067: * Construct.
068: *
069: * @param page
070: * the page instance
071: * @param component
072: * the target component
073: * @param listener
074: * the listener method
075: * @param requestParameters
076: * the request parameter
077: */
078: public AbstractListenerInterfaceRequestTarget(final Page page,
079: final Component component,
080: final RequestListenerInterface listener,
081: final RequestParameters requestParameters) {
082: super (page);
083:
084: if (component == null) {
085: throw new IllegalArgumentException(
086: "Argument component must be not null");
087: }
088:
089: this .component = component;
090:
091: if (listener == null) {
092: throw new IllegalArgumentException(
093: "Argument listenerMethod must be not null");
094: }
095:
096: this .listener = listener;
097: this .requestParameters = requestParameters;
098: }
099:
100: /**
101: * Common functionality to be called by processEvents()
102: *
103: * @param requestCycle
104: * The request cycle
105: */
106: protected void onProcessEvents(final RequestCycle requestCycle) {
107: // Assume cluster needs to be updated now, unless listener
108: // invocation changes this
109: requestCycle.setUpdateSession(true);
110:
111: // Clear all feedback messages if it isn't a redirect
112: getPage().getFeedbackMessages().clear();
113:
114: getPage().startComponentRender(getTarget());
115:
116: final Application application = requestCycle.getApplication();
117: // and see if we have to redirect the render part by default
118: IRequestCycleSettings.RenderStrategy strategy = application
119: .getRequestCycleSettings().getRenderStrategy();
120: boolean issueRedirect = (strategy == IRequestCycleSettings.REDIRECT_TO_RENDER || strategy == IRequestCycleSettings.REDIRECT_TO_BUFFER);
121:
122: requestCycle.setRedirect(issueRedirect);
123: }
124:
125: /**
126: * @see java.lang.Object#equals(java.lang.Object)
127: */
128: public boolean equals(Object obj) {
129: boolean equal = false;
130: if (obj != null && obj.getClass().equals(getClass())) {
131: AbstractListenerInterfaceRequestTarget that = (AbstractListenerInterfaceRequestTarget) obj;
132: if (component.equals(that.component)
133: && listener.equals(that.listener)) {
134: if (requestParameters != null) {
135: return requestParameters
136: .equals(that.requestParameters);
137: } else {
138: return that.requestParameters == null;
139: }
140: }
141: }
142: return equal;
143: }
144:
145: /**
146: * @see wicket.request.target.component.listener.IListenerInterfaceRequestTarget#getRequestParameters()
147: */
148: public final RequestParameters getRequestParameters() {
149: return this .requestParameters;
150: }
151:
152: /**
153: * @see wicket.request.target.component.listener.IListenerInterfaceRequestTarget#getRequestListenerInterface()
154: */
155: public final RequestListenerInterface getRequestListenerInterface() {
156: return listener;
157: }
158:
159: /**
160: * @see wicket.request.target.component.listener.IListenerInterfaceRequestTarget#getTarget()
161: */
162: public final Component getTarget() {
163: return component;
164: }
165:
166: /**
167: * @see java.lang.Object#hashCode()
168: */
169: public int hashCode() {
170: int result = getClass().hashCode();
171: result += component.hashCode();
172: result += listener.hashCode();
173: result += requestParameters != null ? requestParameters
174: .hashCode() : 0;
175: return 17 * result;
176: }
177:
178: /**
179: * @see java.lang.Object#toString()
180: */
181: public String toString() {
182: StringBuffer buf = new StringBuffer(getClass().getName())
183: .append("@").append(hashCode()).append(
184: getPage().toString()).append("->").append(
185: getTarget().getId()).append("->").append(
186: getRequestListenerInterface().getMethod()
187: .getDeclaringClass()).append(".")
188: .append(getRequestListenerInterface().getName());
189:
190: if (requestParameters != null) {
191: buf.append(" (request paramaters: ").append(
192: requestParameters.toString()).append(")");
193: }
194: return buf.toString();
195: }
196: }
|