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 */
017package org.apache.wicket;
018
019
020import org.apache.wicket.util.io.IClusterable;
021
022/**
023 * Unique identifier of a page instance
024 * 
025 * @author igor.vaynberg
026 */
027public class PageReference implements IClusterable
028{
029        private static final long serialVersionUID = 1L;
030
031        private final int pageId;
032
033        /**
034         * Constructor
035         * 
036         * @param pageId
037         */
038        public PageReference(int pageId)
039        {
040                this.pageId = pageId;
041        }
042
043        /**
044         * @return The page that the this PageReference references
045         */
046        public Page getPage()
047        {
048                return (Page)Session.get().getPageManager().getPage(pageId);
049        }
050
051        /**
052         * Gets pageId.
053         * 
054         * @return pageId
055         */
056        public int getPageId()
057        {
058                return pageId;
059        }
060
061
062        /**
063         * @see java.lang.Object#hashCode()
064         */
065        @Override
066        public int hashCode()
067        {
068                return pageId;
069        }
070
071        /**
072         * @see java.lang.Object#equals(java.lang.Object)
073         */
074        @Override
075        public boolean equals(Object obj)
076        {
077                if (this == obj)
078                {
079                        return true;
080                }
081                if (obj == null)
082                {
083                        return false;
084                }
085                if (getClass() != obj.getClass())
086                {
087                        return false;
088                }
089                PageReference other = (PageReference)obj;
090                return getPageId() == other.getPageId();
091        }
092
093
094}