01: package org.objectweb.celtix.bus.transports.jms;
02:
03: import java.util.Enumeration;
04: import java.util.Properties;
05: import java.util.logging.Level;
06: import java.util.logging.Logger;
07: import javax.naming.Context;
08: import javax.naming.InitialContext;
09: import javax.naming.NamingException;
10:
11: import org.objectweb.celtix.common.logging.LogUtils;
12: import org.objectweb.celtix.transports.jms.JMSAddressPolicyType;
13: import org.objectweb.celtix.transports.jms.JMSNamingPropertyType;
14:
15: public final class JMSUtils {
16:
17: private static final Logger LOG = LogUtils
18: .getL7dLogger(JMSUtils.class);
19:
20: private JMSUtils() {
21:
22: }
23:
24: public static Context getInitialContext(
25: JMSAddressPolicyType addrType) throws NamingException {
26: Properties env = new Properties();
27: populateContextEnvironment(addrType, env);
28:
29: if (LOG.isLoggable(Level.FINE)) {
30: Enumeration props = env.propertyNames();
31:
32: while (props.hasMoreElements()) {
33: String name = (String) props.nextElement();
34: String value = env.getProperty(name);
35: LOG.log(Level.FINE, "Context property: " + name + " | "
36: + value);
37: }
38: }
39:
40: Context context = new InitialContext(env);
41:
42: return context;
43: }
44:
45: protected static void populateContextEnvironment(
46: JMSAddressPolicyType addrType, Properties env) {
47:
48: java.util.ListIterator listIter = addrType
49: .getJMSNamingProperty().listIterator();
50:
51: while (listIter.hasNext()) {
52: JMSNamingPropertyType propertyPair = (JMSNamingPropertyType) listIter
53: .next();
54:
55: if (null != propertyPair.getValue()) {
56: env.setProperty(propertyPair.getName(), propertyPair
57: .getValue());
58: }
59: }
60: }
61: }
|