]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.init/src/org/argeo/init/a2/A2Contribution.java
Introduce cms ping command
[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 final static String DEFAULT = "default";
17
18 private final ProvisioningSource source;
19 private final String id;
20
21 final Map<String, A2Component> components = Collections.synchronizedSortedMap(new TreeMap<>());
22
23 /**
24 * The contribution must be added to the source. Rather use
25 * {@link AbstractProvisioningSource#getOrAddContribution(String)} than this
26 * contructor directly.
27 */
28 public A2Contribution(ProvisioningSource context, String id) {
29 this.source = context;
30 this.id = id;
31 // if (context != null)
32 // context.contributions.put(id, this);
33 }
34
35 public Iterable<A2Component> listComponents(Object filter) {
36 return components.values();
37 }
38
39 A2Component getOrAddComponent(String componentId) {
40 if (components.containsKey(componentId))
41 return components.get(componentId);
42 else
43 return new A2Component(this, componentId);
44 }
45
46 public ProvisioningSource getSource() {
47 return source;
48 }
49
50 public String getId() {
51 return id;
52 }
53
54 @Override
55 public int compareTo(A2Contribution o) {
56 return id.compareTo(o.id);
57 }
58
59 @Override
60 public int hashCode() {
61 return id.hashCode();
62 }
63
64 @Override
65 public boolean equals(Object obj) {
66 if (obj instanceof A2Contribution) {
67 A2Contribution o = (A2Contribution) obj;
68 return id.equals(o.id);
69 } else
70 return false;
71 }
72
73 @Override
74 public String toString() {
75 return id;
76 }
77
78 void asTree(String prefix, StringBuffer buf) {
79 if (prefix == null)
80 prefix = "";
81 for (String componentId : components.keySet()) {
82 buf.append(prefix);
83 buf.append(componentId);
84 A2Component component = components.get(componentId);
85 component.asTree(prefix, buf);
86 buf.append('\n');
87 }
88 }
89
90 }