1
2
3
4
5
6
7
8 package it.imolinfo.jbi4ejb.exception;
9
10 import it.imolinfo.jbi4ejb.jbi.Messages;
11 import java.util.MissingResourceException;
12
13
14
15
16
17
18
19 public class Jbi4EjbException extends Exception {
20
21
22
23
24 private static final long serialVersionUID = 3762815969835563319L;
25
26
27
28
29 private String localizedMessage;
30
31
32
33
34
35
36 public Jbi4EjbException(final String message) {
37 this(message, null, null);
38 }
39
40
41
42
43
44
45
46 public Jbi4EjbException(final String message, final Throwable cause) {
47 this(message, null, cause);
48 }
49
50
51
52
53
54
55 public Jbi4EjbException(final Throwable cause) {
56 this(cause.toString(), null, cause);
57
58
59 localizedMessage = getMessage();
60 }
61
62
63
64
65
66
67
68 public Jbi4EjbException(final String message, final Object[] args) {
69 this(message, args, null);
70 }
71
72
73
74
75
76
77
78
79 public Jbi4EjbException(final String message, final Object[] args,
80 final Throwable cause) {
81 super(message, cause);
82 setupLocalizedMessage(args);
83 }
84
85
86
87
88
89
90
91 private void setupLocalizedMessage(final Object[] args) {
92 StackTraceElement[] stackTrace = getStackTrace();
93
94 if (stackTrace.length == 0) {
95 localizedMessage = getMessage();
96 } else {
97 try {
98 Class clazz = Class.forName(stackTrace[0].getClassName());
99 Messages messages = Messages.getMessages(clazz);
100
101 localizedMessage = messages.getString(getMessage(), args);
102 } catch (ClassNotFoundException e) {
103 localizedMessage = getMessage();
104 } catch (MissingResourceException e) {
105 localizedMessage = getMessage();
106 }
107 }
108 }
109
110
111
112 public String getLocalizedMessage() {
113 return localizedMessage;
114 }
115
116
117 }