EntityList now freemarker compliant. Deprecated makeSimpleList(EntityList)
[mir.git] / source / mir / entity / EntityList.java
index 303917d..77e5969 100755 (executable)
@@ -7,6 +7,9 @@ package  mir.entity;
 
 import java.lang.*;
 import java.util.*;
+
+import freemarker.template.*;
+
 import mir.misc.*;
 
 
@@ -17,23 +20,28 @@ import mir.misc.*;
  * @author <RK>
  * @version    27.6.1999
  */
-public class EntityList {
-               private static Logfile     theLog;
-               private ArrayList          theEntityArrayList;
-               private String             whereClause;
-               private String             orderClause;
-               private int                count;
-               private int                offset;
-               private int                offsetnext = -1;
-               private int                offsetprev = -1;
+public class EntityList implements TemplateListModel {
+
+  private static Logfile     theLog;
+  private ArrayList          theEntityArrayList;
+  private String             whereClause;
+  private String             orderClause;
+  private int                count;
+  private int                offset;
+  private int                offsetnext = -1;
+  private int                offsetprev = -1;
+  private int                freemarkerListPointer=-1;
+
+
+  static {
+    theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("Entity.Logfile"));
+  }
 
        /**
         * Konstruktor für leere Liste von Entities
         */
                public EntityList(){
                        this.theEntityArrayList = new ArrayList();
-                       if (theLog == null)
-                        this.theLog = Logfile.getInstance(this.getClass().getName());
                }
 
        /**
@@ -173,27 +181,46 @@ public class EntityList {
         * Fügt eine Entity in die Liste ein
         * @param anEntity
         */
-       public void add (Entity anEntity) {
-       if (anEntity!=null)
-                       theEntityArrayList.add(anEntity);
-       else
-                       theLog.printWarning("add (EntityList) mit leerer Entity");
-               }
+  public void add (Entity anEntity) {
+    if (anEntity!=null)
+        theEntityArrayList.add(anEntity);
+    else
+                       theLog.printWarning("EntityList: add called with empty Entity");
+  }
 
        /**
         * @return Anzahl der Entities in der Liste
         */
-               public int size() {
-       return theEntityArrayList.size();
-               }
+  public int size() {
+    return theEntityArrayList.size();
+  }
 
 
+  public Entity elementAt(int i) {
+    /** @todo check if i is in list.size() */
+    return (Entity)theEntityArrayList.get(i);
+  }
 
 
+  // Freemarker TemplateListModel methods
 
+  public TemplateModel get(int i){ return elementAt(i); }
+  public boolean isRewound() { return (freemarkerListPointer==-1) ? true : false; }
+  public void rewind() { freemarkerListPointer=-1; }
 
-               public Entity elementAt(int i) {
-                       return (Entity)theEntityArrayList.get(i);
-               }
+  public TemplateModel next() {
+    if (hasNext()) { freemarkerListPointer++;return get(freemarkerListPointer); }
+    else return null;
+  }
+
+  public boolean hasNext() {
+    return theEntityArrayList.size()>0 && freemarkerListPointer+2<=theEntityArrayList.size();
+  }
+
+  public boolean isEmpty() {
+    if (theEntityArrayList!=null)
+      return theEntityArrayList.size()>0 ;
+    else return false;
+  }
 
 }