1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package nl.toolforge.karma.core.module;
20
21 import nl.toolforge.karma.core.Version;
22
23 import java.util.regex.PatternSyntaxException;
24
25 /***
26 * Class modelling a <code><module></code>-element in a manifest file.
27 *
28 * @author D.A. Smedes
29 * @version $Id: ModuleDigester.java,v 1.1 2004/11/10 22:25:11 hippe Exp $
30 */
31 public final class ModuleDigester {
32
33
34
35
36 public static final String NAME_PATTERN_STRING = "[A-Za-z//-//d]+";
37 public static final String LOCATION_PATTERN_STRING = "[0-9a-z//-//_]+";
38
39 private String name = null;
40 private String location = null;
41
42 private String version = null;
43
44 /***
45 *
46 */
47 public ModuleDigester(String name, String location) {
48
49 if (name == null || !name.matches(NAME_PATTERN_STRING)) {
50 throw new PatternSyntaxException(
51 "Pattern mismatch for name-attribute. Should match " + NAME_PATTERN_STRING, name, -1);
52 }
53 this.name = name;
54
55 if (location == null || !location.matches(LOCATION_PATTERN_STRING)) {
56 throw new PatternSyntaxException(
57 "Pattern mismatch for location-attribute. Should match " + LOCATION_PATTERN_STRING, location, -1);
58 }
59 this.location = location;
60 }
61
62
63 public String getName() {
64 return name;
65 }
66
67 public String getLocation() {
68 return location;
69 }
70
71 /***
72 * Sets the modules' version. {@link nl.toolforge.karma.core.Version} is used to validate the version-string that
73 * is passed as a parameter.
74 *
75 * @param version Version string.
76 */
77 public void setVersion(String version) {
78
79 if (!version.matches(Version.VERSION_PATTERN_STRING)) {
80 throw new PatternSyntaxException(
81 "Pattern mismatch for version. Should match " + Version.VERSION_PATTERN_STRING, version, -1);
82 }
83 this.version = version;
84 }
85
86 public String getVersion() {
87 return version;
88 }
89
90 /***
91 * Modules are equal when their name and location are equal.
92 *
93 * @param o The object instance that should be compared with <code>this</code>.
94 * @return <code>true</code> if this module descriptor
95 */
96 public boolean equals(Object o) {
97
98 if (o instanceof ModuleDigester) {
99 if (
100 (getName().equals(((ModuleDigester) o).getName())) &&
101 (getLocation().equals(((ModuleDigester) o).getLocation())) ) {
102 return true;
103 } else {
104 return false;
105 }
106 } else {
107 return false;
108 }
109 }
110
111 public int hashCode() {
112
113 return name.hashCode() + location.hashCode();
114 }
115 }
116
117