KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > joram > shared > client > MomExceptionReply


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2001 - 2006 ScalAgent Distributed Technologies
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA.
19  *
20  * Initial developer(s): ScalAgent Distributed Technologies
21  * Contributor(s):
22  */

23 package org.objectweb.joram.shared.client;
24
25 import java.io.Externalizable JavaDoc;
26 import java.io.InputStream JavaDoc;
27 import java.io.OutputStream JavaDoc;
28 import java.io.IOException JavaDoc;
29
30 import org.objectweb.joram.shared.stream.Streamable;
31 import org.objectweb.joram.shared.stream.StreamUtil;
32 import org.objectweb.joram.shared.excepts.MomException;
33
34 /**
35  * A <code>MomExceptionReply</code> instance is used by a JMS client proxy
36  * to send a <code>MomException</code> back to a JMS client.
37  */

38 public final class MomExceptionReply extends AbstractJmsReply {
39   public static final int MomException = 1;
40   public static final int AccessException = 2;
41   public static final int DestinationException = 3;
42   public static final int MessageException = 4;
43   public static final int MessageROException = 5;
44   public static final int MessageValueException = 6;
45   public static final int RequestException = 7;
46   public static final int SelectorException = 8;
47   public static final int StateException = 9;
48
49   // Only used MOM side.
50
public static final int HBCloseConnection = 99999;
51
52   /** The wrapped exception type. */
53   private int type;
54
55   /** Returns the exception wrapped by this reply. */
56   public int getType() {
57     return type;
58   }
59
60   /** The wrapped exception message. */
61   private String JavaDoc message;
62
63   public String JavaDoc getMessage() {
64     return message;
65   }
66
67   protected int getClassId() {
68     return MOM_EXCEPTION_REPLY;
69   }
70
71   /**
72    * Constructs a <code>MomExceptionReply</code> instance.
73    *
74    * @param correlationId Identifier of the failed request.
75    * @param momExcept The resulting exception.
76    */

77   public MomExceptionReply(int correlationId, MomException exc) {
78     super(correlationId);
79     this.type = exc.getType();
80     this.message = exc.getMessage();
81   }
82
83   /**
84    * Constructs a <code>MomExceptionReply</code> instance.
85    *
86    * @param momExcept The exception to wrap.
87    */

88   public MomExceptionReply(MomException exc) {
89     this.type = exc.getType();
90     this.message = exc.getMessage();
91   }
92
93   /**
94    * Public no-arg constructor needed by Externalizable.
95    */

96   public MomExceptionReply() {}
97
98   public void toString(StringBuffer JavaDoc strbuf) {
99     super.toString(strbuf);
100     strbuf.append(",momExceptType=").append(type);
101     strbuf.append(",momExceptMessage=").append(message);
102     strbuf.append(')');
103   }
104
105   /* ***** ***** ***** ***** *****
106    * Streamable interface
107    * ***** ***** ***** ***** ***** */

108
109   /**
110    * The object implements the writeTo method to write its contents to
111    * the output stream.
112    *
113    * @param os the stream to write the object to
114    */

115   public void writeTo(OutputStream JavaDoc os) throws IOException JavaDoc {
116     super.writeTo(os);
117     StreamUtil.writeTo(type, os);
118     StreamUtil.writeTo(message, os);
119   }
120
121   /**
122    * The object implements the readFrom method to restore its contents from
123    * the input stream.
124    *
125    * @param is the stream to read data from in order to restore the object
126    */

127   public void readFrom(InputStream JavaDoc is) throws IOException JavaDoc {
128     super.readFrom(is);
129     type = StreamUtil.readIntFrom(is);
130     message = StreamUtil.readStringFrom(is);
131   }
132 }
133
Popular Tags