1
2
3
4
5
6
7
8
9
10
11
12
13 package it.imolinfo.jbi4corba.jbi.component.runtime;
14
15 import java.util.MissingResourceException;
16 import java.util.logging.Logger;
17 import javax.jbi.JBIException;
18 import javax.jbi.component.ComponentContext;
19 import javax.jbi.messaging.DeliveryChannel;
20 import javax.jbi.messaging.MessageExchange;
21 import javax.jbi.messaging.MessagingException;
22
23
24
25
26
27
28
29
30
31
32
33 public class RuntimeContext {
34
35 private static RuntimeContext sRuntimeContext;
36
37
38 private RuntimeContext() {
39 }
40
41 public static RuntimeContext getInstance() {
42 if ( sRuntimeContext == null ) {
43 synchronized (RuntimeContext.class) {
44 if ( sRuntimeContext == null ) {
45 sRuntimeContext = new RuntimeContext();
46 }
47 }
48 }
49 return sRuntimeContext;
50 }
51
52
53
54
55 private ComponentContext mComponentContext;
56
57
58
59
60
61
62 public ComponentContext getComponentContext() {
63 return this.mComponentContext;
64 }
65
66
67
68
69
70
71 public void setComponentContext(ComponentContext componentContext) {
72 this.mComponentContext = componentContext;
73 this.mDeliveryChannel = null;
74 }
75
76
77
78
79 private DeliveryChannel mDeliveryChannel;
80
81
82
83
84
85
86 public DeliveryChannel getDeliveryChannel() {
87 return this.mDeliveryChannel;
88 }
89
90
91
92
93
94 public void openDeliveryChannel() {
95 try {
96
97 ComponentContext compCtx = getComponentContext();
98 this.mDeliveryChannel = compCtx.getDeliveryChannel();
99 } catch (MessagingException ex) {
100 RuntimeHelper.logDebug(ex);
101 } catch ( Exception ex) {
102 RuntimeHelper.logDebug(ex);
103 }
104 }
105
106
107
108 public void closeDeliveryChannel() {
109 try {
110
111 if ( this.mDeliveryChannel != null ) {
112 this.mDeliveryChannel.close();
113 }
114 } catch (MessagingException ex) {
115 RuntimeHelper.logDebug(ex);
116 } finally {
117
118 this.mDeliveryChannel = null;
119 }
120 }
121
122
123 private Logger mDefLogger;
124
125
126
127 private Logger getDefaultLogger() {
128 if ( mDefLogger == null ) {
129 this.mDefLogger = Logger.getLogger(RuntimeContext.class.getName(), null);
130 }
131 return this.mDefLogger;
132 }
133
134
135
136
137 private Logger mLogger;
138
139
140
141
142
143
144
145 public void setLogger(String name, String resourceBundle) {
146
147 if (this.mComponentContext != null) {
148
149 try {
150 this.mLogger = this.mComponentContext.getLogger(name, resourceBundle);
151 } catch (MissingResourceException ex) {
152 ex.printStackTrace();
153 } catch (JBIException ex) {
154 ex.printStackTrace();
155 }
156 } else {
157 this.mLogger = Logger.getLogger(name, resourceBundle);
158 }
159 }
160
161
162
163
164
165
166 public Logger getLogger() {
167
168 if (this.mLogger == null) {
169
170
171 return getDefaultLogger();
172 }
173 return this.mLogger;
174 }
175
176
177
178
179
180 public String getComponentName() {
181 String componentName = null;
182
183 if (this.mComponentContext != null) {
184 componentName = this.mComponentContext.getComponentName();
185 }
186 return componentName;
187 }
188
189
190
191
192 private MessageExchangeHandlerFactory mMEHandlerFactory;
193
194
195
196
197
198
199 public MessageExchangeHandlerFactory getMessageExchangeHandlerFactory() {
200 return this.mMEHandlerFactory;
201 }
202
203
204
205
206
207
208 public void setMessageExchangeHandlerFactory(MessageExchangeHandlerFactory factory) {
209 this.mMEHandlerFactory = factory;
210 }
211
212
213
214
215 public MessageExchangeHandler newMessageExchangeHandler(MessageExchange msgExchange) {
216 MessageExchangeHandlerFactory factory = getMessageExchangeHandlerFactory();
217 if ( factory == null ) {
218 return null;
219 }
220 return factory.newHandler(msgExchange);
221 }
222 }