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    /**
020     * @openwire:marshaller code="120"
021     * 
022     */
023    public class ConnectionId implements DataStructure, Comparable<ConnectionId> {
024    
025        public static final byte DATA_STRUCTURE_TYPE = CommandTypes.CONNECTION_ID;
026    
027        protected String value;
028    
029        public ConnectionId() {
030        }
031    
032        public ConnectionId(String connectionId) {
033            this.value = connectionId;
034        }
035    
036        public ConnectionId(ConnectionId id) {
037            this.value = id.getValue();
038        }
039    
040        public ConnectionId(SessionId id) {
041            this.value = id.getConnectionId();
042        }
043    
044        public ConnectionId(ProducerId id) {
045            this.value = id.getConnectionId();
046        }
047    
048        public ConnectionId(ConsumerId id) {
049            this.value = id.getConnectionId();
050        }
051    
052        public int hashCode() {
053            return value.hashCode();
054        }
055    
056        public boolean equals(Object o) {
057            if (this == o) {
058                return true;
059            }
060            if (o == null || o.getClass() != ConnectionId.class) {
061                return false;
062            }
063            ConnectionId id = (ConnectionId)o;
064            return value.equals(id.value);
065        }
066    
067        public byte getDataStructureType() {
068            return DATA_STRUCTURE_TYPE;
069        }
070    
071        public String toString() {
072            return value;
073        }
074    
075        /**
076         * @openwire:property version=1
077         */
078        public String getValue() {
079            return value;
080        }
081    
082        public void setValue(String connectionId) {
083            this.value = connectionId;
084        }
085    
086        public boolean isMarshallAware() {
087            return false;
088        }
089    
090        public int compareTo(ConnectionId o) {
091            return value.compareTo(o.value);
092        }
093    }