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;
- private static Logfile storeLog;
+ 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() {}
- 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;
- }
+ private StoreContainerType(Class stocClass, int stocType) {
+ this.stocClass=stocClass;
+ this.stocType=stocType;
+ }
- public String toString() {
- return "";
- }
+ 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 */
+ 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() {
+ 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