1 package org.codehaus.plexus.maven.plugin.report;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.util.Iterator;
20 import java.util.List;
21
22 import org.codehaus.doxia.sink.Sink;
23 import org.codehaus.plexus.util.StringUtils;
24 import org.jdom.Element;
25
26
27
28
29
30 public class Component
31 implements Comparable
32 {
33 private String description;
34
35 private String role;
36
37 private String roleHint;
38
39 private String alias;
40
41 private String version;
42
43 private String implementation;
44
45 private String instantiationStrategy;
46
47 private Requirements requirements;
48
49 private Configuration configuration;
50
51 public Component( Element component )
52 {
53 description = component.getChildText( "description" );
54 role = component.getChildText( "role" );
55 roleHint = component.getChildText( "role-hint" );
56 alias = component.getChildText( "alias" );
57 version = component.getChildText( "version" );
58 implementation = component.getChildText( "implementation" );
59 instantiationStrategy = component.getChildTextTrim( "instantiation-strategy" );
60
61 List list = component.getChildren( "requirements" );
62 for ( Iterator it = list.iterator(); it.hasNext(); )
63 {
64 Element element = (Element) it.next();
65
66 requirements = new Requirements( element );
67 }
68
69 list = component.getChildren( "configuration" );
70 for ( Iterator it = list.iterator(); it.hasNext(); )
71 {
72 Element element = (Element) it.next();
73 configuration = new Configuration( element );
74 }
75 }
76
77 public String getRole()
78 {
79 return role;
80 }
81
82 public String getRoleHint()
83 {
84 return roleHint;
85 }
86
87 public String getImplementation()
88 {
89 return implementation;
90 }
91
92 public boolean hasRoleHint()
93 {
94 return StringUtils.isNotEmpty( roleHint );
95 }
96
97 public void print( Sink sink, String javaDocDestDir, String jxrDestDir )
98 {
99
100
101
102
103 String title;
104 if ( !hasRoleHint() )
105 {
106 title = role;
107 }
108 else
109 {
110 title = roleHint;
111 }
112
113
114
115
116
117 sink.section3();
118 sink.sectionTitle3();
119 sink.text( "Component: " + title );
120 sink.sectionTitle3_();
121 sink.section3_();
122
123 sink.table();
124
125 writeField( sink, "Role", role );
126
127 writeField( sink, "Role hint", roleHint );
128
129 sink.tableRow();
130 sink.tableCell();
131 sink.text( "Implementation" );
132 sink.tableCell_();
133 sink.tableCell();
134 sink.monospaced();
135 sink.text( implementation );
136 sink.monospaced_();
137 sink.text( " " );
138 sink.link( "../" + javaDocDestDir + "/" + implementation.replace( '.', '/' ) + ".html" );
139 sink.text( "javadoc" );
140 sink.link_();
141 sink.link( "../" + jxrDestDir + "/" + implementation.replace( '.', '/' ) + ".html" );
142 sink.text( " " );
143 sink.text( "xref" );
144 sink.link_();
145 sink.tableCell_();
146 sink.tableRow_();
147
148 writeField( sink, "Description", description );
149
150 writeField( sink, "Alias", alias );
151
152 writeField( sink, "Version", version );
153
154 writeField( sink, "Instantiation strategy", instantiationStrategy );
155
156 sink.table_();
157
158 if ( requirements != null )
159 {
160 requirements.print( sink );
161 }
162
163 if ( configuration != null )
164 {
165 configuration.print( sink );
166 }
167 }
168
169 private void writeField( Sink sink, String name, String value )
170 {
171 if ( StringUtils.isNotEmpty( value ) )
172 {
173 sink.tableRow();
174 sink.tableCell();
175 sink.text( name );
176 sink.tableCell_();
177 sink.tableCell();
178 sink.monospaced();
179 sink.text( value );
180 sink.monospaced_();
181 sink.tableCell_();
182 sink.tableRow_();
183 }
184 }
185
186 public int compareTo( Object o )
187 {
188 return ( (Component) o ).getId().compareTo( getId() );
189 }
190
191 private String getId()
192 {
193 if ( !hasRoleHint() )
194 {
195 return role;
196 }
197 else
198 {
199 return role + ":" + roleHint;
200 }
201 }
202 }