1 23 package org.objectweb.joram.shared.client; 24 25 import java.io.Externalizable ; 26 import java.io.InputStream ; 27 import java.io.OutputStream ; 28 import java.io.ObjectInput ; 29 import java.io.ObjectOutput ; 30 import java.io.ByteArrayInputStream ; 31 import java.io.ByteArrayOutputStream ; 32 import java.io.IOException ; 33 34 import java.util.Hashtable ; 35 36 import org.objectweb.joram.shared.stream.Streamable; 37 import org.objectweb.joram.shared.stream.StreamUtil; 38 39 import fr.dyade.aaa.util.Debug; 40 import org.objectweb.util.monolog.api.BasicLevel; 41 import org.objectweb.util.monolog.api.Logger; 42 43 47 public abstract class AbstractJmsMessage implements Externalizable , Streamable { 48 public static Logger logger = Debug.getLogger(AbstractJmsMessage.class.getName()); 49 50 protected final static int NULL_CLASS_ID = -1; 51 52 protected final static int CNX_CONNECT_REQUEST = 0; 53 protected final static int CNX_CONNECT_REPLY = 1; 54 protected final static int CNX_START_REQUEST = 2; 55 protected final static int CNX_STOP_REQUEST = 3; 56 protected final static int CNX_CLOSE_REQUEST = 4; 57 protected final static int CNX_CLOSE_REPLY = 5; 58 protected final static int PRODUCER_MESSAGES = 6; 59 protected final static int CONSUMER_RECEIVE_REQUEST = 7; protected final static int CONSUMER_MESSAGES = 8; protected final static int CONSUMER_SUB_REQUEST = 9; 62 protected final static int CONSUMER_UNSUB_REQUEST = 10; 63 protected final static int CONSUMER_ACK_REQUEST = 11; protected final static int CONSUMER_DENY_REQUEST = 12; protected final static int SESS_ACK_REQUEST = 13; 66 protected final static int SESS_DENY_REQUEST = 14; 67 protected final static int MOM_EXCEPTION_REPLY = 15; 68 protected final static int SERVER_REPLY = 16; 70 protected final static int ACTIVATE_CONSUMER_REQUEST = 17; 71 protected final static int COMMIT_REQUEST = 18; 72 protected final static int CONSUMER_CLOSE_SUB_REQUEST = 19; 73 protected final static int CONSUMER_SET_LIST_REQUEST = 20; 74 protected final static int CONSUMER_UNSET_LIST_REQUEST = 21; 75 protected final static int GET_ADMIN_TOPIC_REPLY = 22; 76 protected final static int GET_ADMIN_TOPIC_REQUEST = 23; 77 protected final static int JMS_REQUEST_GROUP = 24; 78 protected final static int PING_REQUEST = 25; 79 protected final static int QBROWSE_REPLY = 26; 80 protected final static int QBROWSE_REQUEST = 27; 81 protected final static int SESS_CREATE_TDREPLY = 28; 82 protected final static int SESS_CREATE_TQREQUEST = 29; 83 protected final static int SESS_CREATE_TTREQUEST = 30; 84 protected final static int TEMP_DEST_DELETE_REQUEST = 31; 85 protected final static int XA_CNX_COMMIT = 32; 86 protected final static int XA_CNX_PREPARE = 33; 87 protected final static int XA_CNX_RECOVER_REPLY = 34; 88 protected final static int XA_CNX_RECOVER_REQUEST = 35; 89 protected final static int XA_CNX_ROLLBACK = 36; 90 91 protected int classid; 92 93 protected static final String [] classnames = { 94 "org.objectweb.joram.shared.client.CnxConnectRequest", 95 "org.objectweb.joram.shared.client.CnxConnectReply", 96 "org.objectweb.joram.shared.client.CnxStartRequest", 97 "org.objectweb.joram.shared.client.CnxStopRequest", 98 "org.objectweb.joram.shared.client.CnxCloseRequest", 99 "org.objectweb.joram.shared.client.CnxCloseReply", 100 "org.objectweb.joram.shared.client.ProducerMessages", 101 "org.objectweb.joram.shared.client.ConsumerReceiveRequest", 102 "org.objectweb.joram.shared.client.ConsumerMessages", 103 "org.objectweb.joram.shared.client.ConsumerSubRequest", 104 "org.objectweb.joram.shared.client.ConsumerUnsubRequest", 105 "org.objectweb.joram.shared.client.ConsumerAckRequest", 106 "org.objectweb.joram.shared.client.ConsumerDenyRequest", 107 "org.objectweb.joram.shared.client.SessAckRequest", 108 "org.objectweb.joram.shared.client.SessDenyRequest", 109 "org.objectweb.joram.shared.client.MomExceptionReply", 110 "org.objectweb.joram.shared.client.ServerReply", 111 112 "org.objectweb.joram.shared.client.ActivateConsumerRequest", 113 "org.objectweb.joram.shared.client.CommitRequest", 114 "org.objectweb.joram.shared.client.ConsumerCloseSubRequest", 115 "org.objectweb.joram.shared.client.ConsumerSetListRequest", 116 "org.objectweb.joram.shared.client.ConsumerUnsetListRequest", 117 "org.objectweb.joram.shared.client.GetAdminTopicReply", 118 "org.objectweb.joram.shared.client.GetAdminTopicRequest", 119 "org.objectweb.joram.shared.client.JmsRequestGroup", 120 "org.objectweb.joram.shared.client.PingRequest", 121 "org.objectweb.joram.shared.client.QBrowseReply", 122 "org.objectweb.joram.shared.client.QBrowseRequest", 123 "org.objectweb.joram.shared.client.SessCreateTDReply", 124 "org.objectweb.joram.shared.client.SessCreateTQRequest", 125 "org.objectweb.joram.shared.client.SessCreateTTRequest", 126 "org.objectweb.joram.shared.client.TempDestDeleteRequest", 127 "org.objectweb.joram.shared.client.XACnxCommit", 128 "org.objectweb.joram.shared.client.XACnxPrepare", 129 "org.objectweb.joram.shared.client.XACnxRecoverReply", 130 "org.objectweb.joram.shared.client.XACnxRecoverRequest", 131 "org.objectweb.joram.shared.client.XACnxRollback" 132 }; 133 134 protected abstract int getClassId(); 135 136 139 public AbstractJmsMessage() { 140 classid = getClassId(); 141 } 142 143 146 147 151 public Hashtable soapCode() throws IOException { 152 Hashtable h = new Hashtable (); 153 h.put("classname", getClass().getName()); 154 155 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 156 writeTo(baos); 157 baos.flush(); 158 h.put("bytecontent", baos.toByteArray()); 159 baos.close(); 160 161 return h; 162 } 163 164 171 public static Object soapDecode(Hashtable h) throws Exception { 172 AbstractJmsMessage msg = null; 173 ByteArrayInputStream bais = null; 174 175 try { 176 String classname = (String ) h.get("classname"); 177 msg = (AbstractJmsMessage) Class.forName(classname).newInstance(); 178 byte[] content = (byte[]) h.get("bytecontent"); 179 bais = new ByteArrayInputStream (content); 180 msg.readFrom(bais); 181 } finally { 182 bais.close(); 183 } 184 185 return msg; 186 } 187 188 191 192 public final void writeExternal(ObjectOutput out) throws IOException { 193 writeTo((OutputStream ) out); 194 } 195 196 public final void readExternal(ObjectInput in) throws IOException , ClassNotFoundException { 197 readFrom((InputStream ) in); 198 } 199 200 203 204 static public void write(AbstractJmsMessage msg, 205 OutputStream os) throws IOException { 206 if (logger.isLoggable(BasicLevel.DEBUG)) 207 logger.log(BasicLevel.DEBUG, "AbstractJmsMessage.write: " + msg); 208 209 if (msg == null) { 210 StreamUtil.writeTo(NULL_CLASS_ID, os); 211 } else { 212 StreamUtil.writeTo(msg.getClassId(), os); 213 msg.writeTo(os); 214 } 215 } 216 217 static public AbstractJmsMessage read(InputStream is) throws IOException , ClassNotFoundException , InstantiationException , IllegalAccessException { 218 int classid = -1; 219 AbstractJmsMessage msg = null; 220 221 classid = StreamUtil.readIntFrom(is); 222 if (classid != NULL_CLASS_ID) { 223 msg = (AbstractJmsMessage) Class.forName(classnames[classid]).newInstance(); 224 msg.readFrom(is); 225 } 226 227 if (logger.isLoggable(BasicLevel.DEBUG)) 228 logger.log(BasicLevel.DEBUG, "AbstractJmsMessage.read: " + msg); 229 230 return msg; 231 } 232 } 233 | Popular Tags |