001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.wicket.request.target.component;
018:
019: import org.apache.wicket.Page;
020: import org.apache.wicket.RequestCycle;
021:
022: /**
023: * Default implementation of {@link IPageRequestTarget}. Target that denotes a
024: * page instance.
025: *
026: * @author Eelco Hillenius
027: */
028: public class PageRequestTarget implements IPageRequestTarget
029:
030: {
031: /** the page instance. */
032: private final Page page;
033:
034: /**
035: * Construct.
036: *
037: * @param page
038: * the page instance
039: */
040: public PageRequestTarget(Page page) {
041: if (page == null) {
042: throw new IllegalArgumentException(
043: "Argument page must be not null");
044: }
045:
046: this .page = page;
047: }
048:
049: /**
050: * @see org.apache.wicket.IRequestTarget#respond(org.apache.wicket.RequestCycle)
051: */
052: public void respond(RequestCycle requestCycle) {
053: // Should page be redirected to?
054: if (requestCycle.isRedirect()) {
055: // Redirect to the page
056: requestCycle.redirectTo(page);
057: } else {
058: // Let page render itself
059: page.renderPage();
060: }
061: }
062:
063: /**
064: * @see org.apache.wicket.request.target.component.IPageRequestTarget#getPage()
065: */
066: public final Page getPage() {
067: return page;
068: }
069:
070: /**
071: * @see org.apache.wicket.IRequestTarget#detach(org.apache.wicket.RequestCycle)
072: */
073: public void detach(RequestCycle requestCycle) {
074: page.detach();
075: }
076:
077: /**
078: * @see java.lang.Object#equals(java.lang.Object)
079: */
080: public boolean equals(Object obj) {
081: if (obj instanceof PageRequestTarget) {
082: PageRequestTarget that = (PageRequestTarget) obj;
083: return page.equals(that.page);
084: }
085: return false;
086: }
087:
088: /**
089: * @see java.lang.Object#hashCode()
090: */
091: public int hashCode() {
092: int result = "PageRequestTarget".hashCode();
093: result += page.hashCode();
094: return 17 * result;
095: }
096:
097: /**
098: * @see java.lang.Object#toString()
099: */
100: public String toString() {
101: return "[PageRequestTarget@" + hashCode() + " page=" + page
102: + "]";
103: }
104: }
|