001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.3_testing/src/org/deegree/io/rtree/PageFile.java $
002    //----------------------------------------
003    //RTree implementation.
004    //Copyright (C) 2002-2004 Wolfgang Baer - WBaer@gmx.de
005    //
006    //This library is free software; you can redistribute it and/or
007    //modify it under the terms of the GNU Lesser General Public
008    //License as published by the Free Software Foundation; either
009    //version 2.1 of the License, or (at your option) any later version.
010    //
011    //This library is distributed in the hope that it will be useful,
012    //but WITHOUT ANY WARRANTY; without even the implied warranty of
013    //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014    //Lesser General Public License for more details.
015    //
016    //You should have received a copy of the GNU Lesser General Public
017    //License along with this library; if not, write to the Free Software
018    //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019    //----------------------------------------
020    
021    package org.deegree.io.rtree;
022    
023    import java.io.Serializable;
024    
025    /**
026     * <p>
027     * Abstract class implementing general methods of a PageFile.
028     * </p>
029     *
030     * @author Wolfgang Baer - WBaer@gmx.de
031     * @author last edited by: $Author: aschmitz $
032     *
033     * @version $Revision: 12519 $, $Date: 2008-06-25 11:37:30 +0200 (Mi, 25. Jun 2008) $
034     */
035    abstract class PageFile implements Serializable {
036    
037        /** dimension of saved data */
038        protected int dimension;
039    
040        /** capacity of a node (= MaxLoad + 1) */
041        protected int capacity;
042    
043        /** minimum load of a node */
044        protected int minimum;
045    
046        /**
047         * Returns the dimension of the PageFile
048         *
049         * @return int
050         *
051         */
052        protected int getDimension() {
053            return dimension;
054        }
055    
056        /**
057         * Returns the minimum load of a node
058         *
059         * @return int
060         */
061        protected int getMinimum() {
062            return minimum;
063        }
064    
065        /**
066         * Returns the capacity of a node in the PageFile. Capacity is defined a maximum load of a node
067         * plus 1 for overflow
068         *
069         * @return int
070         */
071        protected int getCapacity() {
072            return capacity;
073        }
074    
075        /**
076         * Reads a node from the PageFile for given index
077         *
078         * @param pageFileNumber -
079         *            index of page file number where node is saved
080         * @return Node
081         * @throws PageFileException
082         */
083        protected abstract Node readNode( int pageFileNumber )
084                                throws PageFileException;
085    
086        /**
087         * Writes a node into the PageFile Method tests if node has already a PageNumber, otherwise a
088         * new page number is assigned and returned.
089         *
090         * @param node -
091         *            Node to write
092         * @return int - page number
093         * @throws PageFileException
094         */
095        protected abstract int writeNode( Node node )
096                                throws PageFileException;
097    
098        /**
099         * Marks the node at given page number as deleted.
100         *
101         * @param pageFileNumber -
102         *            page number
103         * @return Node - deleted node
104         * @throws PageFileException
105         */
106        protected abstract Node deleteNode( int pageFileNumber )
107                                throws PageFileException;
108    
109        /**
110         * Initializes the PageFile.
111         *
112         * @param dimension -
113         *            dimension of the data
114         * @param capacity -
115         *            capacity of a node
116         * @throws PageFileException
117         */
118        protected void initialize( int dimension, int capacity )
119                                throws PageFileException {
120            this.dimension = dimension;
121            this.capacity = capacity;
122            this.minimum = (int) Math.round( ( capacity - 1 ) * 0.5 );
123            if ( this.minimum < 2 )
124                this.minimum = 2;
125        }
126    
127        /**
128         * Closes the pagefile.
129         *
130         * @throws PageFileException
131         */
132        protected abstract void close()
133                                throws PageFileException;
134    
135    }