KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jsftest > repository > DataDictionary


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package jsftest.repository;
18
19 import java.util.ArrayList;
20 import java.util.HashMap;
21 import java.util.Iterator;
22 import java.util.List;
23 import java.util.Map;
24
25 /**
26  * Class to represent a basic data dictionary service
27  *
28  * @author gavinc
29  */

30 public class DataDictionary
31 {
32    private Map types;
33    
34    public DataDictionary()
35    {
36       this.types = new HashMap();
37       
38       // setup the dictionary
39
Property name = new Property("name", "string", "Name", false);
40       Property desc = new Property("description", "string", "Description" , false);
41       Property created = new Property("created", "datetime", "Created Date", true);
42       Property modified = new Property("modified", "datetime", "Modified Date", false);
43       Property keywords = new Property("keywords", "string[]", "Keywords", false);
44       
45       MetaData base = new MetaData("base");
46       base.addProperty(name);
47       base.addProperty(desc);
48       base.addProperty(created);
49       base.addProperty(modified);
50       base.addProperty(keywords);
51       
52       Property sopid = new Property("sopId", "string", "SOP ID", true);
53       Property effective = new Property("effective", "datetime", "Effective Date", false);
54       Property approved = new Property("approved", "boolean", "Approved", false);
55       Property latestVersion = new Property("latestversion", "string", "Latest Version", true);
56       
57       MetaData sop = new MetaData("SOP");
58       sop.setProperties(base.getProperties());
59       sop.addProperty(sopid);
60       sop.addProperty(effective);
61       sop.addProperty(approved);
62       // add an aspect and the associated property
63
sop.addAspect("versionable");
64       sop.addProperty(latestVersion);
65       
66       this.types.put(base.getTypeName(), base);
67       this.types.put(sop.getTypeName(), sop);
68    }
69    
70    public MetaData getMetaData(String type)
71    {
72       return (MetaData)this.types.get(type);
73    }
74    
75    /**
76     * @return Returns the types.
77     */

78    public Map getTypes()
79    {
80       return this.types;
81    }
82    
83    
84    // *********************
85
// *** Inner classes ***
86
// *********************
87

88    /**
89     * Represents the meta data of an object
90     * @author gavinc
91     */

92     public class MetaData
93     {
94       private Map propertiesMap;
95        private List properties;
96        private String typeName;
97       private List aspects;
98        
99        public MetaData(String typeName)
100        {
101           this.properties = new ArrayList();
102          this.propertiesMap = new HashMap();
103          this.aspects = new ArrayList();
104           this.typeName = typeName;
105        }
106        
107        /**
108         * Adds a property to the meta data object
109         *
110         * @author gavinc
111         */

112        public void addProperty(Property property)
113        {
114           this.properties.add(property);
115          this.propertiesMap.put(property.getName(), property);
116        }
117        
118       /**
119        * @return Returns the properties.
120        */

121       public List getProperties()
122       {
123          return this.properties;
124       }
125       
126       /**
127        * @param properties The properties to set.
128        */

129       public void setProperties(List properties)
130       {
131          this.properties.clear();
132          this.propertiesMap.clear();
133          
134          Iterator iter = properties.iterator();
135          while (iter.hasNext())
136          {
137             Property prop = (Property)iter.next();
138             this.properties.add(prop);
139             this.propertiesMap.put(prop.getName(), prop);
140          }
141       }
142       
143       public Map getPropertiesMap()
144       {
145          return this.propertiesMap;
146       }
147       
148       public List getAspects()
149       {
150          return this.aspects;
151       }
152       
153       public void addAspect(String aspect)
154       {
155          this.aspects.add(aspect);
156       }
157       
158       /**
159        * @return Returns the typeName.
160        */

161       public String getTypeName()
162       {
163          return this.typeName;
164       }
165     }
166     
167     /**
168      * Represents a property on an object
169      * @author gavinc
170      */

171     public class Property
172     {
173        private String name;
174        private String type;
175        private String displayName;
176        private boolean readOnly;
177        
178       /**
179        * @param name
180        * @param type
181        * @param readOnly
182        */

183       public Property(String name, String type, String displayName, boolean readOnly)
184       {
185          this.name = name;
186          this.type = type;
187          this.displayName = displayName;
188          this.readOnly = readOnly;
189       }
190       
191        /**
192         * @return Returns the name.
193         */

194        public String getName()
195        {
196           return this.name;
197        }
198        
199        /**
200         * @param name The name to set.
201         */

202        public void setName(String name)
203        {
204           this.name = name;
205        }
206        
207        /**
208         * @return Returns the type.
209         */

210        public String getType()
211        {
212           return this.type;
213        }
214        
215        /**
216         * @param type The type to set.
217         */

218        public void setType(String type)
219        {
220           this.type = type;
221        }
222        
223       /**
224        * @return Returns the displayName.
225        */

226       public String getDisplayName()
227       {
228          return this.displayName;
229       }
230       
231       /**
232        * @param displayName The displayName to set.
233        */

234       public void setDisplayName(String displayName)
235       {
236          this.displayName = displayName;
237       }
238       
239        /**
240         * @return Returns the readOnly.
241         */

242        public boolean isReadOnly()
243        {
244           return this.readOnly;
245        }
246        
247        /**
248         * @param readOnly The readOnly to set.
249         */

250        public void setReadOnly(boolean readOnly)
251        {
252           this.readOnly = readOnly;
253        }
254     }
255     
256 }
Popular Tags