KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > module > ModuleDefinition


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2005 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.module;
14
15 import info.magnolia.cms.beans.config.ModuleRegistration;
16
17 import java.io.File JavaDoc;
18 import java.util.ArrayList JavaDoc;
19 import java.util.Collection JavaDoc;
20 import java.util.Iterator JavaDoc;
21
22 import org.apache.commons.lang.StringUtils;
23
24
25 /**
26  * Defines a module to register. The definition is constructed by the modules xml definition (using betwixt).
27  * @author Philipp Bracher
28  * @version $Revision: 7361 $ ($Author: gjoseph $)
29  */

30 public class ModuleDefinition {
31
32     /**
33      * The dependencies to other modules. This modules are loaded or registerd in advance
34      */

35     private Collection JavaDoc dependencies = new ArrayList JavaDoc();
36
37     /**
38      * The servlets used by this module. They will get registerd in the web.xml
39      */

40     private Collection JavaDoc servlets = new ArrayList JavaDoc();
41
42     /**
43      * The additional repostiories used by this module
44      */

45     private Collection JavaDoc repositories = new ArrayList JavaDoc();
46
47     /**
48      * Properties to set in the magnolia system properties
49      */

50     private Collection JavaDoc properties = new ArrayList JavaDoc();
51
52     /**
53      * The name of the module
54      */

55     private String JavaDoc name;
56
57     /**
58      * A nice name for displaying
59      */

60     private String JavaDoc displayName = "";
61
62     /**
63      * The version of the module
64      */

65     private String JavaDoc version;
66
67     /**
68      * A full descrpition of the module
69      */

70     private String JavaDoc description;
71
72     /**
73      * The className of the engine
74      */

75     private String JavaDoc className;
76
77     /**
78      * The root directory or jar file for the module.
79      */

80     private File JavaDoc moduleRoot;
81
82     /**
83      * Empty constructor used by betwixt
84      */

85     public ModuleDefinition() {
86     }
87
88     /**
89      * Minimal definition
90      * @param name
91      * @param version
92      * @param className
93      */

94     public ModuleDefinition(String JavaDoc name, String JavaDoc version, String JavaDoc className) {
95         setName(name);
96         setVersion(version);
97         setClassName(className);
98     }
99
100     /**
101      * @return Returns the name.
102      */

103     public String JavaDoc getName() {
104         return this.name;
105     }
106
107     /**
108      * If the displayName is empty the displayName will get set too.
109      * @param name The name to set.
110      */

111     public void setName(String JavaDoc name) {
112         this.name = name;
113         if (StringUtils.isEmpty(this.getDisplayName())) {
114             this.setDisplayName(name);
115         }
116     }
117
118     /**
119      * @return Returns the version.
120      */

121     public String JavaDoc getVersion() {
122         return this.version;
123     }
124
125     /**
126      * @param version The version to set.
127      */

128     public void setVersion(String JavaDoc version) {
129         this.version = version;
130     }
131
132     /**
133      * @return Returns the dependencies.
134      */

135     public Collection JavaDoc getDependencies() {
136         return this.dependencies;
137     }
138
139     public void addDependency(DependencyDefinition dep) {
140         this.dependencies.add(dep);
141     }
142
143     /**
144      * True if def is a direct or inderect dipendency of this module
145      * @param def
146      * @return
147      */

148     public boolean isDependent(ModuleDefinition def) {
149         // direct dipendency
150
for (Iterator JavaDoc iter = this.dependencies.iterator(); iter.hasNext();) {
151             DependencyDefinition dep = (DependencyDefinition) iter.next();
152             if (dep.getName().equals(def.getName())) {
153                 return true;
154             }
155         }
156
157         // indirect dipendency
158
for (Iterator JavaDoc iter = this.dependencies.iterator(); iter.hasNext();) {
159             DependencyDefinition dep = (DependencyDefinition) iter.next();
160             ModuleDefinition depDef = ModuleRegistration.getInstance().getModuleDefinition(dep.getName());
161             if (depDef.isDependent(def)) {
162                 return true;
163             }
164         }
165         // no dependency
166
return false;
167     }
168
169     /**
170      * @return Returns the servlets.
171      */

172     public Collection JavaDoc getServlets() {
173         return this.servlets;
174     }
175
176     /**
177      * Add a servlet definition
178      */

179     public void addServlet(ServletDefinition def) {
180         if (StringUtils.isEmpty(def.getComment())) {
181             def.setComment("a servlet used by the " + this.getName() + " module");
182         }
183         this.servlets.add(def);
184     }
185
186     /**
187      * @return Returns the repositories.
188      */

189     public Collection JavaDoc getRepositories() {
190         return this.repositories;
191     }
192
193     /**
194      * Add a repository definition
195      * @param repository
196      */

197     public void addRepository(RepositoryDefinition repository) {
198         this.repositories.add(repository);
199     }
200
201     /**
202      * @return Returns the className.
203      */

204     public String JavaDoc getClassName() {
205         return this.className;
206     }
207
208     /**
209      * @param className The className to set.
210      */

211     public void setClassName(String JavaDoc className) {
212         this.className = className;
213     }
214
215     /**
216      * @return Returns the description.
217      */

218     public String JavaDoc getDescription() {
219         return this.description;
220     }
221
222     /**
223      * @param description The description to set.
224      */

225     public void setDescription(String JavaDoc description) {
226         this.description = description;
227     }
228
229     /**
230      * @return Returns the displayName.
231      */

232     public String JavaDoc getDisplayName() {
233         return this.displayName;
234     }
235
236     /**
237      * @param displayName The displayName to set.
238      */

239     public void setDisplayName(String JavaDoc displayName) {
240         this.displayName = displayName;
241     }
242
243     /**
244      * Getter for <code>moduleRoot</code>.
245      * @return Returns the moduleRoot.
246      */

247     public File JavaDoc getModuleRoot() {
248         return this.moduleRoot;
249     }
250
251     /**
252      * Setter for <code>moduleRoot</code>.
253      * @param moduleRoot The moduleRoot to set.
254      */

255     public void setModuleRoot(File JavaDoc moduleRoot) {
256         this.moduleRoot = moduleRoot;
257     }
258
259     /**
260      * @return the properties
261      */

262     public Collection JavaDoc getProperties() {
263         return properties;
264     }
265
266     public void addProperty(PropertyDefinition property) {
267         properties.add(property);
268     }
269
270     /**
271      * Convenience method which returns the value of the given property,
272      * or null if it does not exist.
273      */

274     public String JavaDoc getProperty(String JavaDoc propertyName) {
275         final Iterator JavaDoc it = properties.iterator();
276         while (it.hasNext()) {
277             final PropertyDefinition p = (PropertyDefinition) it.next();
278             if (propertyName.equals(p.getName())) {
279                 return p.getValue();
280             }
281         }
282         return null;
283     }
284 }
285
Popular Tags