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=-1;
+ public final static int STOC_TYPE_ENTITY=0;
+ public final static int STOC_TYPE_ENTITYLIST=1;
+ public final static int STOC_TYPE_MAX=STOC_TYPE_ENTITYLIST;
+ private static HashMap[] uniqueTypes=new HashMap[STOC_TYPE_MAX+1];
+ private static Logfile storeLog;
+ private Class stocClass=null;
+ private int stocType=STOC_TYPE_UNKNOWN;
- private StoreContainerType() {
- }
+ static {
+ uniqueTypes[STOC_TYPE_ENTITY]= new HashMap();
+ uniqueTypes[STOC_TYPE_ENTITYLIST]=new HashMap();
- 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;
}
- public String toString() {
- return "";
- }
+ private StoreContainerType() {}
+
+ private StoreContainerType(Class stocClass, int stocType) {
+ this.stocClass=stocClass;
+ this.stocType=stocType;
+ }
+
+ public static StoreContainerType valueOf(Class stoc_class, int stoc_type) {
+ StoreContainerType returnStocType=null;
+ if (stoc_type>=0 && stoc_type <= STOC_TYPE_MAX) {
+ HashMap current = uniqueTypes[stoc_type];
+ if ( current.containsKey(stoc_class) )
+ returnStocType=(StoreContainerType)current.get(stoc_class);
+ else {
+ returnStocType=new StoreContainerType(stoc_class,stoc_type);
+ current.put(stoc_class,returnStocType);
+ }
+ }
+ return returnStocType;
+ }
+
+ public int getStocType() { return stocType; }
+ public Class getStocClass() { return stocClass; }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer(this.stocClass.toString());
+ sb.append("@").append(stringForStoreType(stocType));
+ 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