KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > projector > util > StoreHelper


1 package org.apache.slide.projector.util;
2
3 import java.io.IOException JavaDoc;
4 import java.util.Map JavaDoc;
5 import java.util.logging.Level JavaDoc;
6 import java.util.logging.Logger JavaDoc;
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 JavaDoc logger = Logger.getLogger(StoreHelper.class.getName());
14
15     public static Object JavaDoc get(Store store, String JavaDoc domain, String JavaDoc key) {
16         try {
17             MapValue mapResource = (MapValue)store.get(domain);
18             if ( mapResource != null ) {
19                 Map JavaDoc map = mapResource.getMap();
20                 return (Value)map.get(key);
21             }
22         } catch ( IOException JavaDoc 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 JavaDoc domain, String JavaDoc key, Value value) {
29         try {
30             MapValue mapResource = (MapValue)store.get(domain);
31             if ( mapResource != null ) {
32                 Map JavaDoc 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 JavaDoc exception ) {
39             logger.log(Level.SEVERE, "Error while accessing store", exception);
40         }
41     }
42     
43     public static int getStoreByName(String JavaDoc 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