001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)JMSBindingContext.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.binding.jms;
030:
031: import com.sun.jbi.StringTranslator;
032: import com.sun.jbi.binding.jms.JMSConstants;
033: import com.sun.jbi.binding.jms.config.Config;
034: import com.sun.jbi.binding.jms.deploy.EndpointRegistry;
035: import com.sun.jbi.binding.jms.framework.WorkManager;
036: import com.sun.jbi.binding.jms.mq.MQManager;
037:
038: import java.util.logging.Level;
039:
040: import java.util.logging.Logger;
041:
042: import javax.jbi.component.ComponentContext;
043: import javax.jbi.messaging.DeliveryChannel;
044:
045: /**
046: * Context object to store sequencing engine specific informaiton.
047: *
048: * @author Sun Microsystems Inc.
049: */
050: public final class JMSBindingContext {
051: /**
052: * This object.
053: */
054: private static JMSBindingContext sJMSContext;
055:
056: /**
057: * Engine context.
058: */
059: private ComponentContext mContext;
060:
061: /**
062: * Configuration object.
063: */
064: private Config mConfig;
065:
066: /**
067: * Endpoint manager.
068: */
069: private EndpointManager mEndpointManager;
070:
071: /**
072: * Endpoint resistry.
073: */
074: private EndpointRegistry mRegistry;
075:
076: /**
077: * Logger object.
078: */
079: private Logger mLogger;
080: /**
081: * MQ manager.
082: */
083: private MQManager mMQManager;
084: /**
085: * Message registry.
086: */
087: private MessageRegistry mMessageRegistry;
088: /**
089: * String translator.
090: */
091: private StringTranslator mStringTranslator;
092: /**
093: * JMS work manager for amnaging threads.
094: */
095: private WorkManager mJMSWorkManager;
096:
097: /**
098: * Creates a new JMS Binding context object.
099: */
100: private JMSBindingContext() {
101: }
102:
103: /**
104: * Gets the binding channel.
105: *
106: * @return bidning channel
107: */
108: public DeliveryChannel getChannel() {
109: DeliveryChannel chnl = null;
110:
111: if (mContext != null) {
112: try {
113: chnl = mContext.getDeliveryChannel();
114: } catch (Exception e) {
115: e.printStackTrace();
116: }
117: }
118:
119: return chnl;
120: }
121:
122: /**
123: * Setter for property mConfig.
124: *
125: * @param mConfig New value of property mConfig.
126: */
127: public void setConfig(Config mConfig) {
128: this .mConfig = mConfig;
129: }
130:
131: /**
132: * Getter for property mConfig.
133: *
134: * @return Value of property mConfig.
135: */
136: public Config getConfig() {
137: return mConfig;
138: }
139:
140: /**
141: * Sets the binding context.
142: *
143: * @param ctx binding context.
144: */
145: public void setContext(ComponentContext ctx) {
146: mContext = ctx;
147: }
148:
149: /**
150: * Returns the context.
151: *
152: * @return binding context implementation.
153: */
154: public ComponentContext getContext() {
155: return mContext;
156: }
157:
158: /**
159: * Used to grab a reference of this object.
160: *
161: * @return an initialized SequencingEngineContext reference
162: */
163: public static synchronized JMSBindingContext getInstance() {
164: if (sJMSContext == null) {
165: synchronized (JMSBindingContext.class) {
166: if (sJMSContext == null) {
167: sJMSContext = new JMSBindingContext();
168: }
169: }
170: }
171:
172: return sJMSContext;
173: }
174:
175: /**
176: * Setter for property mEndpointManager.
177: *
178: * @param mEndpointManager New value of property mEndpointManager.
179: */
180: public void setEndpointManager(EndpointManager mEndpointManager) {
181: this .mEndpointManager = mEndpointManager;
182: }
183:
184: /**
185: * Getter for property mEndpointManager.
186: *
187: * @return Value of property mEndpointManager.
188: */
189: public EndpointManager getEndpointManager() {
190: return mEndpointManager;
191: }
192:
193: /**
194: * Setter for property mJMSWorkManager.
195: *
196: * @param mJMSWorkManager New value of property mJMSWorkManager.
197: */
198: public void setJMSWorkManager(WorkManager mJMSWorkManager) {
199: this .mJMSWorkManager = mJMSWorkManager;
200: }
201:
202: /**
203: * Getter for property mJMSWorkManager.
204: *
205: * @return Value of property mJMSWorkManager.
206: */
207: public WorkManager getJMSWorkManager() {
208: return mJMSWorkManager;
209: }
210:
211: /**
212: * Sets the logger.
213: *
214: * @param logger Logger.
215: */
216: public void setLogger(Logger logger) {
217: mLogger = logger;
218: }
219:
220: /**
221: * Returns the logger.
222: *
223: * @return logger object.
224: */
225: public Logger getLogger() {
226: if (mLogger == null) {
227: mLogger = Logger.getLogger("com.sun.jbi.binding.jms");
228: }
229:
230: return mLogger;
231: }
232:
233: /**
234: * Returns the logger.
235: *
236: * @param pkg package name.
237: *
238: * @return logger object.
239: */
240: public Logger getLogger(String pkg) {
241: Logger logger = Logger.getLogger(JMSConstants.JMS_PACKAGE_NAME);
242:
243: try {
244: if (mConfig != null) {
245: Level loglevel = mConfig.getLogLevel();
246: logger.setLevel(loglevel);
247: }
248: } catch (Exception e) {
249: e.printStackTrace();
250: }
251:
252: return logger;
253: }
254:
255: /**
256: * Setter for property mMQManager.
257: *
258: * @param mMQManager New value of property mMQManager.
259: */
260: public void setMQManager(MQManager mMQManager) {
261: this .mMQManager = mMQManager;
262: }
263:
264: /**
265: * Getter for property mMQManager.
266: *
267: * @return Value of property mMQManager.
268: */
269: public MQManager getMQManager() {
270: return mMQManager;
271: }
272:
273: /**
274: * Setter for property mMessageRegistry.
275: *
276: * @param mMessageRegistry New value of property mMessageRegistry.
277: */
278: public void setMessageRegistry(MessageRegistry mMessageRegistry) {
279: this .mMessageRegistry = mMessageRegistry;
280: }
281:
282: /**
283: * Getter for property mMessageRegistry.
284: *
285: * @return Value of property mMessageRegistry.
286: */
287: public MessageRegistry getMessageRegistry() {
288: return mMessageRegistry;
289: }
290:
291: /**
292: * Setter for property mRegistry.
293: *
294: * @param mRegistry New value of property mRegistry.
295: */
296: public void setRegistry(EndpointRegistry mRegistry) {
297: this .mRegistry = mRegistry;
298: }
299:
300: /**
301: * Getter for property mRegistry.
302: *
303: * @return Value of property mRegistry.
304: */
305: public EndpointRegistry getRegistry() {
306: return mRegistry;
307: }
308:
309: /**
310: * String translator implementation.
311: *
312: *
313: * @return string translator implementation.
314: */
315: public StringTranslator getStringTranslator() {
316:
317: if (mStringTranslator != null) {
318: return mStringTranslator;
319: }
320:
321: try {
322: com.sun.jbi.component.ComponentContext jbiContext = (com.sun.jbi.component.ComponentContext) (mContext);
323: mStringTranslator = jbiContext.getStringTranslatorFor(this );
324: } catch (Throwable throwable) {
325: throwable.printStackTrace();
326: }
327:
328: return mStringTranslator;
329: }
330: }
|