01: package org.objectweb.celtix.bus.ws.rm.persistence;
02:
03: import java.util.HashMap;
04: import java.util.Map;
05: import java.util.logging.Logger;
06:
07: import org.objectweb.celtix.bus.configuration.wsrm.StoreInitParamType;
08: import org.objectweb.celtix.bus.configuration.wsrm.StoreType;
09: 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 LOG = LogUtils
18: .getL7dLogger(RMStoreFactory.class);
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 l) {
37: String storeClassName = s.getStoreClass();
38: assert null != storeClassName;
39: Class<? extends RMStore> storeClass;
40: try {
41: storeClass = Class.forName(storeClassName, true, l)
42: .asSubclass(RMStore.class);
43: theStore = storeClass.newInstance();
44: } catch (Exception ex) {
45: throw new RMStoreException(new Message(
46: "RMSTORE_CREATION_EXC", LOG), ex);
47: }
48: }
49:
50: protected void initStore(StoreType s) {
51: Map<String, String> params = new HashMap<String, String>();
52: for (StoreInitParamType sip : s.getInitParam()) {
53: String key = sip.getParamName();
54: String value = sip.getParamValue();
55: if (null != key && null != value) {
56: params.put(key, value);
57: }
58: }
59: theStore.init(params);
60: }
61:
62: }
|