2 * The former (German) documentation of this classe
3 * stated that this class is an abstract one. There is,
4 * however, not a single abstract method in this class.
13 import freemarker.template.*;
20 * Container class for lists of Entities.
25 public class EntityList implements TemplateListModel {
27 private static Logfile theLog;
28 private ArrayList theEntityArrayList;
29 private String whereClause;
30 private String orderClause;
33 private int offsetnext = -1;
34 private int offsetprev = -1;
35 private int freemarkerListPointer=-1;
39 theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("Entity.Logfile"));
43 * Constructor. Creates an empty EntityList
46 this.theEntityArrayList = new ArrayList();
51 * Sets the WHERE clause that fetched the Entities of this EntityList from the database.
52 * @param wc The string that contains the WHERE clause
54 public void setWhere(String wc) {
55 this.whereClause = wc;
59 * Returns the WHERE clause that returned this EntityList from the database
60 * @return whereClause The WHERE clause
62 public String getWhere() {
68 * Sets the sorting criterium of this EntityList
71 public void setOrder(String oc) {
72 this.orderClause = oc;
76 * Returns the sorting criterium.
77 * @return orderClause The sort order
79 public String getOrder() {
84 * Sets the number of rows that match the WHERE clause
85 * @param i The number of rows that match the WHERE clause
87 public void setCount(int i) {
92 * Returns the number of rows that match the WHERE clause
93 * @return The number of rows ...
95 public int getCount() {
101 * @param i The offset
103 public void setOffset(int i) {
111 public int getOffset() {
116 * Sets the offset of the next batch of Entities.
117 * @param i The next offset
119 public void setNextBatch(int i) {
124 * Returns the offset of the next batch of Entities.
125 * @return offset of the next batch
127 public int getNextBatch() {
132 * Returns whether there is a next batch within the WHERE clause
133 * @return true if yes, false if no.
135 public boolean hasNextBatch() {
136 return (offsetnext >= 0);
140 * Sets the offset of the previous batch.
141 * @param i the previous offset
143 public void setPrevBatch(int i) {
148 * Returns the offset of the previous batch.
149 * @return offset of the previous batch
151 public int getPrevBatch() {
156 * Returns whether there is a previous batch.
157 * @return true if yes, false if no
159 public boolean hasPrevBatch() {
160 return (offsetprev >= 0);
164 * Returns the start index of the batch.
167 public int getFrom() {
172 * Returns the end index of the batch.
183 * Inserts an Entity into the EntityList.
184 * @param anEntity The entity to be inserted.
187 public void add (Entity anEntity) {
189 theEntityArrayList.add(anEntity);
191 theLog.printWarning("EntityList: add called with empty Entity");
196 * @return The number of Entities in the EntityList.
200 return theEntityArrayList.size();
205 * Returns the element at position i in the EntityList as Entity
206 * @param i the position of the element in question
207 * @return The element at position i.
210 public Entity elementAt(int i) {
211 /** @todo check if i is in list.size() */
212 return (Entity)theEntityArrayList.get(i);
216 // The following methods have to be implemented
217 // for this class to be an implementation of the
218 // TemplateListModel of the Freemarker packages
220 public TemplateModel get(int i) { return elementAt(i); }
221 public boolean isRewound() { return (freemarkerListPointer==-1) ? true : false; }
222 public void rewind() { freemarkerListPointer=-1; }
224 public TemplateModel next() {
226 freemarkerListPointer++;return get(freemarkerListPointer); }
232 * Returns whether there is a next element
233 * @return true if there is a next element, else false
236 public boolean hasNext() {
237 return theEntityArrayList.size()>0 && freemarkerListPointer+2<=theEntityArrayList.size();
242 * Returns whether EntityList is empty or not
243 * @return true in case of empty list, false otherwise
246 public boolean isEmpty() {
247 if (theEntityArrayList!=null)
248 return theEntityArrayList.size()<1 ;