001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.activemq.command;
018    
019    import javax.jms.JMSException;
020    import org.apache.activemq.ActiveMQConnection;
021    import org.apache.commons.logging.Log;
022    import org.apache.commons.logging.LogFactory;
023    
024    /**
025     * @openwire:marshaller
026     * @version $Revision: 1.5 $
027     */
028    public abstract class ActiveMQTempDestination extends ActiveMQDestination {
029    
030        private static final Log LOG = LogFactory.getLog(ActiveMQTempDestination.class);
031        protected transient ActiveMQConnection connection;
032        protected transient String connectionId;
033        protected transient int sequenceId;
034    
035        public ActiveMQTempDestination() {
036        }
037    
038        public ActiveMQTempDestination(String name) {
039            super(name);
040        }
041    
042        public ActiveMQTempDestination(String connectionId, long sequenceId) {
043            super(connectionId + ":" + sequenceId);
044        }
045    
046        public boolean isTemporary() {
047            return true;
048        }
049    
050        public void delete() throws JMSException {
051            connection.deleteTempDestination(this);
052        }
053    
054        public ActiveMQConnection getConnection() {
055            return connection;
056        }
057    
058        public void setConnection(ActiveMQConnection connection) {
059            this.connection = connection;
060        }
061    
062        public void setPhysicalName(String physicalName) {
063            super.setPhysicalName(physicalName);
064            if (!isComposite()) {
065                // Parse off the sequenceId off the end.
066                // this can fail if the temp destination is
067                // generated by another JMS system via the JMS<->JMS Bridge
068                int p = this.physicalName.lastIndexOf(":");
069                if (p >= 0) {
070                    String seqStr = this.physicalName.substring(p + 1).trim();
071                    if (seqStr != null && seqStr.length() > 0) {
072                        try {
073                            sequenceId = Integer.parseInt(seqStr);
074                        } catch (NumberFormatException e) {
075                            LOG.debug("Did not parse sequence Id from " + physicalName);
076                        }
077                        // The rest should be the connection id.
078                        connectionId = this.physicalName.substring(0, p);
079                    }
080                }
081            }
082        }
083    
084        public String getConnectionId() {
085            return connectionId;
086        }
087    
088        public void setConnectionId(String connectionId) {
089            this.connectionId = connectionId;
090        }
091    
092        public int getSequenceId() {
093            return sequenceId;
094        }
095    }