001: package com.jcorporate.expresso.kernel.metadata;
002:
003: /* ====================================================================
004: * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
005: *
006: * Copyright (c) 1995-2003 Jcorporate Ltd. All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in
017: * the documentation and/or other materials provided with the
018: * distribution.
019: *
020: * 3. The end-user documentation included with the redistribution,
021: * if any, must include the following acknowledgment:
022: * "This product includes software developed by Jcorporate Ltd.
023: * (http://www.jcorporate.com/)."
024: * Alternately, this acknowledgment may appear in the software itself,
025: * if and wherever such third-party acknowledgments normally appear.
026: *
027: * 4. "Jcorporate" and product names such as "Expresso" must
028: * not be used to endorse or promote products derived from this
029: * software without prior written permission. For written permission,
030: * please contact info@jcorporate.com.
031: *
032: * 5. Products derived from this software may not be called "Expresso",
033: * or other Jcorporate product names; nor may "Expresso" or other
034: * Jcorporate product names appear in their name, without prior
035: * written permission of Jcorporate Ltd.
036: *
037: * 6. No product derived from this software may compete in the same
038: * market space, i.e. framework, without prior written permission
039: * of Jcorporate Ltd. For written permission, please contact
040: * partners@jcorporate.com.
041: *
042: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
043: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
044: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
045: * DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
046: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
047: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
048: * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
049: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
050: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
051: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
052: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
053: * SUCH DAMAGE.
054: * ====================================================================
055: *
056: * This software consists of voluntary contributions made by many
057: * individuals on behalf of the Jcorporate Ltd. Contributions back
058: * to the project(s) are encouraged when you make modifications.
059: * Please send them to support@jcorporate.com. For more information
060: * on Jcorporate Ltd. and its products, please see
061: * <http://www.jcorporate.com/>.
062: *
063: * Portions of this software are based upon other open source
064: * products and are subject to their respective licenses.
065: */
066:
067: import java.util.ArrayList;
068: import java.util.Collections;
069: import java.util.HashMap;
070: import java.util.List;
071: import java.util.Map;
072:
073: /**
074: * Bean class that stores the component metadata. Although this class is normally
075: * populated by the contents of an XML file, it can be manually populated if
076: * the developer so wishes.
077: *
078: * @author Michael Rimov
079: * @version $Revision: 1.5 $ on $Date: 2004/11/17 20:48:17 $
080: */
081:
082: public class ComponentMetadata {
083:
084: /**
085: * Name of the component
086: */
087: private String name;
088:
089: /**
090: * Return the string of the version number in the format major.minor.micro
091: */
092: private String versionNumber;
093:
094: /**
095: * Nested Component Metadata
096: */
097: List nested;
098:
099: /**
100: * Current properties of the ComponentMetadata
101: */
102: Map properties;
103:
104: /**
105: * Defined management methods of the Component
106: */
107: Map methods;
108:
109: /**
110: * Friendly name of the component
111: */
112: private String description;
113:
114: /**
115: * Location of the message bundle
116: */
117: private String 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();
129: properties = new HashMap();
130: methods = new HashMap();
131: }
132:
133: /**
134: * Retrieve the name of the component
135: *
136: * @return java.lang.String
137: */
138: public String 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 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 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 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 major, String minor,
177: String micro) {
178: try {
179: Integer.parseInt(major);
180: Integer.parseInt(minor);
181: Integer.parseInt(micro);
182: } catch (NumberFormatException ex) {
183: throw new IllegalArgumentException(
184: "ComponentMetadata.setVersionNumber: "
185: + "major, minor, and micro version strings must be parseable integers");
186: }
187:
188: versionNumber = major + "." + minor + "." + micro;
189: }
190:
191: /**
192: * Add a new ComponentMetadata object as a child of this component
193: *
194: * @param newComponent an instantiated ComponentMetadata
195: */
196: public void addChildComponent(ComponentMetadata newComponent) {
197: nested.add(newComponent);
198: }
199:
200: /**
201: * Retrieve a list of children
202: *
203: * @return UnModifiable List
204: */
205: public List getChildren() {
206: return Collections.unmodifiableList(nested);
207: }
208:
209: /**
210: * Set the description of the component metadata
211: *
212: * @param description The new 'friendly name' of the component
213: */
214: public void setDescription(String description) {
215: this .description = description;
216: }
217:
218: /**
219: * Retrieve the friendly name of the component
220: *
221: * @return java.lang.String
222: */
223: public String getDescription() {
224: return description;
225: }
226:
227: /**
228: * Add a new Property to this component's metadata
229: *
230: * @param newValue the new property value
231: */
232: public void addProperty(Property newValue) {
233: properties.put(newValue.getName(), newValue);
234: }
235:
236: /**
237: * Add a new Method metadata object
238: *
239: * @param newValue the new Method metadata object
240: */
241: public void addMethod(Method newValue) {
242: methods.put(newValue.getName(), newValue);
243: }
244:
245: /**
246: * Retrieve the metadata
247: *
248: * @param methodName name of the method to retrieve
249: * @return The Method or null if it doesn't exist
250: */
251: public Method getMethod(String methodName) {
252: return (Method) methods.get(methodName);
253: }
254:
255: /**
256: * Retrieve all registered methods
257: *
258: * @return an Unmodifiable Map
259: */
260: public Map getMethods() {
261: return Collections.unmodifiableMap(methods);
262: }
263:
264: /**
265: * Retrieve the properties for the component
266: *
267: * @return an Unmodifiable Map of Property classes
268: */
269: public Map getProperties() {
270: return Collections.unmodifiableMap(properties);
271: }
272:
273: /**
274: * <p>Sets the method metadata available. </p>
275: * <p>Example Usage:
276: * <code>
277: * metadata.setMessageBundle("/com/jcorporate/expresso/core/MessagesBundle");
278: * </code>
279: *
280: * @param messageBundle 'resource' path to the MessageBundle.
281: */
282: public void setMessageBundle(String messageBundle) {
283: this .messageBundle = messageBundle;
284: }
285:
286: /**
287: * Retrieve the 'relative resource path' to the MessageBundle
288: *
289: * @return java.lang.String
290: */
291: public String getMessageBundle() {
292: return messageBundle;
293: }
294:
295: /**
296: * Sets the Schema data for the component.
297: *
298: * @param newData the new SchemaData object
299: */
300: public void setSchemaData(SchemaData newData) {
301: schemaData = newData;
302: }
303:
304: /**
305: * Retrieve the SchemaData bean from the metadata object
306: *
307: * @return SchemaData for this metadata
308: */
309: public SchemaData getSchemaData() {
310: return schemaData;
311: }
312:
313: }
|