private Method getDeclaredMethod(Class<?> cl, String methodName,
                                     Class<?>... parameterTypes) throws NoSuchMethodException
    {
        do {
            try {
                return cl.getDeclaredMethod(methodName, parameterTypes);
            }
            catch (NoSuchMethodException e) {
                // do nothing - just fall through to the below
            }
            cl = cl.getSuperclass();
        }
        while (cl != null);
        throw new NoSuchMethodException("Method " + methodName
                + "() not found in hierarchy");
    }