001/** 002 * GRANITE DATA SERVICES 003 * Copyright (C) 2006-2013 GRANITE DATA SERVICES S.A.S. 004 * 005 * This file is part of the Granite Data Services Platform. 006 * 007 * Granite Data Services is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * Granite Data Services is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 015 * General Public License for more details. 016 * 017 * You should have received a copy of the GNU Lesser General Public 018 * License along with this library; if not, write to the Free Software 019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 020 * USA, or see <http://www.gnu.org/licenses/>. 021 */ 022package org.granite.tide.data.model; 023 024import java.io.Externalizable; 025import java.io.IOException; 026import java.io.ObjectInput; 027import java.io.ObjectOutput; 028 029 030public class PageInfo implements Externalizable { 031 032 private static final long serialVersionUID = 1L; 033 034 private int firstResult; 035 private int maxResults; 036 private SortInfo sortInfo; 037 038 039 public PageInfo() { 040 } 041 042 public PageInfo(int firstResult, int maxResults) { 043 this.firstResult = firstResult; 044 this.maxResults = maxResults; 045 this.sortInfo = null; 046 } 047 048 public PageInfo(int firstResult, int maxResults, String[] order, boolean[] desc) { 049 this.firstResult = firstResult; 050 this.maxResults = maxResults; 051 this.sortInfo = order != null && desc != null && order.length > 0 && desc.length > 0 ? new SortInfo(order, desc) : null; 052 } 053 054 055 public int getFirstResult() { 056 return firstResult; 057 } 058 public void setFirstResult(int firstResult) { 059 this.firstResult = firstResult; 060 } 061 062 public int getMaxResults() { 063 return maxResults; 064 } 065 public void setMaxResults(int maxResults) { 066 this.maxResults = maxResults; 067 } 068 069 public SortInfo getSortInfo() { 070 return sortInfo; 071 } 072 public void setSortInfo(SortInfo sortInfo) { 073 this.sortInfo = sortInfo; 074 } 075 076 077 public void writeExternal(ObjectOutput out) throws IOException { 078 out.writeObject(firstResult); 079 out.writeObject(maxResults); 080 out.writeObject(sortInfo != null ? sortInfo.getOrder() : null); 081 out.writeObject(sortInfo != null ? sortInfo.getDesc() : null); 082 } 083 084 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { 085 firstResult = (Integer)in.readObject(); 086 maxResults = (Integer)in.readObject(); 087 Object[] oorder = (Object[])in.readObject(); 088 Object[] odesc = (Object[])in.readObject(); 089 if (oorder == null || odesc == null) { 090 sortInfo = null; 091 return; 092 } 093 String[] order = new String[oorder.length]; 094 boolean[] desc = new boolean[oorder.length]; 095 int i = 0; 096 for (Object o : oorder) 097 order[i++] = (String)o; 098 i = 0; 099 for (Object d : odesc) 100 desc[i++] = (Boolean)d; 101 sortInfo = new SortInfo(order, desc); 102 } 103 104}