1 package org.objectweb.celtix.bus.ws.rm.persistence; 2 3 import java.util.HashMap ; 4 import java.util.Map ; 5 import java.util.logging.Logger ; 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 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 l) { 37 String storeClassName = s.getStoreClass(); 38 assert null != storeClassName; 39 Class <? extends RMStore> storeClass; 40 try { 41 storeClass = Class.forName(storeClassName, true, l).asSubclass(RMStore.class); 42 theStore = storeClass.newInstance(); 43 } catch (Exception ex) { 44 throw new RMStoreException(new Message("RMSTORE_CREATION_EXC", LOG), ex); 45 } 46 } 47 48 protected void initStore(StoreType s) { 49 Map <String , String > params = new HashMap <String , String >(); 50 for (StoreInitParamType sip : s.getInitParam()) { 51 String key = sip.getParamName(); 52 String 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 |