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: * @(#)MQDestination.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.mq;
030:
031: import com.sun.jbi.binding.jms.util.UtilBase;
032:
033: import javax.jms.Destination;
034: import javax.jms.Queue;
035: import javax.jms.Topic;
036:
037: /**
038: * MQ destination wrapper.
039: *
040: * @author Sun Microsystems Inc.
041: */
042: public final class MQDestination extends UtilBase {
043: /**
044: * JMS destination.
045: */
046: private javax.jms.Destination mDestination;
047:
048: /**
049: * Lookup name.
050: */
051: private String mLookupName;
052:
053: /**
054: * Style.
055: */
056: private int mStyle;
057:
058: /**
059: * Destination name
060: */
061: private String mDestinationName;
062:
063: /**
064: * Creates a new MQDestination object.
065: *
066: * @param dest JMS destination.
067: */
068: public MQDestination(javax.jms.Destination dest) {
069: mDestination = dest;
070: setStyle();
071: setDestinationName();
072: }
073:
074: /**
075: * Creates a new MQDestination object.
076: *
077: * @param dest jms destination.
078: * @param style q or topic.
079: * @param lookupname destination lookup name.
080: */
081: public MQDestination(javax.jms.Destination dest, int style,
082: String lookupname) {
083: mDestination = dest;
084: mStyle = style;
085: mLookupName = lookupname;
086: }
087:
088: /**
089: * Gets the destination.
090: *
091: * @return JMS destination.
092: */
093: public javax.jms.Destination getDestination() {
094: return mDestination;
095: }
096:
097: /**
098: * Gets the lookup name.
099: *
100: * @return lookup name.
101: */
102: public String getDestinationName() {
103: if (mDestinationName != null) {
104: return mDestinationName;
105: } else {
106: return mLookupName;
107: }
108: }
109:
110: /**
111: * Gets the lookup name.
112: *
113: * @return lookup name.
114: */
115: public String getLookupName() {
116: if (mLookupName != null) {
117: return mLookupName;
118: } else {
119: return mDestinationName;
120: }
121: }
122:
123: /**
124: * Gets the style.
125: *
126: * @return topic or queue.
127: */
128: public int getStyle() {
129: return mStyle;
130: }
131:
132: /**
133: * Sets the lookupname.
134: */
135: private void setDestinationName() {
136: try {
137: if (mDestination instanceof javax.jms.Queue) {
138: mDestinationName = ((javax.jms.Queue) mDestination)
139: .getQueueName();
140: } else if (mDestination instanceof javax.jms.Topic) {
141: mDestinationName = ((javax.jms.Topic) mDestination)
142: .getTopicName();
143: }
144: } catch (Throwable e) {
145: setError("Destination is not a Queue or topic ");
146: setError(e.getMessage());
147: }
148: }
149:
150: /**
151: * Sets the style.
152: */
153: private void setStyle() {
154: if (mDestination instanceof javax.jms.Queue) {
155: mStyle = 0;
156: } else if (mDestination instanceof javax.jms.Topic) {
157: mStyle = 1;
158: }
159: }
160: }
|