1 package no.sesat.mojo.modes;
2
3 import java.util.List;
4 import java.util.Set;
5 import java.util.TreeSet;
6 import java.util.Vector;
7
8 import com.sun.javadoc.ClassDoc;
9 import com.sun.javadoc.MethodDoc;
10 import com.sun.javadoc.Parameter;
11
12
13
14
15
16 public class ConfigElement extends ConfigAbstract {
17
18 protected final List<ConfigAttribute> attributes = new Vector<ConfigAttribute>();
19 private final Set<String> attribNames = new TreeSet<String>();
20 protected final int id;
21 private static int idCounter = 0;
22
23 protected List<ConfigElement> children = new Vector<ConfigElement>();
24
25
26
27
28 public ConfigElement(final String name) {
29 id = ++idCounter;
30 this.name = name;
31 }
32
33
34
35
36 public ConfigElement(final ClassDoc klass) {
37 this(klass.name());
38
39 doc = klass.commentText();
40
41
42 attributes.add(new ConfigAttribute("inherit"));
43
44 build(klass);
45 }
46
47
48
49
50 public void applyNameFilter(final NameFilter filter) {
51 name = filter.filter(name);
52 }
53
54
55
56
57 public void addChildren(final List<ConfigElement> childrenList) {
58 children.addAll(childrenList);
59 }
60
61
62
63
64 public void addChild(final ConfigElement child) {
65 children.add(child);
66 }
67
68 private void build(final ClassDoc klass) {
69
70 if (klass != null) {
71 final MethodDoc[] methods = klass.methods();
72 for (int i = 0; i < methods.length; i++) {
73
74 final MethodDoc methodDoc = methods[i];
75
76 if (!attribNames.contains(methodDoc.name())
77 && (methodDoc.name().startsWith("set") || methodDoc.name().startsWith("add"))) {
78 final Parameter[] parameters = methodDoc.parameters();
79 if (parameters.length == 1) {
80 attribNames.add(methodDoc.name());
81 attributes.add(new ConfigAttribute(methodDoc));
82
83 }
84 }
85 }
86 build(klass.superclass());
87 }
88 }
89 }