X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmir%2Fentity%2FEntity.java;h=5a69e3e2915ec047dfb2f6489aa3e236dcdbdf62;hb=e368bbb50c99177c97d0f3c7de877accc014a4b3;hp=8dca5b13a6254f5f3c6c04dc96d50787c4d87f04;hpb=19e43122d238202f5026ae776893305bdcdafc7c;p=mir.git diff --git a/source/mir/entity/Entity.java b/source/mir/entity/Entity.java index 8dca5b13..5a69e3e2 100755 --- a/source/mir/entity/Entity.java +++ b/source/mir/entity/Entity.java @@ -36,43 +36,55 @@ package mir.entity; -import java.lang.*; -import java.io.*; -import java.util.*; -import java.sql.*; - -import freemarker.template.*; - -import mir.storage.*; -import mir.misc.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Set; + +import mir.config.MirPropertiesConfiguration; +import mir.config.MirPropertiesConfiguration.PropertiesConfigExc; +import mir.misc.Logfile; +import mir.misc.StringUtil; +import mir.storage.StorageObject; +import mir.storage.StorageObjectExc; +import mir.storage.StorageObjectFailure; +import freemarker.template.SimpleScalar; +import freemarker.template.TemplateHashModel; +import freemarker.template.TemplateModel; +import freemarker.template.TemplateModelException; +import freemarker.template.TemplateModelRoot; /** * Base Class of Entities * Interfacing TemplateHashModel and TemplateModelRoot to be freemarker compliant * - * @version $Id: Entity.java,v 1.10 2002/11/04 04:35:21 mh Exp $ + * @version $Id: Entity.java,v 1.13 2003/01/25 17:45:17 idfx Exp $ * @author rk * */ public class Entity implements TemplateHashModel, TemplateModelRoot { + protected static MirPropertiesConfiguration configuration; + protected static Logfile theLog; + private boolean changed; protected HashMap theValuesHash; // tablekey / value protected StorageObject theStorageObject; - protected static Logfile theLog; protected ArrayList streamedInput=null; - private static int instances = 0; - static { - theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("Entity.Logfile")); + + + static { + try { + configuration = MirPropertiesConfiguration.instance(); + } catch (PropertiesConfigExc e) { + e.printStackTrace(); + } + theLog = Logfile.getInstance(configuration.getStringWithHome("Entity.Logfile")); } public Entity() { - this.changed = false; - instances++; - Integer i = new Integer(instances); - //System.err.println("New abstract entity instance: "+i.toString()); } /** @@ -126,7 +138,7 @@ public class Entity implements TemplateHashModel, TemplateModelRoot * @return String Id */ public String getId () { - return (String)getValue(theStorageObject.getIdName()); + return (String) getValue(theStorageObject.getIdName()); } /** @@ -156,11 +168,6 @@ public class Entity implements TemplateHashModel, TemplateModelRoot if (hasValueForField("webdb_lastchange")) returnValue=StringUtil.dateToReadableDate(getValue("webdb_lastchange")); } - else if (field.equals("webdb_create_dc")) - { - if (hasValueForField("webdb_create")) - returnValue=StringUtil.webdbdateToDCDate(getValue("webdb_create")); - } else returnValue = (String)theValuesHash.get(field); } @@ -179,20 +186,20 @@ public class Entity implements TemplateHashModel, TemplateModelRoot * @return Primary Key of the Entity * @exception StorageObjectException */ - public String insert () throws StorageObjectException { + public String insert () throws StorageObjectExc { theLog.printDebugInfo("Entity: trying to insert ..."); if (theStorageObject != null) { return theStorageObject.insert((Entity)this); } else - throw new StorageObjectException("Kein StorageObject gesetzt!"); + throw new StorageObjectExc("Kein StorageObject gesetzt!"); } /** * Saves changes of this Entity to the database * @exception StorageObjectException */ - public void update () throws StorageObjectException { + public void update () throws StorageObjectFailure { theStorageObject.update((Entity)this); } @@ -204,7 +211,7 @@ public class Entity implements TemplateHashModel, TemplateModelRoot * @exception StorageObjectException */ public void setValueForProperty (String theProp, String theValue) - throws StorageObjectException { + throws StorageObjectFailure { this.changed = true; if (isField(theProp)) theValuesHash.put(theProp, theValue); @@ -219,7 +226,7 @@ public class Entity implements TemplateHashModel, TemplateModelRoot * @return ArrayList with field names * @exception StorageObjectException is throuwn if database access was impossible */ - public ArrayList getFields () throws StorageObjectException { + public ArrayList getFields () throws StorageObjectFailure { return theStorageObject.getFields(); } @@ -228,7 +235,7 @@ public class Entity implements TemplateHashModel, TemplateModelRoot * @return int[] that contains the types of the fields * @exception StorageObjectException */ - public int[] getTypes () throws StorageObjectException { + public int[] getTypes () throws StorageObjectFailure { return theStorageObject.getTypes(); } @@ -237,7 +244,7 @@ public class Entity implements TemplateHashModel, TemplateModelRoot * @return List with field names * @exception StorageObjectException */ - public ArrayList getLabels () throws StorageObjectException { + public ArrayList getLabels () throws StorageObjectFailure { return theStorageObject.getLabels(); } @@ -276,37 +283,19 @@ public class Entity implements TemplateHashModel, TemplateModelRoot * @return true in case fieldName is a field name, else false. * @exception StorageObjectException */ - public boolean isField (String fieldName) throws StorageObjectException { + public boolean isField (String fieldName) throws StorageObjectFailure { return theStorageObject.getFields().contains(fieldName); } - /** Returns the number of instances of this Entity - * @return int The number of instances - */ - public int getInstances() { - return instances; - } - protected void throwStorageObjectException (Exception e, String wo) throws StorageObjectException { + + protected void throwStorageObjectFailure (Exception e, String wo) + throws StorageObjectFailure { theLog.printError( e.toString() + " Funktion: "+ wo); - throw new StorageObjectException("Storage Object Exception in entity" +e.toString()); + e.printStackTrace(System.out); + throw new StorageObjectFailure("Storage Object Exception in entity", e); } - /** - * Frees an instance - */ - /*public void finalize () { - instances--; - Integer i = new Integer(instances); - System.err.println("Removing abstract entity instance: "+i.toString()); - try { - super.finalize(); - } catch (Throwable t) { - System.err.println(t.toString()); - } - }*/ - - // Now implements freemarkers TemplateHashModel // two methods have to be overridden: // 1. public boolean isEmpty() throws TemplateModelException @@ -319,10 +308,10 @@ public class Entity implements TemplateHashModel, TemplateModelRoot public TemplateModel get(java.lang.String key) throws TemplateModelException { - return new SimpleScalar(getValue(key)); + return new SimpleScalar(getValue(key)); } - - public void put(java.lang.String key, TemplateModel model) + + public void put(java.lang.String key, TemplateModel model) { // putting should only take place via setValue and is limited to the // database fields associated with the entity. no additional freemarker