/** * Constructs a mapper by reflecting on the class. */ public MethodMapper(Class resourceClass) { map = createMap(resourceClass); }
/** * Return a method matching the getter signature expected for an attribute. * * @param info the info * @return the method */ public Method lookupGetter(MBeanAttributeInfo info) { if (null == info) { throw new IllegalArgumentException("MBeanAttributeInfo cannot be null"); } return (Method) map.get(getterSignature(info)); }
/** * Return a method matching the specified signature */ public Method lookupMethod(String returnType, String name, String[] signature) { if (null == returnType) { throw new IllegalArgumentException("returnType cannot be null"); } if (null == name) { throw new IllegalArgumentException("method name cannot be null"); } return (Method) map.get(methodSignature(returnType, name, signature)); }
MethodMapper mmap = new MethodMapper(clazz); if (trace) log.trace(getObjectName() + " " + clazz + " map=" + mmap); Method m = mmap.lookupOperation(op); if (m == null) m = MethodMapper.lookupOperation(op, this); if (m != null) InvocationContext ctx = (InvocationContext) attributeContextMap.get(name); Method getter = mmap.lookupGetter(attribute); Method setter = mmap.lookupSetter(attribute); ctx.setDispatcher(new AttributeDispatcher(getter, setter, dynamicResource)); ctx.setTarget(resource);
opsMap.put(MethodMapper.operationSignature(operations[i]), operations[i]); String key = MethodMapper.getterSignature(attributes[i]); ModelMBeanOperationInfo opinfo = (ModelMBeanOperationInfo) opsMap.get(key); String role = (String) opinfo.getDescriptor().getFieldValue("role"); String key = MethodMapper.setterSignature(attributes[i]); ModelMBeanOperationInfo opinfo = (ModelMBeanOperationInfo) opsMap.get(key);
/** * Return a method matching the setter signature expected for an attribute */ public Method lookupSetter(MBeanAttributeInfo info) { if (null == info) { throw new IllegalArgumentException("MBeanAttributeInfo cannot be null"); } return (Method) map.get(setterSignature(info)); }
/** * Return a method matching the signature defined in the operation info */ public Method lookupOperation(MBeanOperationInfo info) { if (null == info) { throw new IllegalArgumentException("MBeanOperationInfo cannot be null"); } return (Method) map.get(operationSignature(info)); }
MethodMapper mmap = new MethodMapper(clazz); if (trace) log.trace(getObjectName() + " " + clazz + " map=" + mmap); Method m = mmap.lookupOperation(op); if (m == null) m = MethodMapper.lookupOperation(op, this); if (m != null) InvocationContext ctx = (InvocationContext) attributeContextMap.get(name); Method getter = mmap.lookupGetter(attribute); Method setter = mmap.lookupSetter(attribute); ctx.setDispatcher(new AttributeDispatcher(getter, setter, dynamicResource)); ctx.setTarget(resource);
opsMap.put(MethodMapper.operationSignature(operations[i]), operations[i]); String key = MethodMapper.getterSignature(attributes[i]); ModelMBeanOperationInfo opinfo = (ModelMBeanOperationInfo) opsMap.get(key); String role = (String) opinfo.getDescriptor().getFieldValue("role"); String key = MethodMapper.setterSignature(attributes[i]); ModelMBeanOperationInfo opinfo = (ModelMBeanOperationInfo) opsMap.get(key);
/** * Return a method matching the setter signature expected for an attribute * * @param info the info * @return the method */ public Method lookupSetter(MBeanAttributeInfo info) { if (null == info) { throw new IllegalArgumentException("MBeanAttributeInfo cannot be null"); } return (Method) map.get(setterSignature(info)); }
/** * Return a method matching the signature defined in the operation info * * @param info the info * @return the method */ public Method lookupOperation(MBeanOperationInfo info) { if (null == info) { throw new IllegalArgumentException("MBeanOperationInfo cannot be null"); } return (Method) map.get(operationSignature(info)); }
/** * Return a method matching the specified signature * * @param returnType the return type * @param name the name * @param signature the signature * @return the method */ public Method lookupMethod(String returnType, String name, String[] signature) { if (null == returnType) { throw new IllegalArgumentException("returnType cannot be null"); } if (null == name) { throw new IllegalArgumentException("method name cannot be null"); } return (Method) map.get(methodSignature(returnType, name, signature)); }
/** * Constructs a mapper by reflecting on the class. * * @param resourceClass the resource class */ public MethodMapper(Class resourceClass) { map = createMap(resourceClass); }
/** * Return a method matching the getter signature expected for an attribute. */ public Method lookupGetter(MBeanAttributeInfo info) { if (null == info) { throw new IllegalArgumentException("MBeanAttributeInfo cannot be null"); } return (Method) map.get(getterSignature(info)); }
/** * creates the signature string to Method HashMap. */ protected HashMap createMap(Class resourceClass) { HashMap cmap = new HashMap(); if (resourceClass != null) { Method[] methods = resourceClass.getMethods(); for (int i = 0; i < methods.length; i++) { Method method = methods[i]; cmap.put(methodSignature(method), method); } } return cmap; }
/** * creates the signature string to Method HashMap. * * @param resourceClass the resource class * @return the map */ protected HashMap createMap(Class resourceClass) { HashMap cmap = new HashMap(); if (resourceClass != null) { Method[] methods = resourceClass.getMethods(); for (int i = 0; i < methods.length; i++) { Method method = methods[i]; cmap.put(methodSignature(method), method); } } return cmap; }
/** * Generates a signature string using a Method object. */ public static String methodSignature(Method method) { if (null == method) { throw new IllegalArgumentException("Method cannot be null"); } Class[] paramtypes = method.getParameterTypes(); String[] signature = new String[paramtypes.length]; for (int i = 0; i < signature.length; i++) { signature[i] = paramtypes[i].getName(); } return methodSignature(method.getReturnType().getName(), method.getName(), signature); }
/** * Generates a signature string using a Method object. * * @param method the method * @return signature */ public static String methodSignature(Method method) { if (null == method) { throw new IllegalArgumentException("Method cannot be null"); } Class[] paramtypes = method.getParameterTypes(); String[] signature = new String[paramtypes.length]; for (int i = 0; i < signature.length; i++) { signature[i] = paramtypes[i].getName(); } return methodSignature(method.getReturnType().getName(), method.getName(), signature); }
/** * Generates a signature string for an attribute setter method using standard rules * * @param info the info * @return signature */ public static String setterSignature(MBeanAttributeInfo info) { if (null == info) { throw new IllegalArgumentException("MBeanAttributeInfo cannot be null"); } String sig = null; if( info instanceof ModelMBeanAttributeInfo ) { ModelMBeanAttributeInfo minfo = (ModelMBeanAttributeInfo) info; Descriptor desc = minfo.getDescriptor(); String methodName = (String) desc.getFieldValue(ModelMBeanConstants.SET_METHOD); String[] typeSig = {info.getType()}; if( methodName != null ) sig = methodSignature(Void.TYPE.getName(), methodName, typeSig); } if( sig == null ) { String[] typeSig = {info.getType()}; sig = methodSignature(Void.TYPE.getName(), "set" + info.getName(), typeSig); } return sig; }
/** * Generates a signature string for an attribute setter method using standard rules */ public static String setterSignature(MBeanAttributeInfo info) { if (null == info) { throw new IllegalArgumentException("MBeanAttributeInfo cannot be null"); } String sig = null; if( info instanceof ModelMBeanAttributeInfo ) { ModelMBeanAttributeInfo minfo = (ModelMBeanAttributeInfo) info; Descriptor desc = minfo.getDescriptor(); String methodName = (String) desc.getFieldValue(ModelMBeanConstants.SET_METHOD); String[] typeSig = {info.getType()}; if( methodName != null ) sig = methodSignature(Void.TYPE.getName(), methodName, typeSig); } if( sig == null ) { String[] typeSig = {info.getType()}; sig = methodSignature(Void.TYPE.getName(), "set" + info.getName(), typeSig); } return sig; }