1 package org.andromda.core.namespace;
2
3 import java.net.URL;
4 import java.util.ArrayList;
5 import java.util.Collection;
6 import java.util.LinkedHashMap;
7 import java.util.Map;
8
9
10
11
12
13
14
15
16 public class NamespaceRegistry
17 {
18
19
20
21 private String name;
22
23
24
25
26
27
28 public String getName()
29 {
30 return this.name;
31 }
32
33
34
35
36
37
38 public void setName(String name)
39 {
40 this.name = name;
41 }
42
43
44
45
46 private boolean shared = false;
47
48
49
50
51
52
53
54 public boolean isShared()
55 {
56 return shared;
57 }
58
59
60
61
62
63
64 public void setShared(final boolean shared)
65 {
66 this.shared = shared;
67 }
68
69
70
71
72
73
74 private final Map<String, String[]> components = new LinkedHashMap<String, String[]>();
75
76
77
78
79
80
81
82 public void registerComponent(final Component component)
83 {
84 if (component != null)
85 {
86 this.components.put(
87 component.getName(),
88 component.getPaths());
89 }
90 }
91
92
93
94
95
96
97 public String[] getRegisteredComponents()
98 {
99 return this.components.keySet().toArray(new String[this.components.size()]);
100 }
101
102
103
104
105
106
107
108 public String[] getPaths(final String name)
109 {
110 return this.components.get(name);
111 }
112
113
114
115
116 private final Map<String, PropertyDefinition> definitions = new LinkedHashMap<String, PropertyDefinition>();
117
118
119
120
121
122
123
124 public PropertyDefinition getPropertyDefinition(final String name)
125 {
126 return this.definitions.get(name);
127 }
128
129
130
131
132
133
134 public void addPropertyDefinitions(final PropertyDefinition[] propertyDefinitions)
135 {
136 for (PropertyDefinition propertyDefinition : propertyDefinitions)
137 {
138 this.addPropertyDefinition(propertyDefinition);
139 }
140 }
141
142
143
144
145
146
147
148 final void copy(final NamespaceRegistry registry)
149 {
150 if (registry != null)
151 {
152 this.addPropertyDefinitions(registry.getPropertyDefinitions());
153 this.components.putAll(registry.components);
154 if (registry.isShared())
155 {
156 this.shared = registry.isShared();
157 }
158 this.resourceRoots.addAll(registry.resourceRoots);
159 }
160 }
161
162
163
164
165
166
167 public PropertyDefinition[] getPropertyDefinitions()
168 {
169 return this.definitions.values().toArray(new PropertyDefinition[this.definitions.size()]);
170 }
171
172
173
174
175
176
177 public void addPropertyDefinition(final PropertyDefinition propertyDefinition)
178 {
179 if (propertyDefinition != null)
180 {
181 this.definitions.put(
182 propertyDefinition.getName(),
183 propertyDefinition);
184 }
185 }
186
187
188
189
190 private Collection<URL> resourceRoots = new ArrayList<URL>();
191
192
193
194
195
196
197 public URL[] getResourceRoots()
198 {
199 return this.resourceRoots.toArray(new URL[this.resourceRoots.size()]);
200 }
201
202
203
204
205
206
207
208 final void addResourceRoot(final URL resourceRoot)
209 {
210 this.resourceRoots.add(resourceRoot);
211 }
212
213
214
215
216 public String toString()
217 {
218 return super.toString() + '[' + this.getName() + ']';
219 }
220 }