001package org.granite.tide.data.model;
002
003import java.io.Externalizable;
004import java.io.IOException;
005import java.io.ObjectInput;
006import java.io.ObjectOutput;
007
008
009public class PageInfo implements Externalizable {
010        
011        private int firstResult;
012        private int maxResults;
013        private SortInfo sortInfo;
014        
015        
016        public PageInfo() {             
017        }
018        
019        public PageInfo(int firstResult, int maxResults, String[] order, boolean[] desc) {
020                this.firstResult = firstResult;
021                this.maxResults = maxResults;
022                this.sortInfo = order != null && desc != null && order.length > 0 && desc.length > 0 ? new SortInfo(order, desc) : null;
023        }
024        
025        
026        public int getFirstResult() {
027                return firstResult;
028        }
029        public void setFirstResult(int firstResult) {
030                this.firstResult = firstResult;
031        }
032        
033        public int getMaxResults() {
034                return maxResults;
035        }
036        public void setMaxResults(int maxResults) {
037                this.maxResults = maxResults;
038        }
039        
040        public SortInfo getSortInfo() {
041                return sortInfo;
042        }
043        public void setSortInfo(SortInfo sortInfo) {
044                this.sortInfo = sortInfo;
045        }
046        
047
048        public void writeExternal(ObjectOutput out) throws IOException {
049                out.writeObject(firstResult);
050                out.writeObject(maxResults);
051                out.writeObject(sortInfo != null ? sortInfo.getOrder() : null);
052                out.writeObject(sortInfo != null ? sortInfo.getDesc() : null);
053        }
054
055        public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
056                firstResult = (Integer)in.readObject();
057                maxResults = (Integer)in.readObject();
058                Object[] oorder = (Object[])in.readObject();
059                Object[] odesc = (Object[])in.readObject();
060                if (oorder == null || odesc == null) {
061                        sortInfo = null;
062                        return;
063                }
064                String[] order = new String[oorder.length];
065                boolean[] desc = new boolean[oorder.length];
066                int i = 0;
067                for (Object o : oorder)
068                        order[i++] = (String)o;
069                i = 0;
070                for (Object d : odesc)
071                        desc[i++] = (Boolean)d;
072                sortInfo = new SortInfo(order, desc);
073        }
074
075}