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.servicemix.jbi.framework;
018
019 import java.io.Externalizable;
020 import java.io.IOException;
021 import java.io.ObjectInput;
022 import java.io.ObjectOutput;
023
024 /**
025 * Component Name is used internally to identify a Component.
026 *
027 * @version $Revision: 564900 $
028 */
029 public class ComponentNameSpace implements Externalizable {
030
031 /**
032 * Generated serial version UID
033 */
034 private static final long serialVersionUID = -9130913368962887486L;
035
036 protected String containerName;
037 protected String name;
038
039 /**
040 * Default Constructor
041 */
042 public ComponentNameSpace() {
043 }
044
045 /**
046 * Construct a ComponentName
047 *
048 * @param containerName
049 * @param componentName
050 * @param componentId
051 */
052 public ComponentNameSpace(String containerName, String componentName) {
053 this.containerName = containerName;
054 this.name = componentName;
055 }
056
057 /**
058 * @return Returns the componentName.
059 */
060 public String getName() {
061 return name;
062 }
063
064 /**
065 * @param componentName The componentName to set.
066 */
067 public void setName(String componentName) {
068 this.name = componentName;
069 }
070
071 /**
072 * @return Returns the containerName.
073 */
074 public String getContainerName() {
075 return containerName;
076 }
077
078 /**
079 * @param containerName The containerName to set.
080 */
081 public void setContainerName(String containerName) {
082 this.containerName = containerName;
083 }
084
085 /**
086 * @param obj
087 * @return true if obj is equivalent to 'this'
088 */
089 public boolean equals(Object obj) {
090 boolean result = false;
091 if (obj instanceof ComponentNameSpace) {
092 ComponentNameSpace other = (ComponentNameSpace) obj;
093 result = other.containerName.equals(this.containerName)
094 && other.name.equals(this.name);
095 }
096 return result;
097 }
098
099 /**
100 * @return the hashCode
101 */
102 public int hashCode() {
103 return containerName.hashCode() ^ name.hashCode();
104 }
105
106 /**
107 * @return pretty print
108 */
109 public String toString() {
110 return "[container=" + containerName + ",name=" + name + "]";
111 }
112
113 /**
114 * write out to stream
115 * @param out
116 * @throws IOException
117 */
118 public void writeExternal(ObjectOutput out) throws IOException {
119 out.writeUTF(containerName != null ? containerName : "");
120 out.writeUTF(name != null ? name : "");
121 }
122
123 /**
124 * read from Stream
125 * @param in
126 * @throws IOException
127 * @throws ClassNotFoundException
128 */
129 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
130 containerName = in.readUTF();
131 name = in.readUTF();
132 }
133
134 /**
135 * copy this
136 * @return
137 */
138 public ComponentNameSpace copy() {
139 return new ComponentNameSpace(containerName, name);
140 }
141
142 }