1 45 package org.exolab.jms.net.connector; 46 47 import java.io.IOException ; 48 import java.io.ObjectInput ; 49 import java.io.ObjectOutput ; 50 import java.io.Serializable ; 51 import java.lang.reflect.Method ; 52 import java.rmi.server.ObjID ; 53 54 import org.exolab.jms.net.util.SerializationHelper; 55 56 57 66 public class Request implements Serializable { 67 68 71 private transient String _uri; 72 73 76 private ObjID _objID; 77 78 81 private transient Method _method; 82 83 86 private transient ObjectInput _argStream; 87 88 93 private Object [] _args; 94 95 98 private long _methodID; 99 100 101 110 public Request(ObjID objID, Method method, Object [] args, long methodID) { 111 _objID = objID; 112 _method = method; 113 _args = args; 114 _methodID = methodID; 115 } 116 117 127 private Request(String uri, ObjID objID, long methodID, 128 ObjectInput argStream) { 129 _uri = uri; 130 _objID = objID; 131 _argStream = argStream; 132 _methodID = methodID; 133 } 134 135 140 public String getURI() { 141 return _uri; 142 } 143 144 149 public ObjID getObjID() { 150 return _objID; 151 } 152 153 158 public Method getMethod() { 159 return _method; 160 } 161 162 169 public Object [] getArgs() { 170 return _args; 171 } 172 173 183 public Object [] readArgs(Method method) 184 throws ClassNotFoundException , IOException { 185 Class [] types = method.getParameterTypes(); 186 _args = new Object [types.length]; 187 _method = method; 188 for (int i = 0; i < types.length; ++i) { 189 _args[i] = SerializationHelper.read(types[i], _argStream); 190 } 191 if (_argStream != null) { 192 _argStream.close(); 193 _argStream = null; 194 } 195 return _args; 196 } 197 198 203 public long getMethodID() { 204 return _methodID; 205 } 206 207 213 public void write(ObjectOutput out) throws IOException { 214 _objID.write(out); 215 out.writeLong(_methodID); 216 217 Class [] types = _method.getParameterTypes(); 219 for (int i = 0; i < types.length; ++i) { 220 SerializationHelper.write(types[i], _args[i], out); 221 } 222 } 223 224 235 public static Request read(ObjectInput in) throws IOException { 236 ObjID objID = ObjID.read(in); 237 long methodID = in.readLong(); 238 return new Request(null, objID, methodID, in); 239 } 240 241 } 242 | Popular Tags |