1 package org.codehaus.plexus.component.repository.exception;
2
3 import java.io.ByteArrayOutputStream;
4 import java.io.PrintStream;
5
6 import org.codehaus.plexus.classworlds.realm.ClassRealm;
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 public class ComponentLookupException extends Exception {
31 private String LS = System.getProperty("line.separator");
32
33 private String role;
34
35 private String roleHint;
36
37 private ClassRealm realm;
38
39 public ComponentLookupException(String message, String role, String roleHint) {
40 super(message);
41
42 this.role = role;
43
44 this.roleHint = roleHint;
45 }
46
47 public ComponentLookupException(String message, String role, String roleHint, Throwable cause) {
48 super(message, cause);
49
50 this.role = role;
51
52 this.roleHint = roleHint;
53 }
54
55 public ComponentLookupException(String message, String role, String roleHint, ClassRealm realm) {
56 super(message);
57
58 this.role = role;
59
60 this.roleHint = roleHint;
61
62 this.realm = realm;
63 }
64
65 public ComponentLookupException(String message, String role, String roleHint, ClassRealm realm, Throwable cause) {
66 super(message, cause);
67
68 this.role = role;
69
70 this.roleHint = roleHint;
71
72 this.realm = realm;
73 }
74
75 public String getMessage() {
76 StringBuilder sb = new StringBuilder()
77 .append(super.getMessage())
78 .append(LS)
79 .append(" role: ")
80 .append(role)
81 .append(LS)
82 .append(" roleHint: ")
83 .append(roleHint)
84 .append(LS)
85 .append("classRealm: ");
86
87 if (realm != null) {
88 sb.append(realm.getId()).append(LS);
89 ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
90 PrintStream ps = new PrintStream(os);
91 realm.display(ps);
92 sb.append(os.toString());
93 } else {
94 sb.append("none specified");
95 }
96
97 return sb.toString();
98 }
99 }