1 package mir.storage.store;
4 * Title: StoreContainerType
6 * Description: StoreContainerTypes are uniqe Objects and are generated
7 * via @see valueOf(Class stocClass, int stocType).
8 * For every combination of stocClass and stocType there is
9 * only one Object instantiated.
11 * Copyright: Copyright (c) 2002
18 import java.util.HashMap;
19 import mir.misc.Logfile;
21 public class StoreContainerType {
23 public final static int STOC_TYPE_UNKNOWN=0;
24 public final static int STOC_TYPE_ENTITY=1;
25 public final static int STOC_TYPE_ENTITYLIST=2;
27 private static HashMap uniqueTypes = new HashMap(); // StoreKey / StoreContainerType
28 private static Logfile storeLog;
29 private Class stocClass=null;
30 private int stocType=STOC_TYPE_UNKNOWN;
32 private StoreContainerType() {}
34 private StoreContainerType(Class stocClass, int stocType) {
35 this.stocClass=stocClass;
36 this.stocType=stocType;
39 public static StoreContainerType valueOf(Class stoc_class, int stoc_type) {
40 /** @todo factory, only gives out types once to make them comparable via ==
41 * check if class is StorableObject */
42 StoreContainerType returnStocType=null;
44 // inner class for hashlookup
50 StoreKey key = new StoreKey();
51 key.storeClass = stoc_class; key.storeType = stoc_type;
52 if (uniqueTypes.containsKey(key))
53 returnStocType=(StoreContainerType)uniqueTypes.get(key);
55 returnStocType=new StoreContainerType(stoc_class,stoc_type);
56 uniqueTypes.put(key,returnStocType);
58 return returnStocType;
61 public String toString() {
62 StringBuffer sb = new StringBuffer("StoreContainerType: ");
63 sb.append(this.stocClass.toString()).append("@");
64 sb.append(stringForStoreType(stocType)).append("\n");
68 private static String stringForStoreType(int stocType) {
70 case STOC_TYPE_ENTITY: return "ENTITY";
71 case STOC_TYPE_ENTITYLIST: return "ENTITYLIST";
72 default: return "UNKNOWN";