KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > browser > core > naming > AbstractName


1 /*===========================================================================
2
3 ObjectWeb Naming Context Framework
4 Copyright (C) 2002 USTL - LIFL - GOAL
5 Contact: architecture@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Philippe Merle.
23 Contributor(s): ______________________________________.
24
25 ===========================================================================*/

26
27 package org.objectweb.util.browser.core.naming;
28
29 /** To implement the Name interface. */
30 import org.objectweb.util.browser.core.api.Name;
31
32 /**
33  * Abstract basic implementation of the Name interface which
34  * only provides an base implementation for the toStringBuffer and equals methods.
35  *
36  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
37  * @version 0.1
38  */

39 public abstract class AbstractName extends AbstractObject implements Name {
40
41     // ==================================================================
42
//
43
// No internal state.
44
//
45
// ==================================================================
46

47     // ==================================================================
48
//
49
// No constructors.
50
//
51
// ==================================================================
52

53     // ==================================================================
54
//
55
// No internal methods.
56
//
57
// ==================================================================
58

59     // ==================================================================
60
//
61
// Public methods for class Object.
62
//
63
// ==================================================================
64

65     /**
66      * Tests if a given object is equals to the target name.
67      *
68      * @param obj The given object.
69      *
70      * @return
71      * true if the given object is a Name instance and
72      * this given name is equals to the target name;
73      * false otherwise.
74      *
75      * @postcondition
76      * obj instanceof Name
77      * and result == equals((Name)obj);
78      */

79     public boolean equals(Object JavaDoc obj) {
80         if (obj instanceof Name)
81             return equals((Name) obj);
82         else
83             return super.equals(obj);
84     }
85
86     // ==================================================================
87
//
88
// Public methods for class AbstractObject.
89
//
90
// ==================================================================
91

92     /**
93      * Appends internal state representation into a given string buffer.
94      *
95      * This method does not update the target object.
96      *
97      * @param sb The string buffer where pairs <name,value> are appended.
98      *
99      * @postcondition isNotModified();
100      */

101     public void toStringBuffer(StringBuffer JavaDoc sb) {
102         sb.append("id=");
103         sb.append(getOWId());
104         sb.append(",subname=");
105         sb.append(getOWSubName());
106     }
107     
108     // ==================================================================
109
//
110
// Public methods for interface Name.
111
//
112
// ==================================================================
113

114     /**
115      * Gets the id of the target name.
116      *
117      * This method does not update the id of the target name.
118      *
119      * @return The id of the target name.
120      *
121      * @postcondition return == getOWId();
122      */

123     public abstract String JavaDoc getOWId();
124
125     /**
126      * Gets the subname of the target name.
127      *
128      * This method does not update the subname of the target name.
129      *
130      * @return the subname of the target name.
131      *
132      * @postcondition return == getOWSubName();
133      */

134     public abstract Name getOWSubName();
135
136     /**
137      * Tests if a given name is equals to the target name.
138      *
139      * @param name The given name.
140      *
141      * @return
142      * true if the given name is the same object of the target name,
143      * or if the id and the subname of the given name are equals to
144      * respectively the id and subname of the target name;
145      * false otherwise.
146      *
147      * @postcondition
148      * result == (name == this)
149      * or ( name.getOWId().equals(this.getOWId())
150      * and name.getOWSubName().equals(getOWSubName()) );
151      */

152     public boolean equals(Name name) {
153         return (name == this) || (name.getOWId().equals(this.getOWId()) && name.getOWSubName().equals(getOWSubName()));
154     }
155
156 }
157
Popular Tags