]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.init/src/org/argeo/init/a2/A2Contribution.java
Improve initialisation.
[lgpl/argeo-commons.git] / org.argeo.init / src / org / argeo / init / a2 / A2Contribution.java
1 package org.argeo.init.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 public Iterable<A2Component> listComponents(Object filter) {
34 return components.values();
35 }
36
37 A2Component getOrAddComponent(String componentId) {
38 if (components.containsKey(componentId))
39 return components.get(componentId);
40 else
41 return new A2Component(this, componentId);
42 }
43
44 public ProvisioningSource getSource() {
45 return source;
46 }
47
48 public String getId() {
49 return id;
50 }
51
52 @Override
53 public int compareTo(A2Contribution o) {
54 return id.compareTo(o.id);
55 }
56
57 @Override
58 public int hashCode() {
59 return id.hashCode();
60 }
61
62 @Override
63 public boolean equals(Object obj) {
64 if (obj instanceof A2Contribution) {
65 A2Contribution o = (A2Contribution) obj;
66 return id.equals(o.id);
67 } else
68 return false;
69 }
70
71 @Override
72 public String toString() {
73 return id;
74 }
75
76 void asTree(String prefix, StringBuffer buf) {
77 if (prefix == null)
78 prefix = "";
79 for (String componentId : components.keySet()) {
80 buf.append(prefix);
81 buf.append(componentId);
82 A2Component component = components.get(componentId);
83 component.asTree(prefix, buf);
84 buf.append('\n');
85 }
86 }
87
88 }