]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.osgi.boot/src/org/argeo/osgi/a2/A2Contribution.java
Merge remote-tracking branch 'origin/master' into v2.x
[lgpl/argeo-commons.git] / org.argeo.osgi.boot / src / org / argeo / osgi / a2 / A2Contribution.java
1 package org.argeo.osgi.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 public 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 /**
22 * The contribution must be added to the source. Rather use
23 * {@link AbstractProvisioningSource#getOrAddContribution(String)} than this
24 * contructor directly.
25 */
26 public A2Contribution(ProvisioningSource context, String id) {
27 this.source = context;
28 this.id = id;
29 // if (context != null)
30 // context.contributions.put(id, this);
31 }
32
33 A2Component getOrAddComponent(String componentId) {
34 if (components.containsKey(componentId))
35 return components.get(componentId);
36 else
37 return new A2Component(this, componentId);
38 }
39
40 public ProvisioningSource getSource() {
41 return source;
42 }
43
44 public String getId() {
45 return id;
46 }
47
48 @Override
49 public int compareTo(A2Contribution o) {
50 return id.compareTo(o.id);
51 }
52
53 @Override
54 public int hashCode() {
55 return id.hashCode();
56 }
57
58 @Override
59 public boolean equals(Object obj) {
60 if (obj instanceof A2Contribution) {
61 A2Contribution o = (A2Contribution) obj;
62 return id.equals(o.id);
63 } else
64 return false;
65 }
66
67 @Override
68 public String toString() {
69 return id;
70 }
71
72 void asTree(String prefix, StringBuffer buf) {
73 if (prefix == null)
74 prefix = "";
75 for (String componentId : components.keySet()) {
76 buf.append(prefix);
77 buf.append(componentId);
78 A2Component component = components.get(componentId);
79 component.asTree(prefix, buf);
80 buf.append('\n');
81 }
82 }
83
84 }