]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.osgi.boot/src/org/argeo/osgi/boot/a2/A2Contribution.java
Rename container scripts.
[lgpl/argeo-commons.git] / org.argeo.osgi.boot / src / org / argeo / osgi / boot / a2 / A2Contribution.java
1 package org.argeo.osgi.boot.a2;
2
3 import java.util.Collections;
4 import java.util.Map;
5 import java.util.TreeMap;
6
7 /**
8 * A category grouping a set of {@link A2Component}, typically based on the
9 * provider of these components. This is the equivalent of Maven's group Id.
10 */
11 class A2Contribution implements Comparable<A2Contribution> {
12 final static String BOOT = "boot";
13 final static String RUNTIME = "runtime";
14 final static String CLASSPATH = "classpath";
15
16 private final ProvisioningSource source;
17 private final String id;
18
19 final Map<String, A2Component> components = Collections.synchronizedSortedMap(new TreeMap<>());
20
21 public A2Contribution(ProvisioningSource context, String id) {
22 this.source = context;
23 this.id = id;
24 if (context != null)
25 context.contributions.put(id, this);
26 }
27
28 A2Component getOrAddComponent(String componentId) {
29 if (components.containsKey(componentId))
30 return components.get(componentId);
31 else
32 return new A2Component(this, componentId);
33 }
34
35 public ProvisioningSource getSource() {
36 return source;
37 }
38
39 public String getId() {
40 return id;
41 }
42
43 @Override
44 public int compareTo(A2Contribution o) {
45 return id.compareTo(o.id);
46 }
47
48 @Override
49 public int hashCode() {
50 return id.hashCode();
51 }
52
53 @Override
54 public boolean equals(Object obj) {
55 if (obj instanceof A2Contribution) {
56 A2Contribution o = (A2Contribution) obj;
57 return id.equals(o.id);
58 } else
59 return false;
60 }
61
62 @Override
63 public String toString() {
64 return id;
65 }
66
67 void asTree(String prefix, StringBuffer buf) {
68 if (prefix == null)
69 prefix = "";
70 for (String componentId : components.keySet()) {
71 buf.append(prefix);
72 buf.append(componentId);
73 A2Component component = components.get(componentId);
74 component.asTree(prefix, buf);
75 buf.append('\n');
76 }
77 }
78
79 }