1 package org.objectweb.celtix.bus.transports.jms; 2 3 4 import java.util.Enumeration ; 5 import java.util.Properties ; 6 import java.util.logging.Level ; 7 import java.util.logging.Logger ; 8 import javax.naming.Context ; 9 import javax.naming.InitialContext ; 10 import javax.naming.NamingException ; 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 LOG = LogUtils.getL7dLogger(JMSUtils.class); 20 21 private JMSUtils() { 22 23 } 24 25 public static Context getInitialContext(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 + " | " + value); 36 } 37 } 38 39 Context context = new InitialContext (env); 40 41 return context; 42 } 43 44 45 protected static void populateContextEnvironment(JMSAddressPolicyType addrType, Properties env) { 46 47 java.util.ListIterator 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 |