compilable snapshot of ObjectStore / day two
authorrk <rk>
Tue, 19 Feb 2002 17:59:21 +0000 (17:59 +0000)
committerrk <rk>
Tue, 19 Feb 2002 17:59:21 +0000 (17:59 +0000)
source/mir/storage/store/ObjectStore.java
source/mir/storage/store/StoreContainer.java
source/mir/storage/store/StoreContainerType.java

index 26f2b5c..e719aad 100755 (executable)
@@ -36,8 +36,11 @@ public class ObjectStore {
   private static HashMap        containerMap=new HashMap(); // StoreContainerType/StoreContainer
   private static Logfile        storeLog;
   private static long           storeHit=0,storeMiss=0;
+  private static Class          storableObjectInterface;
 
-  private ObjectStore() { }
+  private ObjectStore() {
+    storableObjectInterface=StorableObject.class;
+  }
   public static ObjectStore getInstance() { return INSTANCE; }
 
 
@@ -99,5 +102,19 @@ public class ObjectStore {
     return null;
   }
 
+  private boolean implementsStorableObject(Class aClass) {
+    boolean yesno=false;
+    if (aClass!=null) {
+      Class[] interfaces = aClass.getInterfaces();
+      if (interfaces.length>0) {
+        for (int i=0;i<interfaces.length;i++) {
+          if (interfaces[i]==storableObjectInterface) return true;
+        }
+      }
+    }
+
+    return yesno;
+  }
+
   private String version() { return "prototype_daytwo";}
 }
\ No newline at end of file
index e863f00..d91b53a 100755 (executable)
@@ -24,6 +24,7 @@ public class StoreContainer {
   private LinkedList          container;
   private StoreContainerType  stocType;
   private int                 maxSize=DEFAULT_SIZE;
+  private static Logfile      storeLog;
 
   private StoreContainer() {};
 
index 0ddb034..72d2b50 100755 (executable)
@@ -1,35 +1,75 @@
 package mir.storage.store;
 
 /**
- * Title:
- * Description:
- * Copyright:    Copyright (c) 2002
- * Company:
- * @author
+ * Title:         StoreContainerType
+ *
+ * Description:   StoreContainerTypes are uniqe Objects and are generated
+ *                via @see valueOf(Class stocClass, int stocType).
+ *                For every combination of stocClass and stocType there is
+ *                only one Object instantiated.
+ *
+ * Copyright:     Copyright (c) 2002
+ * Company:       indy
+ *
+ * @author        rk
  * @version 1.0
  */
 
+import java.util.HashMap;
 import mir.misc.Logfile;
 
 public class StoreContainerType {
 
-  private final static int    STOC_TYPE_UNKNOWN=0;
-  private final static int    STOC_TYPE_ENTITY=1;
-  private final static int    STOC_TYPE_ENTITYLIST=2;
+  public final static int    STOC_TYPE_UNKNOWN=0;
+  public final static int    STOC_TYPE_ENTITY=1;
+  public final static int    STOC_TYPE_ENTITYLIST=2;
+
+  private static HashMap      uniqueTypes = new HashMap(); // StoreKey / StoreContainerType
   private static Logfile      storeLog;
+  private Class               stocClass=null;
+  private int                 stocType=STOC_TYPE_UNKNOWN;
 
+  private StoreContainerType() {}
 
-  private StoreContainerType() {
+  private StoreContainerType(Class stocClass, int stocType) {
+    this.stocClass=stocClass;
+    this.stocType=stocType;
   }
 
   public static StoreContainerType valueOf(Class stoc_class, int stoc_type) {
     /** @todo factory, only gives out types once to make them comparable via ==
       *   check if class is StorableObject */
-    return null;
+    StoreContainerType returnStocType=null;
+
+      // inner class for hashlookup
+      class StoreKey {
+        int   storeType;
+        Class storeClass;
+      }
+
+    StoreKey key = new StoreKey();
+    key.storeClass = stoc_class; key.storeType = stoc_type;
+    if (uniqueTypes.containsKey(key))
+      returnStocType=(StoreContainerType)uniqueTypes.get(key);
+    else {
+      returnStocType=new StoreContainerType(stoc_class,stoc_type);
+      uniqueTypes.put(key,returnStocType);
+    }
+    return returnStocType;
   }
 
   public String toString() {
-    return "";
+    StringBuffer sb = new StringBuffer("StoreContainerType: ");
+    sb.append(this.stocClass.toString()).append("@");
+    sb.append(stringForStoreType(stocType)).append("\n");
+    return sb.toString();
   }
 
+  private static String stringForStoreType(int stocType) {
+    switch(stocType) {
+      case STOC_TYPE_ENTITY: return "ENTITY";
+      case STOC_TYPE_ENTITYLIST: return "ENTITYLIST";
+      default: return "UNKNOWN";
+    }
+  }
 }
\ No newline at end of file