View Javadoc

1   /**
2    * This file Copyright (c) 2003-2010 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  
61      public ModuleDefinition() {
62      }
63  
64      public ModuleDefinition(String name, Version version, String className, Class<? extends ModuleVersionHandler> versionHandler) {
65          this.name = name;
66          this.version = version;
67          this.className = className;
68          this.versionHandler = versionHandler;
69      }
70  
71      public String getName() {
72          return this.name;
73      }
74  
75      public void setName(String name) {
76          this.name = name;
77      }
78  
79      /**
80       * Returns the displayName or the name if displayName wasn't set.
81       */
82      public String getDisplayName() {
83          if (StringUtils.isEmpty(this.displayName)) {
84              return this.name;
85          }
86  
87          return this.displayName;
88      }
89  
90      public void setDisplayName(String displayName) {
91          this.displayName = displayName;
92      }
93  
94      public String getDescription() {
95          return this.description;
96      }
97  
98      public void setDescription(String description) {
99          this.description = description;
100     }
101 
102     public String getClassName() {
103         return this.className;
104     }
105 
106     public void setClassName(String className) {
107         this.className = className;
108     }
109 
110     public Class<? extends ModuleVersionHandler> getVersionHandler() {
111         return versionHandler;
112     }
113 
114     public void setVersionHandler(Class<? extends ModuleVersionHandler> versionHandler) {
115         this.versionHandler = versionHandler;
116     }
117 
118     public void setVersion(Version version) {
119         this.version = version;
120     }
121 
122     public Version getVersion() {
123         return version;
124     }
125 
126     public Collection<DependencyDefinition> getDependencies() {
127         return this.dependencies;
128     }
129 
130     public void addDependency(DependencyDefinition dep) {
131         dependencies.add(dep);
132     }
133 
134     public Collection<ServletDefinition> getServlets() {
135         return this.servlets;
136     }
137 
138     public void addServlet(ServletDefinition def) {
139         if (StringUtils.isEmpty(def.getComment())) {
140             def.setComment("a servlet used by the " + this.getName() + " module");
141         }
142         this.servlets.add(def);
143     }
144 
145     public Collection<RepositoryDefinition> getRepositories() {
146         return this.repositories;
147     }
148 
149     public void addRepository(RepositoryDefinition repository) {
150         this.repositories.add(repository);
151     }
152 
153     public Collection<PropertyDefinition> getProperties() {
154         return properties;
155     }
156 
157     public void addProperty(PropertyDefinition property) {
158         properties.add(property);
159     }
160 
161     /**
162      * Convenience method which returns the value of the given property,
163      * or null if it does not exist.
164      */
165     public String getProperty(String propertyName) {
166         for (PropertyDefinition p : properties) {
167             if (propertyName.equals(p.getName())) {
168                 return p.getValue();
169             }
170         }
171         return null;
172     }
173 
174     public String toString() {
175         return getDisplayName() + " (version " + version + ")";
176     }
177 }