1 19 package org.netbeans.mdr.persistence.memoryimpl; 20 21 import java.util.HashMap ; 22 import java.util.Map ; 23 import org.netbeans.mdr.persistence.*; 24 25 30 public class StorageFactoryImpl extends Object implements StorageFactory { 31 public static final String STORAGE_ID = "org.netbeans.mdr.persistence.memoryimpl.id"; 32 public static final String STORAGE_NAME = "org.netbeans.mdr.persistence.memoryimpl.fileName"; 33 static final String NULL_STORAGE_ID = "."; 34 private static final MOFID NULL_MOFID = new MOFID(0, NULL_STORAGE_ID); 35 36 private StorageImpl nullStorage; 37 38 private static final HashMap storages = new HashMap (); 39 40 41 public StorageFactoryImpl() { 42 } 43 44 47 public synchronized Storage createStorage(Map properties) throws StorageException { 48 String name = (String ) properties.get(STORAGE_ID); if (name == null || name.equals(NULL_STORAGE_ID)) { 50 if (nullStorage == null) { 51 nullStorage = new StorageImpl(NULL_STORAGE_ID, null); 52 } 53 return nullStorage; 54 } else { 55 synchronized (storages) { 56 if (storages.containsKey(name)) { 57 throw new RuntimeException ("Storage '" + name + "' already created."); 58 } else { 59 Storage result = new StorageImpl(name, (String ) properties.get(STORAGE_NAME)); 60 storages.put(name, result); 61 return result; 62 } 63 } 64 } 65 } 66 67 69 public static boolean serialize(String storageId) throws StorageException { 70 StorageImpl storage; 71 synchronized (storages) { 72 storage = (StorageImpl) storages.get(storageId); 73 } 74 if (storage == null) { 75 return false; 76 } 77 storage.serialize(); 78 return true; 79 } 80 81 public org.netbeans.mdr.persistence.MOFID createNullMOFID() throws StorageException { 82 return NULL_MOFID; 83 } 84 } 85 | Popular Tags |