KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > utils > xml > betwixt > BaseDescriptor


1 /*
2  * Copyright 2000-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.jahia.utils.xml.betwixt;
17
18 /**
19  * The base class from which all descriptor beans are derived.
20  *
21  * Summit's XML configuration files are parse into descriptor beans
22  * and the descriptor beans are processed to configure Summit.
23  *
24  * @author <a HREF="mailto:jvanzyl@apache.org">Jason van Zyl</a>
25  * @version $Id: BaseDescriptor.java 6702 2004-05-28 15:34:30Z shuber $
26  */

27 public class BaseDescriptor
28 {
29     /**
30      * Display name to use for this descriptor.
31      */

32     private String JavaDoc name;
33
34     /**
35      * Id to use for this descriptor.
36      */

37     private String JavaDoc id;
38
39     /**
40      * Give object that have not been given an explicit unique id
41      * one that will keep betwixt happy.
42      */

43     private static int uniqueId;
44
45     /**
46      * Sets the name attribute
47      *
48      * @param name the new name value
49      */

50     public void setName(String JavaDoc name)
51     {
52         this.name = name;
53     }
54
55     /**
56      * Gets the name attribute
57      *
58      * @return the name attribute
59      */

60     public String JavaDoc getName()
61     {
62         return name;
63     }
64
65     /**
66      * Sets the id attribute of the BaseDescriptor object
67      *
68      * @param id the new id value
69      */

70     public void setId(String JavaDoc id)
71     {
72         this.id = id;
73     }
74
75     /**
76      * Gets the id attribute
77      *
78      * @return the id attribute
79      */

80     public String JavaDoc getId()
81     {
82         if (id == null)
83         {
84             id = Integer.toString(uniqueId++);
85         }
86
87         return id;
88     }
89
90     /**
91      * Return a string suitable for display/debugging
92      *
93      * @return the name attribute as a default
94      */

95     public String JavaDoc toString()
96     {
97         return name;
98     }
99
100     /**
101      * Whether the passed object is the same as this one. In this case
102      * the id is the unique qualifier. So two objects are equal
103      * if they have equal id's
104      * @param o any object
105      * @return true if o is the same as this object, false otherwise
106      */

107     public boolean equals(Object JavaDoc o)
108     {
109         if (o == null)
110         {
111             return false;
112         }
113
114         if (getClass() != o.getClass())
115         {
116             return false;
117         }
118
119         if (getId() != null)
120         {
121             return getId().equals(((BaseDescriptor) o).getId());
122         }
123         else
124         {
125             return ((BaseDescriptor) o).getId() == null;
126         }
127     }
128
129     /**
130      * Provides the hashCode of this object, which is determined by simply
131      * delegating the responsibility to the name property
132      * @return the hashCode of the name if not null, otherwise delegate to the
133      * parent class
134      */

135     public int hashCode()
136     {
137         if (getId() != null)
138         {
139             return getId().hashCode();
140         }
141         else
142         {
143             return super.hashCode();
144         }
145     }
146 }
147
Popular Tags