KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.Properties JavaDoc;
55
56 /**
57  * This is the Abstract class for all feature feature descriptors.
58  *
59  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
60  * @version $Revision: 1.4 $ $Date: 2003/07/12 13:34:27 $
61  */

62 public abstract class Descriptor
63         implements Serializable JavaDoc
64 {
65     private static final String JavaDoc[] EMPTY_SET = new String JavaDoc[0];
66
67     /**
68      * The arbitrary set of attributes associated with Component.
69      */

70     private final Properties JavaDoc m_attributes;
71
72     /**
73      * Creation of an abstract descriptor.
74      * @param attributes the set of attributes to assign to the descriptor
75      */

76     protected Descriptor( final Properties JavaDoc attributes )
77     {
78         m_attributes = attributes;
79     }
80
81     /**
82      * Return the attribute for specified key.
83      *
84      * @param key the attribute key to resolve
85      * @return the attribute for specified key.
86      */

87     public String JavaDoc getAttribute( final String JavaDoc key )
88     {
89         if ( null == m_attributes )
90         {
91             return null;
92         }
93         else
94         {
95             return m_attributes.getProperty( key );
96         }
97     }
98
99     /**
100      * Return the attribute for specified key.
101      *
102      * @param key the attribute key to resolve
103      * @param defaultValue the default value to use if the value is not defined
104      * @return the attribute for specified key.
105      */

106     public String JavaDoc getAttribute( final String JavaDoc key,
107                                 final String JavaDoc defaultValue )
108     {
109         if ( null == m_attributes )
110         {
111             return defaultValue;
112         }
113         else
114         {
115             return m_attributes.getProperty( key, defaultValue );
116         }
117     }
118
119     /**
120      * Returns the set of attribute names available under this descriptor.
121      *
122      * @return an array of the properties names held by the descriptor.
123      */

124     public String JavaDoc[] getAttributeNames()
125     {
126         if ( null == m_attributes )
127         {
128             return EMPTY_SET;
129         }
130         else
131         {
132             return (String JavaDoc[]) m_attributes.keySet().toArray( EMPTY_SET );
133         }
134     }
135
136     /**
137      * Compare this object with another for equality.
138      * @param other the object to compare this object with
139      * @return TRUE if the supplied object equivalent
140      */

141     public boolean equals( Object JavaDoc other )
142     {
143         if ( other instanceof Descriptor )
144         {
145             Descriptor descriptor = (Descriptor) other;
146             if ( null == m_attributes ) return null == descriptor.m_attributes;
147
148             return m_attributes.equals( descriptor.m_attributes );
149         }
150         return false;
151     }
152
153    /**
154     * Return the hashcode for the object.
155     * @return the hashcode value
156     */

157     public int hashCode()
158     {
159         if( m_attributes != null )
160         {
161             return m_attributes.hashCode();
162         }
163         else
164         {
165             return 1;
166         }
167     }
168
169     /**
170      * Returns the property set.
171      * TODO: check necessity for this operationi and if really needed return
172      * a cloned equivalent (i.e. disable modification)
173      *
174      * @return the property set.
175      */

176     protected Properties JavaDoc getProperties()
177     {
178         return m_attributes;
179     }
180 }
181
Popular Tags