001: /*
002: * $Id: PageRequestTarget.java 459916 2006-03-21 00:46:45Z jonl $
003: * $Revision: 459916 $ $Date: 2006-03-21 01:46:45 +0100 (Tue, 21 Mar 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;
019:
020: import wicket.Page;
021: import wicket.RequestCycle;
022:
023: /**
024: * Default implementation of {@link IPageRequestTarget}. Target that denotes a
025: * page instance.
026: *
027: * @author Eelco Hillenius
028: */
029: public class PageRequestTarget implements IPageRequestTarget
030:
031: {
032: /** the page instance. */
033: private final Page page;
034:
035: /**
036: * Construct.
037: *
038: * @param page
039: * the page instance
040: */
041: public PageRequestTarget(Page page) {
042: if (page == null) {
043: throw new IllegalArgumentException(
044: "Argument page must be not null");
045: }
046:
047: this .page = page;
048: }
049:
050: /**
051: * @see wicket.IRequestTarget#respond(wicket.RequestCycle)
052: */
053: public void respond(RequestCycle requestCycle) {
054: // Should page be redirected to?
055: if (requestCycle.getRedirect()) {
056: // Redirect to the page
057: requestCycle.redirectTo(page);
058: } else {
059: requestCycle.setUpdateSession(true);
060:
061: // Let page render itself
062: page.renderPage();
063: }
064: }
065:
066: /**
067: * @see wicket.request.target.component.IPageRequestTarget#getPage()
068: */
069: public final Page getPage() {
070: return page;
071: }
072:
073: /**
074: * @see wicket.IRequestTarget#detach(wicket.RequestCycle)
075: */
076: public void detach(RequestCycle requestCycle) {
077: page.internalDetach();
078: }
079:
080: /**
081: * @see wicket.IRequestTarget#getLock(RequestCycle)
082: */
083: public Object getLock(RequestCycle requestCycle) {
084: // we need to lock when we are not redirecting, i.e. we are
085: // actually rendering the page
086: return !requestCycle.getRedirect() ? requestCycle.getSession()
087: : null;
088: }
089:
090: /**
091: * @see java.lang.Object#equals(java.lang.Object)
092: */
093: public boolean equals(Object obj) {
094: if (obj instanceof PageRequestTarget) {
095: PageRequestTarget that = (PageRequestTarget) obj;
096: return page.equals(that.page);
097: }
098: return false;
099: }
100:
101: /**
102: * @see java.lang.Object#hashCode()
103: */
104: public int hashCode() {
105: int result = "PageRequestTarget".hashCode();
106: result += page.hashCode();
107: return 17 * result;
108: }
109:
110: /**
111: * @see java.lang.Object#toString()
112: */
113: public String toString() {
114: return "[PageRequestTarget@" + hashCode() + " page=" + page
115: + "]";
116: }
117: }
|