git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@908092 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Timothy A. Bish 2010-02-09 16:03:58 +00:00
parent fde472195f
commit 348f62e8cc
1 changed files with 60 additions and 60 deletions

View File

@ -26,79 +26,79 @@ import javax.naming.NamingException;
/** /**
* Configuration based on JNDI values. * Configuration based on JNDI values.
* *
* @version $Revision: $ * @version $Revision: $
*/ */
public class JNDIConfiguration extends AbstractConfiguration { public class JNDIConfiguration extends AbstractConfiguration {
private static final String JNDI_JMS_CONNECTION_FACTORY = "java:comp/env/jms/connectionFactory"; private static final String JNDI_JMS_CONNECTION_FACTORY = "java:comp/env/jms/connectionFactory";
private static final String JNDI_JMS_URL = "java:comp/env/jms/url"; private static final String JNDI_JMS_URL = "java:comp/env/jms/url";
private static final String JNDI_JMS_USER = "java:comp/env/jms/user"; private static final String JNDI_JMS_USER = "java:comp/env/jms/user";
private static final String JNDI_JMS_PASSWORD = "java:comp/env/jms/password"; private static final String JNDI_JMS_PASSWORD = "java:comp/env/jms/password";
private static final String JNDI_JMX_URL = "java:comp/env/jmx/url"; private static final String JNDI_JMX_URL = "java:comp/env/jmx/url";
private static final String JNDI_JMX_USER = "java:comp/env/jmx/user"; private static final String JNDI_JMX_USER = "java:comp/env/jmx/user";
private static final String JNDI_JMX_PASSWORD = "java:comp/env/jmx/password"; private static final String JNDI_JMX_PASSWORD = "java:comp/env/jmx/password";
private InitialContext context; private InitialContext context;
public JNDIConfiguration() throws NamingException { public JNDIConfiguration() throws NamingException {
this.context = new InitialContext(); this.context = new InitialContext();
} }
public JNDIConfiguration(InitialContext context) { public JNDIConfiguration(InitialContext context) {
this.context = context; this.context = context;
} }
public ConnectionFactory getConnectionFactory() { public ConnectionFactory getConnectionFactory() {
try { try {
ConnectionFactory connectionFactory = (ConnectionFactory) this.context ConnectionFactory connectionFactory = (ConnectionFactory) this.context
.lookup(JNDI_JMS_CONNECTION_FACTORY); .lookup(JNDI_JMS_CONNECTION_FACTORY);
return connectionFactory; return connectionFactory;
} catch (NameNotFoundException e) { } catch (NameNotFoundException e) {
// try to find an url // try to find an url
} catch (NamingException e) { } catch (NamingException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
try { try {
String jmsUrl = (String) this.context.lookup(JNDI_JMS_URL); String jmsUrl = (String) this.context.lookup(JNDI_JMS_URL);
if (jmsUrl == null) { if (jmsUrl == null) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"A JMS-url must be specified (system property " "A JMS-url must be specified (system property "
+ JNDI_JMS_URL); + JNDI_JMS_URL);
} }
String jmsUser = getJndiString(JNDI_JMS_USER); String jmsUser = getJndiString(JNDI_JMS_USER);
String jmsPassword = getJndiString(JNDI_JMS_PASSWORD); String jmsPassword = getJndiString(JNDI_JMS_PASSWORD);
return makeConnectionFactory(jmsUrl, jmsUser, jmsPassword); return makeConnectionFactory(jmsUrl, jmsUser, jmsPassword);
} catch (NameNotFoundException e) { } catch (NameNotFoundException e) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Neither a ConnectionFactory nor a JMS-url were specified"); "Neither a ConnectionFactory nor a JMS-url were specified");
} catch (NamingException e) { } catch (NamingException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
protected String getJndiString(String name) { protected String getJndiString(String name) {
try { try {
return (String) this.context.lookup(name); return (String) this.context.lookup(name);
} catch (NamingException e) { } catch (NamingException e) {
return null; return null;
} }
} }
public Collection<JMXServiceURL> getJmxUrls() { public Collection<JMXServiceURL> getJmxUrls() {
String jmxUrls = getJndiString(JNDI_JMX_URL); String jmxUrls = getJndiString(JNDI_JMX_URL);
return makeJmxUrls(jmxUrls); return makeJmxUrls(jmxUrls);
} }
public String getJmxPassword() { public String getJmxPassword() {
return getJndiString(JNDI_JMX_USER); return getJndiString(JNDI_JMX_PASSWORD);
} }
public String getJmxUser() { public String getJmxUser() {
return getJndiString(JNDI_JMX_PASSWORD); return getJndiString(JNDI_JMX_USER);
} }
} }