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; }
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
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