1 16 17 package org.springframework.remoting.support; 18 19 import java.io.Serializable ; 20 import java.lang.reflect.InvocationTargetException ; 21 import java.lang.reflect.Method ; 22 import java.util.HashMap ; 23 import java.util.Map ; 24 25 import org.aopalliance.intercept.MethodInvocation; 26 27 import org.springframework.util.ClassUtils; 28 29 46 public class RemoteInvocation implements Serializable { 47 48 49 private static final long serialVersionUID = 6876024250231820554L; 50 51 52 private String methodName; 53 54 private Class [] parameterTypes; 55 56 private Object [] arguments; 57 58 private Map attributes; 59 60 61 64 public RemoteInvocation() { 65 } 66 67 73 public RemoteInvocation(String methodName, Class [] parameterTypes, Object [] arguments) { 74 this.methodName = methodName; 75 this.parameterTypes = parameterTypes; 76 this.arguments = arguments; 77 } 78 79 83 public RemoteInvocation(MethodInvocation methodInvocation) { 84 this.methodName = methodInvocation.getMethod().getName(); 85 this.parameterTypes = methodInvocation.getMethod().getParameterTypes(); 86 this.arguments = methodInvocation.getArguments(); 87 } 88 89 90 93 public void setMethodName(String methodName) { 94 this.methodName = methodName; 95 } 96 97 100 public String getMethodName() { 101 return this.methodName; 102 } 103 104 107 public void setParameterTypes(Class [] parameterTypes) { 108 this.parameterTypes = parameterTypes; 109 } 110 111 114 public Class [] getParameterTypes() { 115 return this.parameterTypes; 116 } 117 118 121 public void setArguments(Object [] arguments) { 122 this.arguments = arguments; 123 } 124 125 128 public Object [] getArguments() { 129 return this.arguments; 130 } 131 132 133 144 public void addAttribute(String key, Serializable value) throws IllegalStateException { 145 if (this.attributes == null) { 146 this.attributes = new HashMap (); 147 } 148 if (this.attributes.containsKey(key)) { 149 throw new IllegalStateException ("There is already an attribute with key '" + key + "' bound"); 150 } 151 this.attributes.put(key, value); 152 } 153 154 161 public Serializable getAttribute(String key) { 162 if (this.attributes == null) { 163 return null; 164 } 165 return (Serializable ) this.attributes.get(key); 166 } 167 168 175 public void setAttributes(Map attributes) { 176 this.attributes = attributes; 177 } 178 179 186 public Map getAttributes() { 187 return this.attributes; 188 } 189 190 191 201 public Object invoke(Object targetObject) 202 throws NoSuchMethodException , IllegalAccessException , InvocationTargetException { 203 204 Method method = targetObject.getClass().getMethod(this.methodName, this.parameterTypes); 205 return method.invoke(targetObject, this.arguments); 206 } 207 208 209 public String toString() { 210 return "RemoteInvocation: method name '" + this.methodName + "'; parameter types " + 211 ClassUtils.classNamesToString(this.parameterTypes); 212 } 213 214 } 215 | Popular Tags |