diff --git a/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java b/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java index 4f8f6fa593..6d794e9538 100755 --- a/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java @@ -20,6 +20,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.Map; import java.util.Properties; +import java.util.Enumeration; import javax.jms.Connection; import javax.jms.ConnectionFactory; @@ -29,6 +30,9 @@ import javax.jms.QueueConnectionFactory; import javax.jms.TopicConnection; import javax.jms.TopicConnectionFactory; import javax.naming.Context; +import javax.naming.Referenceable; +import javax.naming.Reference; +import javax.naming.NamingException; import org.apache.activemq.management.JMSStatsImpl; import org.apache.activemq.management.StatsCapable; @@ -53,7 +57,7 @@ import edu.emory.mathcs.backport.java.util.concurrent.ThreadFactory; * @version $Revision: 1.9 $ * @see javax.jms.ConnectionFactory */ -public class ActiveMQConnectionFactory implements ConnectionFactory, QueueConnectionFactory, TopicConnectionFactory, StatsCapable { +public class ActiveMQConnectionFactory implements ConnectionFactory, QueueConnectionFactory, TopicConnectionFactory, StatsCapable, Referenceable { public static final String DEFAULT_BROKER_URL = "tcp://localhost:61616"; public static final String DEFAULT_USER = null; @@ -377,6 +381,25 @@ public class ActiveMQConnectionFactory implements ConnectionFactory, QueueConnec } } + public Properties getProperties() { + Properties props = new Properties(); + props.setProperty("asyncDispatch", Boolean.toString(isAsyncDispatch())); + props.setProperty("brokerURL", getBrokerURL()); + props.setProperty("clientID", getClientID()); + props.setProperty("copyMessageOnSend", Boolean.toString(isCopyMessageOnSend())); + props.setProperty("disableTimeStampsByDefault", Boolean.toString(isDisableTimeStampsByDefault())); + props.setProperty("objectMessageSerializationDefered", Boolean.toString(isObjectMessageSerializationDefered())); + props.setProperty("onSendPrepareMessageBody", Boolean.toString(isOnSendPrepareMessageBody())); + props.setProperty("optimizedMessageDispatch", Boolean.toString(isOptimizedMessageDispatch())); + props.setProperty("password", getPassword()); + props.setProperty("useAsyncSend", Boolean.toString(isUseAsyncSend())); + props.setProperty("useCompression", Boolean.toString(isUseCompression())); + props.setProperty("useRetroactiveConsumer", Boolean.toString(isUseRetroactiveConsumer())); + props.setProperty("username", getUserName()); + + return props; + } + public boolean isOnSendPrepareMessageBody() { return onSendPrepareMessageBody; } @@ -409,4 +432,27 @@ public class ActiveMQConnectionFactory implements ConnectionFactory, QueueConnec this.asyncDispatch = asyncDispatch; } + /** + * Retrieve a Reference for this instance to store in JNDI + * + * @return the built Reference + * @throws NamingException if error on building Reference + */ + public Reference getReference() throws NamingException { + Reference ref = new Reference(this.getClass().getName()); + + try { + Properties props = getProperties(); + for (Enumeration iter = props.propertyNames(); iter.hasMoreElements();) { + String key = (String) iter.nextElement(); + String value = props.getProperty(key); + javax.naming.StringRefAddr addr = new javax.naming.StringRefAddr(key, value); + ref.add(addr); + } + } catch (Exception e) { + throw new NamingException(e.getMessage()); + } + return ref; + } + } diff --git a/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQDestination.java b/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQDestination.java index e7e8984b57..9891841101 100755 --- a/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQDestination.java +++ b/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQDestination.java @@ -25,6 +25,8 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.Map; import java.util.StringTokenizer; +import java.util.Properties; +import java.util.Enumeration; import javax.jms.Destination; import javax.jms.JMSException; @@ -32,6 +34,9 @@ import javax.jms.Queue; import javax.jms.TemporaryQueue; import javax.jms.TemporaryTopic; import javax.jms.Topic; +import javax.naming.Reference; +import javax.naming.NamingException; +import javax.naming.Referenceable; import org.apache.activemq.util.URISupport; @@ -39,7 +44,7 @@ import org.apache.activemq.util.URISupport; * @openwire:marshaller * @version $Revision: 1.10 $ */ -abstract public class ActiveMQDestination implements DataStructure, Destination, Externalizable, Comparable { +abstract public class ActiveMQDestination implements DataStructure, Destination, Externalizable, Comparable, Referenceable { private static final long serialVersionUID = -3885260014960795889L; @@ -330,4 +335,43 @@ abstract public class ActiveMQDestination implements DataStructure, Destination, return false; } + public Properties getProperties() { + Properties props = new Properties(); + + props.setProperty("composite", Boolean.toString(isComposite())); + props.setProperty("destinationType", Byte.toString(getDestinationType())); + props.setProperty("destinationTypeAsString", getDestinationTypeAsString()); + props.setProperty("marshallAware", Boolean.toString(isMarshallAware())); + props.setProperty("physicalName", getPhysicalName()); + props.setProperty("qualifiedName", getQualifiedName()); + props.setProperty("qualifiedPrefix", getQualifiedPrefix()); + props.setProperty("queue", Boolean.toString(isQueue())); + props.setProperty("temporary", Boolean.toString(isTemporary())); + props.setProperty("topic", Boolean.toString(isTopic())); + + return props; + } + + /** + * Retrieve a Reference for this instance to store in JNDI + * + * @return the built Reference + * @throws javax.naming.NamingException if error on building Reference + */ + public Reference getReference() throws NamingException { + Reference ref = new Reference(this.getClass().getName()); + + try { + Properties props = getProperties(); + for (Enumeration iter = props.propertyNames(); iter.hasMoreElements();) { + String key = (String) iter.nextElement(); + String value = props.getProperty(key); + javax.naming.StringRefAddr addr = new javax.naming.StringRefAddr(key, value); + ref.add(addr); + } + } catch (Exception e) { + throw new NamingException(e.getMessage()); + } + return ref; + } }