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.kaha;
018    
019    import java.io.Externalizable;
020    import java.io.IOException;
021    import java.io.ObjectInput;
022    import java.io.ObjectOutput;
023    
024    /**
025     * Used by RootContainers
026     * 
027     * 
028     */
029    public class ContainerId implements Externalizable {
030        private static final long serialVersionUID = -8883779541021821943L;
031        private Object key;
032        private String dataContainerName;
033    
034        public ContainerId() {
035        }
036    
037        public ContainerId(Object key, String dataContainerName) {
038            this.key = key;
039            this.dataContainerName = dataContainerName;
040        }
041    
042        /**
043         * @return Returns the dataContainerPrefix.
044         */
045        public String getDataContainerName() {
046            return dataContainerName;
047        }
048    
049        /**
050         * @return Returns the key.
051         */
052        public Object getKey() {
053            return key;
054        }
055    
056        public int hashCode() {
057            return key.hashCode() ^ dataContainerName.hashCode();
058        }
059    
060        public boolean equals(Object obj) {
061            if (obj == null || obj.getClass() != ContainerId.class) {
062                return false;
063            }
064            ContainerId other = (ContainerId)obj;
065            return other.key.equals(this.key) && other.dataContainerName.equals(this.dataContainerName);
066        }
067    
068        public void writeExternal(ObjectOutput out) throws IOException {
069            out.writeUTF(getDataContainerName());
070            out.writeObject(key);
071        }
072    
073        public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
074            dataContainerName = in.readUTF();
075            key = in.readObject();
076        }
077    
078        public String toString() {
079            return "CID{" + dataContainerName + ":" + key + "}";
080        }
081    }