KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > meta > info > EntryDescriptor


1 /*
2
3  ============================================================================
4                    The Apache Software License, Version 1.1
5  ============================================================================
6
7  Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
8
9  Redistribution and use in source and binary forms, with or without modifica-
10  tion, are permitted provided that the following conditions are met:
11
12  1. Redistributions of source code must retain the above copyright notice,
13     this list of conditions and the following disclaimer.
14
15  2. Redistributions in binary form must reproduce the above copyright notice,
16     this list of conditions and the following disclaimer in the documentation
17     and/or other materials provided with the distribution.
18
19  3. The end-user documentation included with the redistribution, if any, must
20     include the following acknowledgment: "This product includes software
21     developed by the Apache Software Foundation (http://www.apache.org/)."
22     Alternately, this acknowledgment may appear in the software itself, if
23     and wherever such third-party acknowledgments normally appear.
24
25  4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and
26     "Apache Software Foundation" must not be used to endorse or promote
27     products derived from this software without prior written
28     permission. For written permission, please contact apache@apache.org.
29
30  5. Products derived from this software may not be called "Apache", nor may
31     "Apache" appear in their name, without prior written permission of the
32     Apache Software Foundation.
33
34  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
35  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
36  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
37  APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
38  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
39  DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
40  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
41  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
42  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
43  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44
45  This software consists of voluntary contributions made by many individuals
46  on behalf of the Apache Software Foundation. For more information on the
47  Apache Software Foundation, please see <http://www.apache.org/>.
48
49 */

50
51 package org.apache.avalon.meta.info;
52
53 import java.io.Serializable JavaDoc;
54
55 /**
56  * A descriptor that describes a value that must be placed
57  * in components Context. It contains information about;
58  * <ul>
59  * <li>key: the key that component uses to look up entry</li>
60  * <li>classname: the class/interface of the entry</li>
61  * <li>isOptional: true if entry is optional rather than required</li>
62  * </ul>
63  *
64  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
65  * @version $Revision: 1.8 $ $Date: 2003/09/14 14:05:30 $
66  */

67 public final class EntryDescriptor
68         implements Serializable JavaDoc
69 {
70     /**
71      * The name the component uses to lookup entry.
72      */

73     private final String JavaDoc m_key;
74
75     /**
76      * The class/interface of the Entry.
77      */

78     private final String JavaDoc m_classname;
79
80     /**
81      * True if entry is optional, false otherwise.
82      */

83     private final boolean m_optional;
84
85     /**
86      * Immutable state of the entry.
87      */

88     private final boolean m_volatile;
89
90     /**
91      * An alias to a key.
92      */

93     private final String JavaDoc m_alias;
94
95     /**
96      * Construct an non-volotile required Entry.
97      * @param key the context entry key
98      * @param classname the classname of the context entry
99      * @exception NullPointerException if the key or type value are null
100      */

101     public EntryDescriptor( final String JavaDoc key,
102                             final String JavaDoc classname ) throws NullPointerException JavaDoc
103     {
104         this( key, classname, false );
105     }
106
107     /**
108      * Construct an non-volotile Entry.
109      * @param key the context entry key
110      * @param classname the classname of the context entry
111      * @param optional TRUE if this is an optional entry
112      * @exception NullPointerException if the key or type value are null
113      */

114     public EntryDescriptor( final String JavaDoc key,
115                             final String JavaDoc classname,
116                             final boolean optional ) throws NullPointerException JavaDoc
117     {
118         this( key, classname, optional, false );
119     }
120
121     /**
122      * Construct an Entry.
123      * @param key the context entry key
124      * @param classname the classname of the context entry
125      * @param optional TRUE if this is an optional entry
126      * @param isVolatile TRUE if the entry is consider to be immutable
127      * @exception NullPointerException if the key or type value are null
128      */

129     public EntryDescriptor( final String JavaDoc key,
130                             final String JavaDoc classname,
131                             final boolean optional,
132                             final boolean isVolatile ) throws NullPointerException JavaDoc
133     {
134         this( key, classname, optional, isVolatile, null );
135     }
136
137     /**
138      * Construct an Entry.
139      * @param key the context entry key
140      * @param classname the classname of the context entry
141      * @param optional TRUE if this is an optional entry
142      * @param isVolatile TRUE if the entry is is volatile
143      * @param alias an alternative key used by the component to reference the key
144      * @exception NullPointerException if the key or type value are null
145      */

146     public EntryDescriptor( final String JavaDoc key,
147                             final String JavaDoc classname,
148                             final boolean optional,
149                             final boolean isVolatile,
150                             final String JavaDoc alias ) throws NullPointerException JavaDoc
151     {
152         if ( null == key )
153         {
154             throw new NullPointerException JavaDoc( "key" );
155         }
156         if ( null == classname )
157         {
158             throw new NullPointerException JavaDoc( "classnamei" );
159         }
160
161         m_key = key;
162         m_classname = classname;
163         m_optional = optional;
164         m_volatile = isVolatile;
165         m_alias = alias;
166     }
167
168     /**
169      * Return the key that Component uses to lookup entry.
170      *
171      * @return the key that Component uses to lookup entry.
172      */

173     public String JavaDoc getKey()
174     {
175         return m_key;
176     }
177
178     /**
179      * Return the alias that Component uses to lookup the entry.
180      * If no alias is declared, the standard lookup key will be
181      * returned.
182      *
183      * @return the alias to the key.
184      */

185     public String JavaDoc getAlias()
186     {
187         if( m_alias != null )
188         {
189             return m_alias;
190         }
191         else
192         {
193             return m_key;
194         }
195     }
196
197     /**
198      * Return the key type of value that is stored in Context.
199      *
200      * @return the key type of value that is stored in Context.
201      */

202     public String JavaDoc getClassname()
203     {
204         return m_classname;
205     }
206
207     /**
208      * Return true if entry is optional, false otherwise.
209      *
210      * @return true if entry is optional, false otherwise.
211      */

212     public boolean isOptional()
213     {
214         return m_optional;
215     }
216
217     /**
218      * Return true if entry is required, false otherwise.
219      *
220      * @return true if entry is required, false otherwise.
221      */

222     public boolean isRequired()
223     {
224         return !isOptional();
225     }
226
227     /**
228      * Return true if entry is volotile.
229      *
230      * @return the volatile state of the entry
231      */

232     public boolean isVolatile()
233     {
234         return m_volatile;
235     }
236
237    /**
238     * Test is the supplied object is equal to this object.
239     * @param other the object to compare with this instance
240     * @return true if the object are equivalent
241     */

242     public boolean equals( Object JavaDoc other )
243     {
244         boolean isEqual = other instanceof EntryDescriptor;
245
246         if ( isEqual )
247         {
248             EntryDescriptor entry = (EntryDescriptor) other;
249
250             isEqual = isEqual && m_key.equals( entry.m_key );
251             isEqual = isEqual && m_classname.equals( entry.m_classname );
252             isEqual = isEqual && m_optional == entry.m_optional;
253             isEqual = isEqual && m_volatile == entry.m_volatile;
254             if ( null == m_alias )
255             {
256                 isEqual = isEqual && null == entry.m_alias;
257             }
258             else
259             {
260                 isEqual = isEqual && m_alias.equals( entry.m_alias );
261             }
262         }
263
264         return isEqual;
265     }
266
267    /**
268     * Return the hashcode for the object.
269     * @return the hashcode value
270     */

271     public int hashCode()
272     {
273         int hash = super.hashCode();
274         hash >>>= 13;
275         hash ^= m_key.hashCode();
276         hash >>>= 13;
277         hash ^= m_classname.hashCode();
278         hash >>>= 13;
279         hash ^= ( null != m_alias ) ? m_alias.hashCode() : 0;
280         hash >>>= 13;
281         hash >>>= ( m_volatile ) ? 1 : 3;
282         hash >>>= ( m_optional ) ? 1 : 3;
283
284         return hash;
285     }
286 }
287
Popular Tags