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.pageStore;
018
019import org.apache.wicket.page.IManageablePage;
020import org.apache.wicket.util.lang.Args;
021
022/**
023 * A wrapper around a serialized page.
024 * <p>
025 * An {@link IPageStore} might use this representation of a page internally,
026 * accept it in {@link IPageStore#addPage(IPageContext, IManageablePage)} or delegate it
027 * to another store.
028 * <p>
029 * Stores might pose restrictions on what type of pages they work with, see {@link CryptingPageStore}
030 * for an example.
031 * 
032 * @see SerializingPageStore
033 */
034public final class SerializedPage implements IManageablePage
035{
036        private final int pageId;
037        
038        private final String pageType;
039
040        private final byte[] data;
041
042        /**
043         * Create a serialized page.
044         * 
045         * @param pageId id of page
046         * @param data
047         */
048        public SerializedPage(int pageId, byte[] data)
049        {
050                this(pageId, null, data);
051        }
052
053        /**
054         * Create a serialized page.
055         * 
056         * @param pageId id of page
057         * @param pageType type of page, might be {@code null}
058         * @param data
059         */
060        public SerializedPage(int pageId, String pageType, byte[] data)
061        {
062                this.pageId = pageId;
063                this.pageType = pageType;
064                this.data = Args.notNull(data, "data");
065        }
066
067        @Override
068        public boolean isPageStateless()
069        {
070                return false;
071        }
072
073        @Override
074        public int getPageId()
075        {
076                return pageId;
077        }
078
079
080        public String getPageType()
081        {
082                return pageType;
083        }
084
085        public byte[] getData()
086        {
087                return data;
088        }
089
090        @Override
091        public void detach() {
092        }
093
094        @Override
095        public boolean setFreezePageId(boolean freeze)
096        {
097                return false;
098        }
099        
100        @Override
101        public String toString()
102        {
103                return "[SerializedPage id = " + pageId + ", type=" + pageType + ", size=" + data.length + "]";
104        }
105}