KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > module > CmsModuleDependency


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/module/CmsModuleDependency.java,v $
3  * Date : $Date: 2005/06/23 11:11:58 $
4  * Version: $Revision: 1.9 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.module;
33
34 /**
35  * Describes an OpenCms module dependency.<p>
36  *
37  * Module dependencies are checked if a module is imported or deleted.
38  * If a module A requires certain resources (like Java classes)
39  * from another module B, a should be made dependend on B.<p>
40  
41  * @author Alexander Kandzior
42  *
43  * @version $Revision: 1.9 $
44  *
45  * @since 6.0.0
46  */

47 public class CmsModuleDependency implements Comparable JavaDoc {
48
49     /** The hash code of the module dependency. */
50     private int m_hashCode;
51
52     /** The name of the module dependency. */
53     private String JavaDoc m_name;
54
55     /** The (minimum) version of the module dependency. */
56     private CmsModuleVersion m_version;
57
58     /**
59      * Generates a new, empty module dependency.<p>
60      *
61      */

62     public CmsModuleDependency() {
63
64         super();
65         m_name = new String JavaDoc();
66         m_version = new CmsModuleVersion("0");
67
68         // pre - calculate the hash code
69
m_hashCode = m_name.concat(m_version.toString()).hashCode();
70     }
71
72     /**
73      * Generates a new module dependency.<p>
74      *
75      * @param moduleName the name of the module dependency
76      * @param minVersion the minimum version of the dependency
77      */

78     public CmsModuleDependency(String JavaDoc moduleName, CmsModuleVersion minVersion) {
79
80         super();
81         m_name = moduleName;
82         m_version = minVersion;
83
84         // pre - calculate the hash code
85
m_hashCode = m_name.concat(m_version.toString()).hashCode();
86     }
87
88     /**
89      * @see java.lang.Comparable#compareTo(java.lang.Object)
90      */

91     public int compareTo(Object JavaDoc obj) {
92
93         if (obj == this) {
94             return 0;
95         }
96         if (obj instanceof CmsModuleDependency) {
97             CmsModuleDependency other = (CmsModuleDependency)obj;
98             if (!m_name.equals(other.m_name)) {
99                 // not same name means no dependency
100
return 0;
101             }
102             // same name: result depends on version numbers
103
return m_version.compareTo(other.m_version);
104         }
105         return 0;
106     }
107
108     /**
109      * Checks if this module depedency depends on another given module dependency.<p>
110      *
111      * @param other the other dependency to check against
112      * @return true if this module depedency depends on the given module dependency
113      */

114     public boolean dependesOn(CmsModuleDependency other) {
115
116         if (!m_name.equals(other.m_name)) {
117             // not same name means no dependency
118
return false;
119         }
120
121         // same name: result depends on version numbers
122
return (m_version.compareTo(other.m_version) <= 0);
123     }
124
125     /**
126      * @see java.lang.Object#equals(java.lang.Object)
127      */

128     public boolean equals(Object JavaDoc obj) {
129
130         if (obj == this) {
131             return true;
132         }
133         if (obj instanceof CmsModuleDependency) {
134             CmsModuleDependency other = (CmsModuleDependency)obj;
135             return m_name.equals(other.m_name) && m_version.equals(other.m_version);
136         }
137         return false;
138     }
139
140     /**
141      * Returns the name of the module dependency.<p>
142      *
143      * @return the name of the module dependency
144      */

145     public String JavaDoc getName() {
146
147         return m_name;
148     }
149
150     /**
151      * Returns the minimum version of the dependency.<p>
152      *
153      * @return the minimum version of the dependency
154      */

155     public CmsModuleVersion getVersion() {
156
157         return m_version;
158     }
159
160     /**
161      * @see java.lang.Object#hashCode()
162      */

163     public int hashCode() {
164
165         return m_hashCode;
166     }
167
168     /** Sets the name of a module dependency.<p>
169      *
170      * @param value the name of a module dependency
171      */

172     public void setName(String JavaDoc value) {
173
174         m_name = value;
175     }
176
177     /** Sets the version of a module dependency.<p>
178      *
179      * @param value the version of a module dependency
180      */

181     public void setVersion(CmsModuleVersion value) {
182
183         m_version = value;
184     }
185
186     /**
187      * @see java.lang.Object#toString()
188      */

189     public String JavaDoc toString() {
190
191         return "[" + getClass().getName() + ", name: " + m_name + ", version: " + m_version + "]";
192     }
193 }
Popular Tags