KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jcorporate > expresso > kernel > metadata > ComponentMetadata


1 package com.jcorporate.expresso.kernel.metadata;
2
3 /* ====================================================================
4  * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
5  *
6  * Copyright (c) 1995-2003 Jcorporate Ltd. All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by Jcorporate Ltd.
23  * (http://www.jcorporate.com/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. "Jcorporate" and product names such as "Expresso" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written permission,
30  * please contact info@jcorporate.com.
31  *
32  * 5. Products derived from this software may not be called "Expresso",
33  * or other Jcorporate product names; nor may "Expresso" or other
34  * Jcorporate product names appear in their name, without prior
35  * written permission of Jcorporate Ltd.
36  *
37  * 6. No product derived from this software may compete in the same
38  * market space, i.e. framework, without prior written permission
39  * of Jcorporate Ltd. For written permission, please contact
40  * partners@jcorporate.com.
41  *
42  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
43  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
44  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
45  * DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
46  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
47  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
48  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
49  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
50  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
51  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
52  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53  * SUCH DAMAGE.
54  * ====================================================================
55  *
56  * This software consists of voluntary contributions made by many
57  * individuals on behalf of the Jcorporate Ltd. Contributions back
58  * to the project(s) are encouraged when you make modifications.
59  * Please send them to support@jcorporate.com. For more information
60  * on Jcorporate Ltd. and its products, please see
61  * <http://www.jcorporate.com/>.
62  *
63  * Portions of this software are based upon other open source
64  * products and are subject to their respective licenses.
65  */

66
67 import java.util.ArrayList JavaDoc;
68 import java.util.Collections JavaDoc;
69 import java.util.HashMap JavaDoc;
70 import java.util.List JavaDoc;
71 import java.util.Map JavaDoc;
72
73 /**
74  * Bean class that stores the component metadata. Although this class is normally
75  * populated by the contents of an XML file, it can be manually populated if
76  * the developer so wishes.
77  *
78  * @author Michael Rimov
79  * @version $Revision: 1.5 $ on $Date: 2004/11/17 20:48:17 $
80  */

81
82 public class ComponentMetadata {
83
84     /**
85      * Name of the component
86      */

87     private String JavaDoc name;
88
89     /**
90      * Return the string of the version number in the format major.minor.micro
91      */

92     private String JavaDoc versionNumber;
93
94     /**
95      * Nested Component Metadata
96      */

97     List JavaDoc nested;
98
99     /**
100      * Current properties of the ComponentMetadata
101      */

102     Map JavaDoc properties;
103
104     /**
105      * Defined management methods of the Component
106      */

107     Map JavaDoc methods;
108
109     /**
110      * Friendly name of the component
111      */

112     private String JavaDoc description;
113
114     /**
115      * Location of the message bundle
116      */

117     private String JavaDoc messageBundle;
118
119     /**
120      * SchemaData Metadata bean
121      */

122     private SchemaData schemaData;
123
124     /**
125      * Default constructor
126      */

127     public ComponentMetadata() {
128         nested = new ArrayList JavaDoc();
129         properties = new HashMap JavaDoc();
130         methods = new HashMap JavaDoc();
131     }
132
133     /**
134      * Retrieve the name of the component
135      *
136      * @return java.lang.String
137      */

138     public String JavaDoc getName() {
139         return name;
140     }
141
142     /**
143      * Set the name of the compoent
144      *
145      * @param name New name for the component
146      */

147     public void setName(String JavaDoc name) {
148         this.name = name;
149     }
150
151     /**
152      * Set the version number as a string
153      *
154      * @param versionNumber new version number in the format major.minor.micro
155      */

156     public void setVersionNumber(String JavaDoc versionNumber) {
157         this.versionNumber = versionNumber;
158     }
159
160     /**
161      * Retrieve the version number as a String
162      *
163      * @return java.lang.String
164      */

165     public String JavaDoc getVersionNumber() {
166         return versionNumber;
167     }
168
169     /**
170      * Set the version number as a batch of strings
171      *
172      * @param major the major version number
173      * @param minor the minor version number
174      * @param micro the micro version number
175      */

176     public void setVersionNumber(String JavaDoc major, String JavaDoc minor, String JavaDoc micro) {
177         try {
178             Integer.parseInt(major);
179             Integer.parseInt(minor);
180             Integer.parseInt(micro);
181         } catch (NumberFormatException JavaDoc ex) {
182             throw new IllegalArgumentException JavaDoc("ComponentMetadata.setVersionNumber: " +
183                     "major, minor, and micro version strings must be parseable integers");
184         }
185
186         versionNumber = major + "." + minor + "." + micro;
187     }
188
189     /**
190      * Add a new ComponentMetadata object as a child of this component
191      *
192      * @param newComponent an instantiated ComponentMetadata
193      */

194     public void addChildComponent(ComponentMetadata newComponent) {
195         nested.add(newComponent);
196     }
197
198     /**
199      * Retrieve a list of children
200      *
201      * @return UnModifiable List
202      */

203     public List JavaDoc getChildren() {
204         return Collections.unmodifiableList(nested);
205     }
206
207
208     /**
209      * Set the description of the component metadata
210      *
211      * @param description The new 'friendly name' of the component
212      */

213     public void setDescription(String JavaDoc description) {
214         this.description = description;
215     }
216
217     /**
218      * Retrieve the friendly name of the component
219      *
220      * @return java.lang.String
221      */

222     public String JavaDoc getDescription() {
223         return description;
224     }
225
226     /**
227      * Add a new Property to this component's metadata
228      *
229      * @param newValue the new property value
230      */

231     public void addProperty(Property newValue) {
232         properties.put(newValue.getName(), newValue);
233     }
234
235     /**
236      * Add a new Method metadata object
237      *
238      * @param newValue the new Method metadata object
239      */

240     public void addMethod(Method newValue) {
241         methods.put(newValue.getName(), newValue);
242     }
243
244     /**
245      * Retrieve the metadata
246      *
247      * @param methodName name of the method to retrieve
248      * @return The Method or null if it doesn't exist
249      */

250     public Method getMethod(String JavaDoc methodName) {
251         return (Method) methods.get(methodName);
252     }
253
254     /**
255      * Retrieve all registered methods
256      *
257      * @return an Unmodifiable Map
258      */

259     public Map JavaDoc getMethods() {
260         return Collections.unmodifiableMap(methods);
261     }
262
263     /**
264      * Retrieve the properties for the component
265      *
266      * @return an Unmodifiable Map of Property classes
267      */

268     public Map JavaDoc getProperties() {
269         return Collections.unmodifiableMap(properties);
270     }
271
272     /**
273      * <p>Sets the method metadata available. </p>
274      * <p>Example Usage:
275      * <code>
276      * metadata.setMessageBundle("/com/jcorporate/expresso/core/MessagesBundle");
277      * </code>
278      *
279      * @param messageBundle 'resource' path to the MessageBundle.
280      */

281     public void setMessageBundle(String JavaDoc messageBundle) {
282         this.messageBundle = messageBundle;
283     }
284
285     /**
286      * Retrieve the 'relative resource path' to the MessageBundle
287      *
288      * @return java.lang.String
289      */

290     public String JavaDoc getMessageBundle() {
291         return messageBundle;
292     }
293
294     /**
295      * Sets the Schema data for the component.
296      *
297      * @param newData the new SchemaData object
298      */

299     public void setSchemaData(SchemaData newData) {
300         schemaData = newData;
301     }
302
303     /**
304      * Retrieve the SchemaData bean from the metadata object
305      *
306      * @return SchemaData for this metadata
307      */

308     public SchemaData getSchemaData() {
309         return schemaData;
310     }
311
312 }
Popular Tags