1 20 package org.apache.slide.projector.store; 21 22 import java.io.IOException ; 23 import java.util.HashMap ; 24 import java.util.Map ; 25 26 import org.apache.slide.projector.Projector; 27 import org.apache.slide.projector.Store; 28 import org.apache.slide.projector.value.MapValue; 29 30 public class ProcessStore extends AbstractStore { 31 private final static String STORAGE_PREFIX = "process/"; 32 33 private Store store; 34 private String processId, storageKey; 35 private Map map; 36 private MapValue mapResource; 37 38 public ProcessStore(Store store) { 39 this.store = store; 40 } 41 42 public String getProcessId() { 43 return processId; 44 } 45 46 public void setProcessId(String processId) { 47 this.processId = processId; 48 this.storageKey = Projector.getWorkDir()+STORAGE_PREFIX+processId; 49 } 50 51 public void put(String key, Object value) throws IOException { 52 getMap().put(key, value); 53 store.put(storageKey, mapResource); 54 } 55 56 public Object get(String key) throws IOException { 57 return getMap().get(key); 58 } 59 60 public void dispose(String key) throws IOException { 61 getMap().remove(key); 62 store.put(storageKey, mapResource); 63 } 64 65 private Map getMap() throws IOException { 66 if ( mapResource != null ) return mapResource.getMap(); 67 mapResource = (MapValue)store.get(storageKey); 68 if ( mapResource == null ) { 69 map = new HashMap (); 70 mapResource = new MapValue(map); 71 return map; 72 } else { 73 return mapResource.getMap(); 74 } 75 } 76 } | Popular Tags |