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: * @(#)JMSEvent.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.proxy.jms;
030:
031: import com.sun.jbi.binding.proxy.LocalStringKeys;
032:
033: import com.sun.jbi.binding.proxy.util.Translator;
034:
035: import com.sun.jbi.binding.proxy.connection.Event;
036:
037: import java.io.ObjectOutputStream;
038: import java.io.ObjectInputStream;
039: import java.io.ByteArrayOutputStream;
040: import java.io.ByteArrayInputStream;
041:
042: import javax.jms.StreamMessage;
043: import javax.jms.Queue;
044: import javax.jms.QueueSender;
045: import javax.jms.QueueSession;
046:
047: /**
048: * Connection as a JMS Client.
049: * @author Sun Microsystems, Inc
050: */
051: public class JMSEvent implements Event {
052: StreamMessage mMessage;
053: String mEventName;
054: String mSender;
055: static final String EVENTNAME = "EventName";
056:
057: JMSEvent(StreamMessage m)
058: throws com.sun.jbi.binding.proxy.connection.EventException {
059: mMessage = m;
060: try {
061: mSender = m.getJMSType();
062: mEventName = m.getStringProperty(EVENTNAME);
063: } catch (javax.jms.JMSException jEx) {
064: throw new com.sun.jbi.binding.proxy.connection.EventException(
065: jEx);
066: }
067: }
068:
069: JMSEvent(StreamMessage m, String eventName)
070: throws com.sun.jbi.binding.proxy.connection.EventException {
071: mMessage = m;
072: mEventName = eventName;
073: try {
074: mSender = m.getJMSType();
075: m.setStringProperty(EVENTNAME, eventName);
076: } catch (javax.jms.JMSException jEx) {
077: throw new com.sun.jbi.binding.proxy.connection.EventException(
078: jEx);
079: }
080: }
081:
082: public String getEventName() {
083: return (mEventName);
084: }
085:
086: public String getString()
087: throws com.sun.jbi.binding.proxy.connection.EventException {
088: try {
089: return (mMessage.readString());
090: } catch (javax.jms.JMSException jEx) {
091: throw new com.sun.jbi.binding.proxy.connection.EventException(
092: jEx);
093: }
094: }
095:
096: public long getLong()
097: throws com.sun.jbi.binding.proxy.connection.EventException {
098: try {
099: return (mMessage.readLong());
100: } catch (javax.jms.JMSException jEx) {
101: throw new com.sun.jbi.binding.proxy.connection.EventException(
102: jEx);
103: }
104: }
105:
106: public void putString(String value)
107: throws com.sun.jbi.binding.proxy.connection.EventException {
108: try {
109: mMessage.writeString(value);
110: } catch (javax.jms.JMSException jEx) {
111: throw new com.sun.jbi.binding.proxy.connection.EventException(
112: jEx);
113: }
114: }
115:
116: public void putLong(long value)
117: throws com.sun.jbi.binding.proxy.connection.EventException {
118: try {
119: mMessage.writeLong(value);
120: } catch (javax.jms.JMSException jEx) {
121: throw new com.sun.jbi.binding.proxy.connection.EventException(
122: jEx);
123:
124: }
125: }
126:
127: public Object getObject()
128: throws com.sun.jbi.binding.proxy.connection.EventException {
129: try {
130: ByteArrayInputStream bais;
131: ObjectInputStream ois;
132: int size;
133: byte[] bytes;
134: Object object;
135:
136: size = mMessage.readInt();
137: bytes = new byte[size];
138: mMessage.readBytes(bytes);
139: ois = new ObjectInputStream(
140: bais = new ByteArrayInputStream(bytes));
141: object = ois.readObject();
142: ois.close();
143: return (object);
144: } catch (java.lang.ClassNotFoundException cnfEx) {
145: throw new com.sun.jbi.binding.proxy.connection.EventException(
146: cnfEx);
147: } catch (java.io.IOException ioEx) {
148: throw new com.sun.jbi.binding.proxy.connection.EventException(
149: ioEx);
150: } catch (javax.jms.JMSException jEx) {
151: throw new com.sun.jbi.binding.proxy.connection.EventException(
152: jEx);
153: }
154: }
155:
156: public void putObject(Object value)
157: throws com.sun.jbi.binding.proxy.connection.EventException {
158: try {
159: ByteArrayOutputStream baos;
160: ObjectOutputStream oos;
161: byte[] bytes;
162:
163: oos = new ObjectOutputStream(
164: baos = new ByteArrayOutputStream());
165: oos.writeObject(value);
166: oos.close();
167: bytes = baos.toByteArray();
168: mMessage.writeInt(bytes.length);
169: mMessage.writeBytes(bytes);
170: } catch (java.io.IOException ioEx) {
171: throw new com.sun.jbi.binding.proxy.connection.EventException(
172: ioEx);
173: } catch (javax.jms.JMSException jEx) {
174: throw new com.sun.jbi.binding.proxy.connection.EventException(
175: jEx);
176: }
177: }
178:
179: StreamMessage getMessage() {
180: return (mMessage);
181: }
182:
183: public String getSender() {
184: return (mSender);
185: }
186: }
|