1 package org.apache.slide.projector.util; 2 3 import java.io.IOException ; 4 import java.util.Map ; 5 import java.util.logging.Level ; 6 import java.util.logging.Logger ; 7 8 import org.apache.slide.projector.Store; 9 import org.apache.slide.projector.value.MapValue; 10 import org.apache.slide.projector.value.Value; 11 12 public class StoreHelper { 13 private static Logger logger = Logger.getLogger(StoreHelper.class.getName()); 14 15 public static Object get(Store store, String domain, String key) { 16 try { 17 MapValue mapResource = (MapValue)store.get(domain); 18 if ( mapResource != null ) { 19 Map map = mapResource.getMap(); 20 return (Value)map.get(key); 21 } 22 } catch ( IOException exception ) { 23 logger.log(Level.SEVERE, "Error while accessing store", exception); 24 } 25 return null; 26 } 27 28 public static void put(Store store, String domain, String key, Value value) { 29 try { 30 MapValue mapResource = (MapValue)store.get(domain); 31 if ( mapResource != null ) { 32 Map map = mapResource.getMap(); 33 map.put(key, value); 34 } else { 35 mapResource = new MapValue(key, value); 36 store.put(domain, mapResource); 37 } 38 } catch ( IOException exception ) { 39 logger.log(Level.SEVERE, "Error while accessing store", exception); 40 } 41 } 42 43 public static int getStoreByName(String store) { 44 for ( int i = 0; i < Store.stores.length; i++ ) { 45 if ( Store.stores[i].equals(store) ) return i; 46 } 47 return Store.NONE; 48 } 49 } | Popular Tags |