View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.trinidad.model;
20  
21  import java.util.List;
22  
23  /**
24   * <p>
25   * Used by anybody who wants to wrap the <code>CollectionModel</code> class. 
26   * </p>
27   * <p>
28   * This class simply delegates all the CollectionModel functionalities to the wrapped class.
29   * </p>
30   * The wrapped CollectionModel is returned by the <code>getCollectionModel</code> method. And that 
31   * method needs to be overriden by the subclasses.
32   * @see #getCollectionModel
33   */
34  public abstract class CollectionModelDecorator
35    extends CollectionModel
36  {
37    public Object getRowKey()
38    {
39      return getCollectionModel().getRowKey();
40    }
41  
42    public void setRowKey(Object key)
43    {
44      getCollectionModel().setRowKey(key);
45    }
46  
47    public boolean isRowAvailable(int rowIndex)
48    {
49      return getCollectionModel().isRowAvailable(rowIndex);
50    }
51  
52    public boolean isRowAvailable(Object rowKey)
53    {
54      return getCollectionModel().isRowAvailable(rowKey);
55    }
56  
57    public Object getRowData(int rowIndex)
58    {
59      return getCollectionModel().getRowData(rowIndex);
60    }
61  
62    public Object getRowData(Object rowKey)
63    {
64      return getCollectionModel().getRowData(rowKey);
65    }
66  
67    public boolean isSortable(String property)
68    {
69      return getCollectionModel().isSortable(property);
70    }
71  
72    public List<SortCriterion> getSortCriteria()
73    {
74      return getCollectionModel().getSortCriteria();
75    }
76  
77    public void setSortCriteria(List<SortCriterion> criteria)
78    {
79      getCollectionModel().setSortCriteria(criteria);
80    }
81  
82    public boolean areRowsAvailable(int startIndex, int rowCount)
83    {
84      return getCollectionModel().areRowsAvailable(startIndex, rowCount);
85    }
86    
87    public boolean areRowsAvailable(Object startRowKey, int rowCount)
88    {
89      return getCollectionModel().areRowsAvailable(startRowKey, rowCount);
90    }
91    
92    public boolean areRowsAvailable(int rowCount)
93    {
94      return getCollectionModel().areRowsAvailable(rowCount);
95    }
96    
97    //
98    // below are the LocalRowKeyIndex APIs
99    //
100   
101   public boolean areRowsLocallyAvailable(int startIndex, int rowCount)
102   {
103     return getCollectionModel().areRowsLocallyAvailable(startIndex, rowCount);
104   }
105   
106   public boolean areRowsLocallyAvailable(Object startRowKey, int rowCount)
107   {
108     return getCollectionModel().areRowsLocallyAvailable(startRowKey, rowCount);
109   }
110     
111   public boolean areRowsLocallyAvailable(int rowCount)
112   {
113     return getCollectionModel().areRowsLocallyAvailable(rowCount);
114   }
115 
116   public boolean isRowLocallyAvailable(int rowIndex)
117   {
118     return getCollectionModel().isRowLocallyAvailable(rowIndex);
119   }
120   
121   public boolean isRowLocallyAvailable(Object rowKey)
122   {
123     return getCollectionModel().isRowLocallyAvailable(rowKey);
124   }
125   
126   public int getEstimatedRowCount()
127   {
128     return getCollectionModel().getEstimatedRowCount();
129   }
130   
131   public LocalRowKeyIndex.Confidence getEstimatedRowCountConfidence()
132   {
133     return getCollectionModel().getEstimatedRowCountConfidence();
134   }
135 
136   /**
137    * clear all rows from the local cache
138    */
139   public void clearLocalCache()
140   {
141     getCollectionModel().clearLocalCache();
142   }
143   
144   /**
145    * Clear the requested range of rows from the local cache
146    * @param startingIndex starting row index for the range to clear
147    * @param rowsToClear number of rows to clear from the cache
148    */
149   public void clearCachedRows(int startingIndex,  int rowsToClear)
150   {
151     getCollectionModel().clearCachedRows(startingIndex, rowsToClear);
152   }
153   
154   /**
155    * Clear the requested range of rows from the local cache
156    * @param startingRowKey starting row key for the range to clear
157    * @param rowsToClear number of rows to clear from the cache
158    */
159   public void clearCachedRows(Object startingRowKey, int rowsToClear)
160   {
161     getCollectionModel().clearCachedRows(startingRowKey, rowsToClear);
162   }
163   
164   /**
165    * Clear a row from the local cache by row index
166    * @param index row index for the row to clear from the cache
167    */
168   public void clearCachedRow(int index)
169   {
170     getCollectionModel().clearCachedRow(index);
171   }
172   
173   /**
174    * Clear a row from the local cache by row key
175    * @param rowKey row key for the row to clear from the cache
176    */
177   public void clearCachedRow(Object rowKey)
178   {
179     getCollectionModel().clearCachedRow(rowKey);    
180   }
181   
182   /**
183    * Indicates the caching strategy supported by the model
184    * @see LocalCachingStrategy
185    * @return caching strategy supported by the model
186    */
187   public LocalRowKeyIndex.LocalCachingStrategy getCachingStrategy()
188   {
189     return getCollectionModel().getCachingStrategy();
190   }
191   
192   //
193   // below are the DataModel public APIs
194   //
195   public boolean isRowAvailable()
196   {
197     return getCollectionModel().isRowAvailable();
198   }
199 
200   public int getRowCount()
201   {
202     return getCollectionModel().getRowCount();
203   }
204 
205   public Object getRowData()
206   {
207     return getCollectionModel().getRowData();
208   }
209 
210   public int getRowIndex()
211   {
212     return getCollectionModel().getRowIndex();
213   }
214 
215   public void setRowIndex(int i)
216   {
217     getCollectionModel().setRowIndex(i);
218   }
219 
220   public Object getWrappedData()
221   {
222     return getCollectionModel().getWrappedData();
223   }
224 
225   public void setWrappedData(Object object)
226   {
227     getCollectionModel().setWrappedData(object);
228   }
229 
230   public void addDataModelListener(javax.faces.model.DataModelListener listener)
231   {
232     getCollectionModel().addDataModelListener(listener);
233   }
234 
235   public javax.faces.model.DataModelListener[] getDataModelListeners()
236   {
237     return getCollectionModel().getDataModelListeners();
238   }
239 
240   public void removeDataModelListener(javax.faces.model.DataModelListener listener)
241   {
242     getCollectionModel().removeDataModelListener(listener);
243   }
244 
245   /**
246    * This method returns the wrapped <code>CollectionModel</code>. 
247    * 
248    * @return the wrapped CollectionModel
249    */
250   protected abstract CollectionModel getCollectionModel();
251 }
252