producerContent debugging / pageCount inserted
[mir.git] / source / mir / entity / EntityList.java
1 /*
2  * put your module comment here
3  */
4
5
6 package  mir.entity;
7
8 import java.lang.*;
9 import java.util.*;
10
11 import freemarker.template.*;
12
13 import mir.misc.*;
14
15
16 /**
17  *
18  * abstrakte Containerklasse für Listen von Entities.
19  *
20  * @author <RK>
21  * @version     27.6.1999
22  */
23 public class EntityList implements TemplateListModel {
24
25   private static Logfile     theLog;
26   private ArrayList          theEntityArrayList;
27   private String             whereClause;
28   private String             orderClause;
29   private int                count;
30   private int                offset;
31   private int                offsetnext = -1;
32   private int                offsetprev = -1;
33   private int                freemarkerListPointer=-1;
34
35
36   static {
37     theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("Entity.Logfile"));
38   }
39
40         /**
41          * Konstruktor für leere Liste von Entities
42          */
43                 public EntityList(){
44                         this.theEntityArrayList = new ArrayList();
45                 }
46
47         /**
48          * Setzt die WhereClause, mit der die Entitis dieser Liste geholt wurden.
49          * @param wc
50          */
51                 public void setWhere(String wc) {
52                         this.whereClause = wc;
53                 }
54
55         /**
56          * Liefert die WhereClause zurueck, mit der die Entities geholt wurden.
57          * @return whereClause
58          */
59                 public String getWhere() {
60                         return whereClause;
61                 }
62
63         /**
64          * Setzt das Sortierkriterium fest, mit der die Entities in die Liste
65          * gestellt wurden.
66          *
67          * @param oc
68          */
69                 public void setOrder(String oc) {
70                         this.orderClause = oc;
71                 }
72
73         /**
74          * Liefert das Sortierkriterium der Liste zurueck.
75          * @return orderClause
76          */
77                 public String getOrder() {
78                         return orderClause;
79                 }
80
81         /**
82          * Setzt die Anzahl der Datensätze fest, die WhereClause erfüllen.
83          * @param i
84          */
85                 public void setCount(int i) {
86                         this.count = i;
87                 }
88
89         /**
90          * Liefert Anzahle der Datensätze, die WhereClause erfüllen.
91          * @return
92          */
93                 public int getCount() {
94                         return count;
95                 }
96
97         /**
98          * Setzt den Offset fest.
99          * @param i
100          */
101                 public void setOffset(int i) {
102                         offset = i;
103                 }
104
105         /**
106          * Liefert den Offset zurueck
107          * @return offset
108          */
109                 public int getOffset() {
110                         return offset;
111                 }
112
113         /**
114          * Setzt den offset für das naechste Batch von Entities fest.
115          * @param i
116          */
117                 public void setNextBatch(int i) {
118                         offsetnext = i;
119                 }
120
121         /**
122          * Liefert den offset für das naechste Batch von Entities
123          * @return offset für naechstes Batch
124          */
125                 public int getNextBatch() {
126                         return offsetnext;
127                 }
128
129         /**
130          * Fragt ab, ob es noch nachfolgendes Batch innerhalb der WhereClause gibt
131          * @return
132          */
133                 public boolean hasNextBatch() {
134                         return (offsetnext >= 0);
135                 }
136
137         /**
138          * Setzt offset des vorhergehenden Batches fest.
139          * @param i
140          */
141                 public void setPrevBatch(int i) {
142                         offsetprev = i;
143                 }
144
145         /**
146          * Liefert offset des vorhergehenden Batches zurueck.
147          * @return offset des vorhergehenden Batches.
148          */
149                 public int getPrevBatch() {
150                         return offsetprev;
151                 }
152
153         /**
154          * Fragt ab, ob es ein vorhergehendes Batch gibt
155          * @return true wenn ja, sont false
156          */
157                 public boolean hasPrevBatch() {
158                         return (offsetprev >= 0);
159                 }
160
161         /**
162          * Liefert den Startindex des Batches zurueck.
163          * @return
164          */
165                 public int getFrom() {
166                         return offset+1;
167                 }
168
169         /**
170          * Liefert den Endindex des Batches zurueck.
171          * @return
172          */
173                 public int getTo() {
174         if (hasNextBatch())
175                         return offsetnext;
176         else
177                         return count;
178                 }
179
180         /**
181          * Fügt eine Entity in die Liste ein
182          * @param anEntity
183          */
184   public void add (Entity anEntity) {
185     if (anEntity!=null)
186         theEntityArrayList.add(anEntity);
187     else
188                         theLog.printWarning("EntityList: add called with empty Entity");
189   }
190
191         /**
192          * @return Anzahl der Entities in der Liste
193          */
194   public int size() {
195     return theEntityArrayList.size();
196   }
197
198
199   public Entity elementAt(int i) {
200     /** @todo check if i is in list.size() */
201     return (Entity)theEntityArrayList.get(i);
202   }
203
204
205   // Freemarker TemplateListModel methods
206
207   public TemplateModel get(int i) { return elementAt(i); }
208   public boolean isRewound() { return (freemarkerListPointer==-1) ? true : false; }
209   public void rewind() { freemarkerListPointer=-1; }
210
211   public TemplateModel next() {
212     if (hasNext()) {
213       freemarkerListPointer++;return get(freemarkerListPointer); }
214     else return null;
215   }
216
217   public boolean hasNext() {
218     return theEntityArrayList.size()>0 && freemarkerListPointer+2<=theEntityArrayList.size();
219   }
220
221   public boolean isEmpty() {
222     if (theEntityArrayList!=null)
223       return theEntityArrayList.size()<1 ;
224     else return false;
225   }
226
227 }