1 22 package org.jboss.invocation; 23 24 import java.io.Serializable ; 25 import java.io.ObjectOutputStream ; 26 import java.io.ByteArrayOutputStream ; 27 import java.io.ObjectInputStream ; 28 import java.io.ByteArrayInputStream ; 29 import java.lang.reflect.InvocationTargetException ; 30 import java.lang.reflect.Method ; 31 import java.security.Principal ; 32 import java.util.Map ; 33 import java.util.HashMap ; 34 35 import javax.transaction.Transaction ; 36 37 52 public class Invocation 53 { 54 55 public static final String [] INVOKE_SIGNATURE = { "org.jboss.invocation.Invocation" }; 56 57 60 63 public Map transient_payload; 64 65 69 public Map as_is_payload; 70 71 72 public Map payload; 73 74 public InvocationContext invocationContext; 75 public Object [] args; 76 public Object objectName; 77 public Method method; 78 public InvocationType invocationType; 79 80 82 89 92 public Invocation() 93 { 94 } 95 96 public Invocation( Object id, Method m, Object [] args, Transaction tx, 97 Principal identity, Object credential ) 98 { 99 setId(id); 100 setMethod(m); 101 setArguments(args); 102 setTransaction(tx); 103 setPrincipal(identity); 104 setCredential(credential); 105 } 106 107 115 public void setValue(Object key, Object value) 116 { 117 setValue(key, value, PayloadKey.PAYLOAD); 118 } 119 120 128 public void setValue(Object key, Object value, PayloadKey type) 129 { 130 if(type == PayloadKey.TRANSIENT) 131 { 132 getTransientPayload().put(key,value); 133 } 134 else if(type == PayloadKey.AS_IS) 135 { 136 getAsIsPayload().put(key,value); 137 } 138 else if(type == PayloadKey.PAYLOAD) 139 { 140 getPayload().put(key,value); 141 } 142 else 143 { 144 throw new IllegalArgumentException ("Unknown PayloadKey: " + type); 145 } 146 } 147 148 151 public Object getValue(Object key) 152 { 153 Object rtn = getPayloadValue(key); 155 if (rtn != null) return rtn; 156 157 rtn = getAsIsValue(key); 158 if (rtn != null) return rtn; 159 160 rtn = getTransientValue(key); 161 return rtn; 162 } 163 164 public Object getPayloadValue(Object key) 165 { 166 if (payload == null) return null; 167 return payload.get(key); 168 } 169 170 public Object getTransientValue(Object key) 171 { 172 if (transient_payload == null) return null; 173 return transient_payload.get(key); 174 } 175 176 public Object getAsIsValue(Object key) 177 { 178 if (as_is_payload == null) return null; 179 return as_is_payload.get(key); 180 } 181 182 183 184 193 196 public void setTransaction(Transaction tx) 197 { 198 if( tx instanceof Serializable ) 199 getAsIsPayload().put(InvocationKey.TRANSACTION, tx); 200 else 201 getTransientPayload().put(InvocationKey.TRANSACTION, tx); 202 } 203 204 207 public Transaction getTransaction() 208 { 209 Transaction tx = (Transaction ) getAsIsPayload().get(InvocationKey.TRANSACTION); 210 if( tx == null ) 211 tx = (Transaction ) getTransientPayload().get(InvocationKey.TRANSACTION); 212 return tx; 213 } 214 215 218 public void setPrincipal(Principal principal) 219 { 220 getAsIsPayload().put(InvocationKey.PRINCIPAL, principal); 221 } 222 223 public Principal getPrincipal() 224 { 225 return (Principal ) getAsIsPayload().get(InvocationKey.PRINCIPAL); 226 } 227 228 231 public void setCredential(Object credential) 232 { 233 getPayload().put(InvocationKey.CREDENTIAL, credential); 234 } 235 236 public Object getCredential() 237 { 238 return getPayloadValue(InvocationKey.CREDENTIAL); 239 } 240 241 244 public void setObjectName(Object objectName) 245 { 246 this.objectName = objectName; 247 } 248 249 public Object getObjectName() 250 { 251 return objectName; 252 } 253 254 257 public void setType(InvocationType type) 258 { 259 invocationType = type; 260 } 261 262 public InvocationType getType() 263 { 264 if (invocationType == null) return InvocationType.LOCAL; 265 return invocationType; 266 } 267 268 271 public void setId(Object id) 272 { 273 getPayload().put(InvocationKey.CACHE_ID, id); 274 } 275 276 public Object getId() 277 { 278 return getPayloadValue(InvocationKey.CACHE_ID); 279 } 280 281 284 public void setMethod(Method method) 285 { 286 this.method = method; 287 } 288 289 292 public Method getMethod() 293 { 294 return method; 295 } 296 297 300 public void setArguments(Object [] arguments) 301 { 302 this.args = arguments; 303 } 304 305 public Object [] getArguments() 306 { 307 return this.args; 308 } 309 310 313 public InvocationContext getInvocationContext() 314 { 315 return invocationContext; 316 } 317 318 public void setInvocationContext(InvocationContext ctx) 319 { 320 this.invocationContext = ctx; 321 } 322 323 public void setEnterpriseContext(Object ctx) 324 { 325 getTransientPayload().put(InvocationKey.ENTERPRISE_CONTEXT, ctx); 326 } 327 328 public Object getEnterpriseContext() 329 { 330 return getTransientPayload().get(InvocationKey.ENTERPRISE_CONTEXT); 331 } 332 333 public Map getTransientPayload() 334 { 335 if (transient_payload == null) transient_payload = new HashMap (); 336 return transient_payload; 337 } 338 339 public Map getAsIsPayload() 340 { 341 if (as_is_payload == null) as_is_payload = new HashMap (); 342 return as_is_payload; 343 } 344 345 public Map getPayload() 346 { 347 if (payload == null) payload = new HashMap (); 348 return payload; 349 } 350 351 356 public Object performCall(Object instance, Method m, Object [] arguments) 357 throws IllegalArgumentException , IllegalAccessException , InvocationTargetException , Exception 358 { 359 return m.invoke(instance,arguments); 360 } 361 362 367 public boolean isLocal() 368 { 369 InvocationType type = getType(); 370 return (type == InvocationType.LOCAL || type == InvocationType.LOCALHOME); 371 } 372 } 373 | Popular Tags |