KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > model > AbstractMetaData


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.mvc.model;
8
9 import com.inversoft.verge.mvc.MVCException;
10
11
12 /**
13  * <p>
14  * This is the abstract base class for any implementors of
15  * the MetaData interface.
16  * </p>
17  *
18  * @author Brian Pontarelli
19  * @since 2.0
20  * @version 2.0
21  */

22 public abstract class AbstractMetaData implements MetaData {
23
24     protected String JavaDoc id;
25     protected String JavaDoc property;
26     
27
28     /**
29      * Construsts a new <code>AbstractMetaData</code> using the definition given.
30      * This method splits the definition at the first . character and then saves
31      * of the left as the id and the right as the property.
32      */

33     public AbstractMetaData(String JavaDoc definition) throws MVCException {
34         assert (definition != null) : "definition == null";
35
36         int index = definition.indexOf(".");
37         if (index == -1) {
38             throw new MVCException("Invalid definition: " + definition);
39         }
40
41         id = definition.substring(0, index);
42         property = definition.substring(index + 1);
43     }
44
45     /**
46      * Construsts a new <code>AbstractMetaData</code>
47      */

48     public AbstractMetaData(String JavaDoc id, String JavaDoc property) {
49         assert (id != null) : "id == null";
50         this.id = id;
51         this.property = property;
52     }
53
54
55     /**
56      * Returns the id of this web model
57      *
58      * @return The id used to store the model in a scope
59      */

60     public String JavaDoc getID() {
61         return id;
62     }
63
64     /**
65      * Returns the property of this web model
66      *
67      * @return The property accessed on the model
68      */

69     public String JavaDoc getProperty() {
70         return property;
71     }
72
73     /**
74      * Returns the definition for the model, which references the form bean
75      *
76      * @see com.inversoft.verge.mvc.model.MetaData#getDefinition()
77      */

78     public String JavaDoc getDefinition() {
79         assert (property != null) : "property == null";
80         
81         // If assertions are off, this is the safest route since we will still
82
// get a null pointer hopefully
83
if (property == null) {
84             return null;
85         }
86         
87         StringBuffer JavaDoc buf = new StringBuffer JavaDoc(id).append(".").append(property);
88         return buf.toString();
89     }
90 }
Popular Tags