KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > bus > transports > jms > JMSUtils


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