1 22 package org.jboss.aop.joinpoint; 23 24 import java.io.IOException ; 25 import java.util.HashMap ; 26 import java.util.Iterator ; 27 import java.util.Map ; 28 29 39 public class InvocationResponse 40 implements java.io.Externalizable 41 { 42 44 private static final long serialVersionUID = 2974596986988236395L; 45 46 public Map getContextInfo() 47 { 48 return contextInfo; 49 } 50 51 public void setContextInfo(Map contextInfo) 52 { 53 this.contextInfo = contextInfo; 54 } 55 56 protected Map contextInfo = null; 58 protected Object response = null; 59 60 public InvocationResponse() 62 { 63 } 64 public InvocationResponse(Object obj) 65 { 66 if (obj instanceof InvocationResponse) 67 { 68 new Exception ().printStackTrace(); 69 throw new RuntimeException ("Stuffing an InvocationResponse within an InvocationResponse!!!!"); 70 } 71 this.response = obj; 72 } 73 74 public Object getResponse() { return response; } 75 public void setResponse(Object obj) 76 { 77 if (obj instanceof InvocationResponse) 78 { 79 new Exception ().printStackTrace(); 80 throw new RuntimeException ("Stuffing an InvocationResponse within an InvocationResponse!!!!"); 81 } 82 response = obj; 83 } 84 85 public void addAttachment(Object key, Object val) 86 { 87 if (contextInfo == null) contextInfo = new HashMap (1); 88 contextInfo.put(key, val); 89 } 90 91 public Object getAttachment(Object key) 92 { 93 if (contextInfo == null) return null; 94 return contextInfo.get(key); 95 } 96 97 public void writeExternal(java.io.ObjectOutput out) 99 throws IOException 100 { 101 out.writeObject(response); 102 if (contextInfo == null) 103 { 104 out.writeInt(0); 105 } 106 else 107 { 108 out.writeInt(contextInfo.size()); 109 Iterator keys = contextInfo.keySet().iterator(); 110 while (keys.hasNext()) 111 { 112 Object currentKey = keys.next(); 113 out.writeObject(currentKey); 114 out.writeObject(contextInfo.get(currentKey)); 115 } 116 } 117 } 118 119 public void readExternal(java.io.ObjectInput in) 120 throws IOException , ClassNotFoundException 121 { 122 response = in.readObject(); 123 124 int size = in.readInt(); 126 if (size == 0) 127 { 128 contextInfo = null; 129 } 130 else 131 { 132 contextInfo = new HashMap (size); 133 for (int i = 0; i < size; i++) 134 { 135 Object key = in.readObject(); 136 Object value = in.readObject(); 137 contextInfo.put(key, value); 138 } 139 } 140 } 141 } 142 | Popular Tags |