1 22 package org.jboss.mx.server; 23 24 import java.util.ArrayList ; 25 import java.util.List ; 26 27 import javax.management.Descriptor ; 28 import javax.management.MBeanParameterInfo ; 29 30 import org.jboss.mx.interceptor.AbstractInterceptor; 31 import org.jboss.mx.interceptor.Interceptor; 32 import org.jboss.util.Classes; 33 34 40 public class InvocationContext 41 { 42 43 45 public final static String OP_INVOKE = "invoke"; 46 public final static String OP_GETATTRIBUTE = "getAttribute"; 47 public final static String OP_SETATTRIBUTE = "setAttribute"; 48 public final static String OP_GETMBEANINFO = "getMBeanInfo"; 49 50 public final static String OPERATION_IMPACT = "operation.impact"; 51 public final static String ATTRIBUTE_ACCESS = "attribute.access"; 52 53 54 private static final Class VOID = Void .class; 55 56 public static final Class [] NOCLASSES = new Class [0]; 57 58 60 private String attributeType = null; 61 private String name = null; 62 private String [] signature = null; 63 private String returnType = null; 64 private String type = null; 65 private boolean isWritable = true; 66 private boolean isReadable = true; 67 68 List interceptors = null; 69 transient Interceptor dispatcher = new NullDispatcher(); 70 transient Object target = null; 71 transient Descriptor descriptor = null; 72 transient AbstractMBeanInvoker invoker = null; 73 transient Class attributeTypeClass = null; 74 transient Class returnTypeClass = null; 75 transient Class [] signatureClasses = null; 76 77 79 public final void copy(final InvocationContext src) 80 { 81 if (src == null) 82 return; 83 84 this.attributeType = src.attributeType; 85 this.attributeTypeClass = src.attributeTypeClass; 86 this.name = src.name; 87 this.signature = src.signature; 88 this.signatureClasses = src.signatureClasses; 89 this.returnType = src.returnType; 90 this.returnTypeClass = src.returnTypeClass; 91 this.type = src.type; 92 this.isWritable = src.isWritable; 93 this.interceptors = src.interceptors; 94 this.dispatcher = src.dispatcher; 95 this.target = src.target; 96 this.descriptor = src.descriptor; 97 this.invoker = src.invoker; 98 } 99 100 public void setType(String type) 101 { 102 this.type = type; 103 } 104 105 public String getType() 106 { 107 return type; 108 } 109 110 public void setName(String name) 111 { 112 this.name = name; 113 } 114 115 public String getName() 116 { 117 return name; 118 } 119 120 void setSignature(String [] signature) 121 { 122 this.signature = signature; 123 } 124 125 void setSignature(MBeanParameterInfo [] signature) 126 { 127 this.signature = new String [signature.length]; 128 129 for (int i = 0; i < signature.length; ++i) 130 this.signature[i] = signature[i].getType(); 131 132 } 133 134 public String [] getSignature() 135 { 136 return signature; 137 } 138 139 public Class [] getSignatureClasses() throws ClassNotFoundException 140 { 141 if (signatureClasses != null) 142 return signatureClasses; 143 if (signature == null || signature.length == 0) 144 return NOCLASSES; 145 Class [] signatureClassesTemp = new Class [signature.length]; 146 for (int i = 0; i < signature.length; ++i) 147 signatureClassesTemp[i] = Thread.currentThread().getContextClassLoader().loadClass(signature[i]); 148 signatureClasses = signatureClassesTemp; 149 return signatureClasses; 150 } 151 152 public void setAttributeType(String attrType) 153 { 154 this.attributeType = attrType; 155 this.attributeTypeClass = null; 156 } 157 158 public String getAttributeType() 159 { 160 return attributeType; 161 } 162 163 public Class getAttributeTypeClass() throws ClassNotFoundException 164 { 165 if (attributeType == null) 166 return null; 167 if (attributeTypeClass != null) 168 return attributeTypeClass; 169 attributeTypeClass = loadClass(attributeType); 170 return attributeTypeClass; 171 } 172 173 public void setReturnType(String returnType) 174 { 175 this.returnType = returnType; 176 this.returnTypeClass = null; 177 } 178 179 public String getReturnType() 180 { 181 return returnType; 182 } 183 184 public Class getReturnTypeClass() throws ClassNotFoundException 185 { 186 if (returnType == null) 187 return null; 188 if (returnTypeClass == VOID) 189 return null; 190 if (returnTypeClass != null) 191 return returnTypeClass; 192 if (returnType.equals("void")) 193 { 194 returnTypeClass = VOID; 195 return null; 196 } 197 else 198 returnTypeClass = loadClass(returnType); 199 return returnTypeClass; 200 } 201 202 public boolean isReadable() 203 { 204 return isReadable; 205 } 206 207 public void setReadable(boolean readable) 208 { 209 isReadable = readable; 210 } 211 212 public boolean isWritable() 213 { 214 return isWritable; 215 } 216 217 public void setWritable(boolean writable) 218 { 219 this.isWritable = writable; 220 } 221 222 public void setInterceptors(List interceptors) 223 { 224 this.interceptors = interceptors; 226 } 227 228 public List getInterceptors() 229 { 230 if (interceptors == null) 232 { 233 interceptors = new ArrayList (); 234 } 235 return interceptors; 236 } 237 238 public void setDispatcher(Interceptor d) 239 { 240 this.dispatcher = d; 241 } 242 243 public Interceptor getDispatcher() 244 { 245 return dispatcher; 246 } 247 248 void setTarget(Object o) 249 { 250 this.target = o; 251 } 252 253 public Object getTarget() 254 { 255 return target; 256 } 257 258 public void setDescriptor(Descriptor d) 259 { 260 this.descriptor = d; 261 } 262 263 public Descriptor getDescriptor() 264 { 265 return descriptor; 266 } 267 268 public void setInvoker(AbstractMBeanInvoker mi) 269 { 270 this.invoker = mi; 271 } 272 273 public MBeanInvoker getInvoker() 274 { 275 return invoker; 276 } 277 278 281 public String toString() 282 { 283 StringBuffer sbuf = new StringBuffer (256); 284 285 sbuf.append("InvocationContext[") 286 .append(" name=").append(name) 287 .append(", type=").append(type) 288 .append(", attributeType=").append(attributeType) 289 .append(", isReadable=").append(isReadable) 290 .append(", isWritable=").append(isWritable) 291 .append(", returnType=").append(returnType); 292 293 if (signature != null) 294 { 295 sbuf.append(", signature=["); 296 for (int i = 0; i < signature.length; i++) 297 { 298 sbuf.append(" arg[").append(i).append("]=").append(signature[i]); 299 } 300 sbuf.append(" ] ]"); 301 } 302 else 303 { 304 sbuf.append(", signature=null ]"); 305 } 306 return sbuf.toString(); 307 } 308 309 311 private Class loadClass(String clazz) throws ClassNotFoundException 312 { 313 Class isPrimitive = Classes.getPrimitiveTypeForName(clazz); 314 if (isPrimitive != null) 315 return Classes.getPrimitiveWrapper(isPrimitive); 316 ClassLoader cl = Thread.currentThread().getContextClassLoader(); 317 return cl.loadClass(clazz); 318 } 319 320 322 class NullDispatcher extends AbstractInterceptor 323 { 324 public NullDispatcher() 325 { 326 super("NullDispatcher"); 327 } 328 329 public Object invoke(Invocation invocation) throws Throwable 330 { 331 return null; 332 } 333 } 334 } 335 | Popular Tags |