/** * Returns the value of the given <code>field</code> in the given <code>object</code>. If * necessary, the field is made accessible, assuming the security manager allows it. * * @param field The field containing the value * @param object The object to retrieve the field's value from * @return the value of the <code>field</code> in the <code>object</code> * @throws IllegalStateException if the field is not accessible and the security manager doesn't * allow it to be made accessible */ public static Object getFieldValue(Field field, Object object) { ensureAccessible(field); try { return field.get(object); } catch (IllegalAccessException ex) { throw new IllegalStateException("Unable to access field.", ex); } }
/** * Creates a MethodMessageHandler for the given <code>method</code>, using given <code> * explicitPayloadType</code> (if not <code>null</code>) defining the payload of the message it * supports. If <code>null</code>, the payload type is deducted from the first parameter of the * method. * * @param method The method to create a Handler for * @param explicitPayloadType The payload type explicitly defined on the method, or <code>null * </code> * @return The MethodMessageHandler implementation for the given method. * @throws UnsupportedHandlerException if the given method is not suitable as a Handler */ public static MethodMessageHandler createFor(Method method, Class<?> explicitPayloadType) { ParameterResolver[] resolvers = findResolvers( method.getAnnotations(), method.getParameterTypes(), method.getParameterAnnotations(), explicitPayloadType == null); Class<?> payloadType = explicitPayloadType; if (explicitPayloadType == null) { Class<?> firstParameter = method.getParameterTypes()[0]; if (Message.class.isAssignableFrom(firstParameter)) { payloadType = Object.class; } else { payloadType = firstParameter; } } ensureAccessible(method); validate(method, resolvers); return new MethodMessageHandler(method, resolvers, payloadType); }