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 53 import org.exolab.jms.net.util.SerializationHelper; 54 55 56 64 public class Response implements Serializable { 65 66 69 private Object _object; 70 71 74 private Throwable _exception; 75 76 79 private transient Method _method; 80 81 87 public Response(Object object, Method method) { 88 _object = object; 89 _method = method; 90 } 91 92 97 public Response(Throwable exception) { 98 _exception = exception; 99 } 100 101 106 public Object getObject() { 107 return _object; 108 } 109 110 115 public Throwable getException() { 116 return _exception; 117 } 118 119 124 public boolean isReturn() { 125 return (_exception == null); 126 } 127 128 133 public boolean isException() { 134 return !isReturn(); 135 } 136 137 143 public void write(ObjectOutput out) throws IOException { 144 boolean normal = isReturn(); 145 out.writeBoolean(normal); 146 if (normal) { 147 Class type = _method.getReturnType(); 148 if (type != void.class) { 149 SerializationHelper.write(type, _object, out); 150 } 151 } else { 152 out.writeObject(_exception); 153 } 154 } 155 156 166 public static Response read(ObjectInput in, Method method) 167 throws ClassNotFoundException , IOException { 168 Response response = null; 169 boolean returnResponse = in.readBoolean(); 170 if (returnResponse) { 171 Class type = method.getReturnType(); 172 Object object = null; 173 if (type != void.class) { 174 object = SerializationHelper.read(type, in); 175 } 176 response = new Response(object, method); 177 } else { 178 Object object = in.readObject(); 179 response = new Response((Throwable ) object); 180 } 181 return response; 182 } 183 184 } 185 | Popular Tags |