KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.Properties JavaDoc;
54
55 import org.apache.avalon.framework.Version;
56
57 /**
58  * This class contains the meta information about a particular
59  * service. It contains a set of attributes qualifying the service;
60  *
61  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
62  * @version $Revision: 1.4 $ $Date: 2003/07/12 13:34:27 $
63  */

64 public class Service extends Descriptor
65 {
66     //=========================================================================
67
// state
68
//=========================================================================
69

70     /**
71      * The service reference.
72      */

73     private final ReferenceDescriptor m_reference;
74
75     /**
76      * The optional context entry criteria.
77      */

78     private final EntryDescriptor[] m_entries;
79
80     //=========================================================================
81
// constructor
82
//=========================================================================
83

84     /**
85      * Creation of a new Service instance using a classname and
86      * supplied properties argument.
87      *
88      * @param reference the versioned classname
89      */

90     public Service( final ReferenceDescriptor reference )
91     {
92         this( reference, null, null );
93     }
94
95     /**
96      * Creation of a new Service instance using a classname and
97      * supplied properties argument.
98      *
99      * @param reference the versioned classname
100      * @param entries the set of attributes to assign to the descriptor
101      */

102     public Service(
103             final ReferenceDescriptor reference,
104             final EntryDescriptor[] entries )
105     {
106         this( reference, entries, null );
107     }
108
109     /**
110      * Creation of a new Service instance using a classname and
111      * supplied properties argument.
112      *
113      * @param reference the versioned classname
114      * @param attributes the set of attributes to assign to the descriptor
115      */

116     public Service(
117             final ReferenceDescriptor reference,
118             final Properties JavaDoc attributes )
119     {
120         this( reference, null, attributes );
121     }
122
123     /**
124      * Creation of a new Service instance using a classname and
125      * supplied properties argument.
126      *
127      * @param reference the versioned classname
128      * @param entries the set of optional context entries
129      * @param attributes the set of attributes to assign to the descriptor
130      */

131     public Service(
132             final ReferenceDescriptor reference,
133             final EntryDescriptor[] entries,
134             final Properties JavaDoc attributes )
135     {
136         super( attributes );
137         if ( reference == null )
138         {
139             throw new NullPointerException JavaDoc( "reference" );
140         }
141         m_reference = reference;
142         if ( entries == null )
143         {
144             m_entries = new EntryDescriptor[0];
145         }
146         else
147         {
148             m_entries = entries;
149         }
150     }
151
152     //=========================================================================
153
// implementation
154
//=========================================================================
155

156     /**
157      * Return the service classname key.
158      * @return the service classname
159      */

160     public String JavaDoc getClassname()
161     {
162         return m_reference.getClassname();
163     }
164
165     /**
166      * Return the service version.
167      * @return the version
168      */

169     public Version getVersion()
170     {
171         return m_reference.getVersion();
172     }
173
174     /**
175      * Return the service reference.
176      * @return the reference
177      */

178     public ReferenceDescriptor getReference()
179     {
180         return m_reference;
181     }
182
183     /**
184      * Return the entries declared by the service.
185      *
186      * @return the entry descriptors
187      */

188     public EntryDescriptor[] getEntries()
189     {
190         return m_entries;
191     }
192
193     /**
194      * Determine if supplied reference will match this service.
195      * To match a service has to have same classname and must comply with version.
196      *
197      * @param reference the reference descriptor
198      * @return true if matches, false otherwise
199      */

200     public boolean matches( final ReferenceDescriptor reference )
201     {
202         return m_reference.matches( reference );
203     }
204
205     /**
206      * Return the hashcode for this service defintion.
207      * @return the hashcode value
208      */

209     public int hashCode()
210     {
211         return m_reference.hashCode();
212     }
213
214     /**
215      * Compare this object to the supplied object for equality.
216      * @param other the object to compare to this object
217      * @return true if this object matches the supplied object
218      * in terms of service classname and version
219      */

220     public boolean equals( Object JavaDoc other )
221     {
222         boolean match = false;
223
224         if ( other instanceof ReferenceDescriptor )
225         {
226             match = matches( (ReferenceDescriptor) other );
227         }
228         else if ( other instanceof Service )
229         {
230             Service ref = (Service) other;
231             match = ref.getClassname().equals( getClassname() )
232                     && ref.getVersion().complies( getVersion() );
233         }
234
235         return match;
236     }
237
238     /**
239      * Returns a string representation of the service.
240      * @return a string representation
241      */

242     public String JavaDoc toString()
243     {
244         return getReference().toString();
245     }
246
247 }
248
Popular Tags