1
2
3
4
5
6
7
8
9
10 package org.apache.commons.messagelet;
11
12 import javax.servlet.ServletContext;
13 import javax.servlet.ServletException;
14
15 import org.apache.commons.logging.Log;
16 import org.apache.commons.logging.LogFactory;
17
18
19
20
21
22
23
24
25 public abstract class MessageDrivenObjectSupport implements MessageDrivenObject {
26
27
28
29 private Log log = LogFactory.getLog( getClass() );
30
31
32
33
34 private ServletContext context;
35
36
37
38 public MessageDrivenObjectSupport() {
39 }
40
41 public ServletContext getServletContext() {
42 return context;
43 }
44
45
46
47
48
49
50 public void init() throws ServletException {
51 }
52
53
54
55 public void init(ServletContext context) throws ServletException {
56 this.context = context;
57 init();
58 }
59
60 public void destroy() {
61 this.context = null;
62 }
63
64
65
66
67
68
69
70
71
72
73 protected Log getLog() {
74 return log;
75 }
76
77
78 protected void log( String message ) {
79 if ( context == null ) {
80 log.error( "No Servletcontext available so cannot use it for logging" );
81 log.info( message );
82 }
83 else {
84 context.log( message );
85 }
86 }
87
88
89 protected void log( String message, Throwable t) {
90 if ( context == null ) {
91 log.error( "No Servletcontext available so cannot use it for logging" );
92 log.error( message, t );
93 }
94 else {
95 context.log( message, t );
96 }
97 }
98 }