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 org.apache.commons.lang.StringUtils;
37  
38  import java.util.ArrayList;
39  import java.util.Collection;
40  
41  import info.magnolia.module.ModuleVersionHandler;
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 addDependency(DependencyDefinition dep) {
132         dependencies.add(dep);
133     }
134 
135     public Collection<ServletDefinition> getServlets() {
136         return this.servlets;
137     }
138 
139     public void addServlet(ServletDefinition def) {
140         if (StringUtils.isEmpty(def.getComment())) {
141             def.setComment("a servlet used by the " + this.getName() + " module");
142         }
143         this.servlets.add(def);
144     }
145 
146     public Collection<RepositoryDefinition> getRepositories() {
147         return this.repositories;
148     }
149 
150     public void addRepository(RepositoryDefinition repository) {
151         this.repositories.add(repository);
152     }
153 
154     public Collection<PropertyDefinition> getProperties() {
155         return properties;
156     }
157 
158     public void addProperty(PropertyDefinition property) {
159         properties.add(property);
160     }
161 
162     public Collection<ComponentsDefinition> getComponents() {
163         return components;
164     }
165 
166     public void setComponents(Collection<ComponentsDefinition> components) {
167         this.components = components;
168     }
169 
170     public boolean addComponents(ComponentsDefinition components) {
171         return this.components.add(components);
172     }
173 
174     /**
175      * Convenience method which returns the value of the given property,
176      * or null if it does not exist.
177      */
178     public String getProperty(String propertyName) {
179         for (PropertyDefinition p : properties) {
180             if (propertyName.equals(p.getName())) {
181                 return p.getValue();
182             }
183         }
184         return null;
185     }
186 
187     @Override
188     public String toString() {
189         return getDisplayName() + " (version " + version + ")";
190     }
191 }