View Javadoc

1   /**
2    * This file Copyright (c) 2003-2011 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
32   *
33   */
34  package info.magnolia.module.model;
35  
36  import info.magnolia.module.ModuleVersionHandler;
37  
38  import java.util.ArrayList;
39  import java.util.Collection;
40  
41  import org.apache.commons.lang.StringUtils;
42  
43  /**
44   * Describes a module. Bean representation of a module's xml descriptor.
45   *
46   * @author gjoseph
47   * @version $Revision: $ ($Author: $)
48   */
49  public class ModuleDefinition {
50      private String name;
51      private String displayName;
52      private String description;
53      private String className;
54      private Class<? extends ModuleVersionHandler> versionHandler;
55      private Version version;
56      private Collection<DependencyDefinition> dependencies = new ArrayList<DependencyDefinition>();
57      private Collection<ServletDefinition> servlets = new ArrayList<ServletDefinition>();
58      private Collection<RepositoryDefinition> repositories = new ArrayList<RepositoryDefinition>();
59      private Collection<PropertyDefinition> properties = new ArrayList<PropertyDefinition>();
60      private Collection<ComponentsDefinition> components = new ArrayList<ComponentsDefinition>();
61  
62      public ModuleDefinition() {
63      }
64  
65      public ModuleDefinition(String name, Version version, String className, Class<? extends ModuleVersionHandler> versionHandler) {
66          this.name = name;
67          this.version = version;
68          this.className = className;
69          this.versionHandler = versionHandler;
70      }
71  
72      public String getName() {
73          return this.name;
74      }
75  
76      public void setName(String name) {
77          this.name = name;
78      }
79  
80      /**
81       * Returns the displayName or the name if displayName wasn't set.
82       */
83      public String getDisplayName() {
84          if (StringUtils.isEmpty(this.displayName)) {
85              return this.name;
86          }
87  
88          return this.displayName;
89      }
90  
91      public void setDisplayName(String displayName) {
92          this.displayName = displayName;
93      }
94  
95      public String getDescription() {
96          return this.description;
97      }
98  
99      public void setDescription(String description) {
100         this.description = description;
101     }
102 
103     public String getClassName() {
104         return this.className;
105     }
106 
107     public void setClassName(String className) {
108         this.className = className;
109     }
110 
111     public Class<? extends ModuleVersionHandler> getVersionHandler() {
112         return versionHandler;
113     }
114 
115     public void setVersionHandler(Class<? extends ModuleVersionHandler> versionHandler) {
116         this.versionHandler = versionHandler;
117     }
118 
119     public void setVersion(Version version) {
120         this.version = version;
121     }
122 
123     public Version getVersion() {
124         return version;
125     }
126 
127     public Collection<DependencyDefinition> getDependencies() {
128         return this.dependencies;
129     }
130 
131     public void setDependencies(Collection<DependencyDefinition> dependencies) {
132         this.dependencies = dependencies;
133     }
134 
135     public void addDependency(DependencyDefinition dep) {
136         dependencies.add(dep);
137     }
138 
139     public Collection<ServletDefinition> getServlets() {
140         return this.servlets;
141     }
142 
143     public void setServlets(Collection<ServletDefinition> servlets) {
144         for (ServletDefinition def : servlets) {
145             this.addServlet(def);
146         }
147     }
148 
149     public void addServlet(ServletDefinition def) {
150         if (StringUtils.isEmpty(def.getComment())) {
151             def.setComment("a servlet used by the " + this.getName() + " module");
152         }
153         this.servlets.add(def);
154     }
155 
156     public Collection<RepositoryDefinition> getRepositories() {
157         return this.repositories;
158     }
159 
160     public void setRepositories(Collection<RepositoryDefinition> repositories) {
161         this.repositories = repositories;
162     }
163 
164     public void addRepository(RepositoryDefinition repository) {
165         this.repositories.add(repository);
166     }
167 
168     public Collection<PropertyDefinition> getProperties() {
169         return properties;
170     }
171 
172     public void setProperties(Collection<PropertyDefinition> properties) {
173         this.properties = properties;
174     }
175 
176     public void addProperty(PropertyDefinition property) {
177         properties.add(property);
178     }
179 
180     public Collection<ComponentsDefinition> getComponents() {
181         return components;
182     }
183 
184     public void setComponents(Collection<ComponentsDefinition> components) {
185         this.components = components;
186     }
187 
188     public boolean addComponents(ComponentsDefinition components) {
189         return this.components.add(components);
190     }
191 
192     /**
193      * Convenience method which returns the value of the given property,
194      * or null if it does not exist.
195      */
196     public String getProperty(String propertyName) {
197         for (PropertyDefinition p : properties) {
198             if (propertyName.equals(p.getName())) {
199                 return p.getValue();
200             }
201         }
202         return null;
203     }
204 
205     @Override
206     public String toString() {
207         return getDisplayName() + " (version " + version + ")";
208     }
209 }