KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > bus > ws > rm > persistence > RMStoreFactory


1 package org.objectweb.celtix.bus.ws.rm.persistence;
2
3 import java.util.HashMap JavaDoc;
4 import java.util.Map JavaDoc;
5 import java.util.logging.Logger JavaDoc;
6
7 import org.objectweb.celtix.bus.configuration.wsrm.StoreInitParamType;
8 import org.objectweb.celtix.bus.configuration.wsrm.StoreType;
9 import org.objectweb.celtix.common.i18n.Message;
10 import org.objectweb.celtix.common.logging.LogUtils;
11 import org.objectweb.celtix.configuration.Configuration;
12 import org.objectweb.celtix.ws.rm.persistence.RMStore;
13
14 public class RMStoreFactory {
15     
16     protected static RMStore theStore;
17     private static final Logger JavaDoc LOG = LogUtils.getL7dLogger(RMStoreFactory.class);
18     
19     
20     public RMStore getStore(Configuration c) {
21         
22         StoreType s = c.getObject(StoreType.class, "store");
23         assert null != s;
24         
25         if (null == theStore) {
26             createStore(s);
27             initStore(s);
28         }
29         return theStore;
30     }
31     
32     protected void createStore(StoreType s) {
33         createStore(s, RMStoreFactory.class.getClassLoader());
34     }
35     
36     protected void createStore(StoreType s, ClassLoader JavaDoc l) {
37         String JavaDoc storeClassName = s.getStoreClass();
38         assert null != storeClassName;
39         Class JavaDoc<? extends RMStore> storeClass;
40         try {
41             storeClass = Class.forName(storeClassName, true, l).asSubclass(RMStore.class);
42             theStore = storeClass.newInstance();
43         } catch (Exception JavaDoc ex) {
44             throw new RMStoreException(new Message("RMSTORE_CREATION_EXC", LOG), ex);
45         }
46     }
47     
48     protected void initStore(StoreType s) {
49         Map JavaDoc<String JavaDoc, String JavaDoc> params = new HashMap JavaDoc<String JavaDoc, String JavaDoc>();
50         for (StoreInitParamType sip : s.getInitParam()) {
51             String JavaDoc key = sip.getParamName();
52             String JavaDoc value = sip.getParamValue();
53             if (null != key && null != value) {
54                 params.put(key, value);
55             }
56         }
57         theStore.init(params);
58     }
59     
60     
61 }
62
Popular Tags