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 */ 017package org.apache.activemq.command; 018 019import javax.jms.JMSException; 020import org.apache.activemq.ActiveMQConnection; 021import org.slf4j.Logger; 022import org.slf4j.LoggerFactory; 023 024/** 025 * @openwire:marshaller 026 * 027 */ 028public abstract class ActiveMQTempDestination extends ActiveMQDestination { 029 030 private static final Logger LOG = LoggerFactory.getLogger(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 if (connection != null) { 052 connection.deleteTempDestination(this); 053 } 054 } 055 056 public ActiveMQConnection getConnection() { 057 return connection; 058 } 059 060 public void setConnection(ActiveMQConnection connection) { 061 this.connection = connection; 062 } 063 064 public void setPhysicalName(String physicalName) { 065 super.setPhysicalName(physicalName); 066 if (!isComposite()) { 067 // Parse off the sequenceId off the end. 068 // this can fail if the temp destination is 069 // generated by another JMS system via the JMS<->JMS Bridge 070 int p = this.physicalName.lastIndexOf(":"); 071 if (p >= 0) { 072 String seqStr = this.physicalName.substring(p + 1).trim(); 073 if (seqStr != null && seqStr.length() > 0) { 074 try { 075 sequenceId = Integer.parseInt(seqStr); 076 } catch (NumberFormatException e) { 077 LOG.debug("Did not parse sequence Id from " + physicalName); 078 } 079 // The rest should be the connection id. 080 connectionId = this.physicalName.substring(0, p); 081 } 082 } 083 } 084 } 085 086 public String getConnectionId() { 087 return connectionId; 088 } 089 090 public void setConnectionId(String connectionId) { 091 this.connectionId = connectionId; 092 } 093 094 public int getSequenceId() { 095 return sequenceId; 096 } 097}