KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > common > PropertyName


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/common/PropertyName.java,v 1.3 2004/07/28 09:38:17 ib Exp $
3  * $Revision: 1.3 $
4  * $Date: 2004/07/28 09:38:17 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23 package org.apache.slide.common;
24
25 // import list
26
import org.apache.slide.content.NodeProperty;
27
28 /**
29  * This class is a container for the name and namespace of a property.
30  *
31  * @version $Revision: 1.3 $
32  *
33  **/

34 public class PropertyName {
35     
36     /**
37      * The name of the Property.
38      */

39     protected String JavaDoc name = null;
40     
41     /**
42      * The namespace of the Property.
43      */

44     protected String JavaDoc namespace = null;
45     
46     
47     /**
48      * Creates a PropertyName within the {@link NodeProperty#DEFAULT_NAMESPACE
49      * default namespace}.
50      *
51      * @param name the name of the Property.
52      */

53     public PropertyName(String JavaDoc name) {
54         this(name, NodeProperty.DEFAULT_NAMESPACE);
55     }
56     
57     /**
58      * Creates a PropertyName.
59      *
60      * @param name the name of the Property.
61      * @param namespace the namespace of the Property.
62      */

63     public PropertyName(String JavaDoc name, String JavaDoc namespace) {
64         this.name = name;
65         this.namespace = namespace;
66     }
67     
68     /**
69      * Returns the name of the property.
70      *
71      * @return the name of the property.
72      */

73     public String JavaDoc getName() {
74         return name;
75     }
76     
77     /**
78      * Returns the namespace of the property.
79      *
80      * @return the namespace of the property.
81      */

82     public String JavaDoc getNamespace() {
83         return namespace;
84     }
85     
86     /**
87      * Returns <code>true</code> if <code>other</code> is a PropertyName
88      * and the name and namespace are equal to this intance' name and namespace.
89      *
90      * @param other the Object to test for equality.
91      *
92      * @return <code>true</code> if the object is equal to this one.
93      */

94     public boolean equals(Object JavaDoc other) {
95         
96         boolean equal = false;
97         if (other instanceof PropertyName) {
98             PropertyName otherPropertyName = (PropertyName)other;
99             if (getName() == null) {
100                 equal = (otherPropertyName.getName() == null);
101             }
102             else {
103                 equal = getName().equals(otherPropertyName.getName());
104             }
105             if (getNamespace() == null) {
106                 equal &= (otherPropertyName.getNamespace() == null);
107             }
108             else {
109                 equal &= getNamespace().equals(otherPropertyName.getNamespace());
110             }
111         }
112         return equal;
113     }
114     
115     /**
116      * Returns the hash code of this instance. Due to definition equal objects
117      * must have the same hash code.
118      *
119      * @return the hash code of this instance.
120      */

121     public int hashCode() {
122         
123         int hash = 0;
124         if (getName() != null) {
125             hash = getName().hashCode();
126         }
127         if (getNamespace() != null) {
128             hash += 13 * getNamespace().hashCode();
129         }
130         return hash;
131     }
132     
133     /**
134      * Returns a String representation of the PropertyName.
135      *
136      * @return a String representation of the PropertyName.
137      */

138     public String JavaDoc toString() {
139         if (getNamespace() == null) {
140             return getName();
141         }
142         else {
143             StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(getNamespace());
144             buffer.append(":");
145             if (getName() != null) {
146                 buffer.append(getName());
147             }
148             return buffer.toString();
149         }
150     }
151 }
152
153
Popular Tags