1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package nl.toolforge.karma.core.manifest;
20
21 import nl.toolforge.karma.core.module.ModuleDigester;
22
23 import java.util.ArrayList;
24 import java.util.Hashtable;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.regex.PatternSyntaxException;
28
29 /***
30 * Mapping of a manifest file and its included manifest files (any level deep possible). Note that the structure that
31 * is build is merely the template for the real <code>Manifest</code>.
32 *
33 * @author D.A. Smedes
34 * @version $Id: ManifestStructure.java,v 1.6 2004/11/10 23:53:09 asmedes Exp $
35 */
36 public final class ManifestStructure {
37
38 private String name = null;
39 private String version = null;
40 private String type = null;
41
42 private String description = null;
43
44 private Map childs = null;
45 private List modules = null;
46
47 public ManifestStructure() {
48 childs = new Hashtable();
49 modules = new ArrayList();
50 }
51
52 public Map getChilds() {
53 return childs;
54 }
55
56 public ManifestStructure getChild(String childName) {
57 return (ManifestStructure) childs.get(childName);
58 }
59
60 public void addChild(ManifestStructure structure) throws ManifestException {
61 if (childs.containsKey(structure.getName())) {
62 throw new ManifestException(ManifestException.MANIFEST_NAME_RECURSION, new Object[] {structure.getName()});
63 }
64 childs.put(structure.getName(), structure);
65 }
66
67 public List getModules() {
68 return modules;
69 }
70
71 public void addModule(ModuleDigester digester) throws ManifestException {
72
73 if (modules.contains(digester)) {
74 throw new ManifestException(ManifestException.DUPLICATE_MODULE, new Object[] {digester.getName()});
75 }
76 modules.add(digester);
77 }
78
79 public String getName() {
80 return name;
81 }
82
83 public void setName(String name) {
84
85 if (name.trim().startsWith(".")) {
86 throw new IllegalArgumentException("A manifest name cannot start with a `.`.");
87 }
88 this.name = name;
89 }
90
91 public String getVersion() {
92 return version;
93 }
94
95 public void setVersion(String version) {
96
97 if (!version.matches("//d{1}-//d{1}")) {
98 throw new PatternSyntaxException("A manifests' version attribute should look like '0-0'.", "//d{1}-//d{1}", -1);
99 }
100 this.version = version;
101 }
102
103 public String getType() {
104 return type;
105 }
106
107 public void setType(String type) {
108 this.type = type;
109 }
110
111 public String getDescription() {
112 return description;
113 }
114
115 public void setDescription(String description) {
116 this.description = description;
117 }
118
119 public void update(ManifestStructure child) {
120
121 this.name = child.name;
122 this.type = child.type;
123 this.version = child.version;
124 this.description = child.description;
125 this.childs = child.childs;
126 this.modules = child.modules;
127 }
128 }