List of usage examples for java.lang NoSuchMethodException NoSuchMethodException
public NoSuchMethodException(String s)
NoSuchMethodException
with a detail message. From source file:com.cyberway.issue.crawler.Heritrix.java
public Object invoke(final String operationName, final Object[] params, final String[] signature) throws ReflectionException { if (operationName == null) { throw new RuntimeOperationsException(new IllegalArgumentException("Operation name cannot be null"), "Cannot call invoke with null operation name"); }//from w w w . j av a2 s.c o m // INFO logging of JMX invokes: [#HER-907] if (logger.isLoggable(Level.INFO)) { String paramsString = ""; for (Object o : params) { paramsString.concat("[" + o.toString() + "]"); } logger.info("JMX invoke: " + operationName + " [" + paramsString + "]"); } // The pattern in the below is to match an operation and when found // do a return out of if clause. Doing it this way, I can fall // on to the MethodNotFoundException for case where we've an // attribute but no handler. if (operationName.equals(START_OPER)) { JmxUtils.checkParamsCount(START_OPER, params, 0); start(); return null; } if (operationName.equals(STOP_OPER)) { JmxUtils.checkParamsCount(STOP_OPER, params, 0); stop(); return null; } if (operationName.equals(DESTROY_OPER)) { JmxUtils.checkParamsCount(DESTROY_OPER, params, 0); destroy(); return null; } if (operationName.equals(TERMINATE_CRAWL_JOB_OPER)) { JmxUtils.checkParamsCount(TERMINATE_CRAWL_JOB_OPER, params, 0); return new Boolean(this.jobHandler.terminateCurrentJob()); } if (operationName.equals(REBIND_JNDI_OPER)) { JmxUtils.checkParamsCount(REBIND_JNDI_OPER, params, 0); try { registerContainerJndi(); } catch (MalformedObjectNameException e) { throw new RuntimeOperationsException(new RuntimeException(e)); } catch (UnknownHostException e) { throw new RuntimeOperationsException(new RuntimeException(e)); } catch (NamingException e) { throw new RuntimeOperationsException(new RuntimeException(e)); } return null; } if (operationName.equals(SHUTDOWN_OPER)) { JmxUtils.checkParamsCount(SHUTDOWN_OPER, params, 0); Heritrix.shutdown(); return null; } if (operationName.equals(LOG_OPER)) { JmxUtils.checkParamsCount(LOG_OPER, params, 2); logger.log(Level.parse((String) params[0]), (String) params[1]); return null; } if (operationName.equals(INTERRUPT_OPER)) { JmxUtils.checkParamsCount(INTERRUPT_OPER, params, 1); return interrupt((String) params[0]); } if (operationName.equals(START_CRAWLING_OPER)) { JmxUtils.checkParamsCount(START_CRAWLING_OPER, params, 0); startCrawling(); return null; } if (operationName.equals(STOP_CRAWLING_OPER)) { JmxUtils.checkParamsCount(STOP_CRAWLING_OPER, params, 0); stopCrawling(); return null; } if (operationName.equals(ADD_CRAWL_JOB_OPER)) { JmxUtils.checkParamsCount(ADD_CRAWL_JOB_OPER, params, 4); try { return addCrawlJob((String) params[0], (String) params[1], checkForEmptyPlaceHolder((String) params[2]), checkForEmptyPlaceHolder((String) params[3])); } catch (IOException e) { throw new RuntimeOperationsException(new RuntimeException(e)); } catch (FatalConfigurationException e) { throw new RuntimeOperationsException(new RuntimeException(e)); } } if (operationName.equals(DELETE_CRAWL_JOB_OPER)) { JmxUtils.checkParamsCount(DELETE_CRAWL_JOB_OPER, params, 1); this.jobHandler.deleteJob((String) params[0]); return null; } if (operationName.equals(ADD_CRAWL_JOB_BASEDON_OPER)) { JmxUtils.checkParamsCount(ADD_CRAWL_JOB_BASEDON_OPER, params, 4); return addCrawlJobBasedOn((String) params[0], (String) params[1], checkForEmptyPlaceHolder((String) params[2]), checkForEmptyPlaceHolder((String) params[3])); } if (operationName.equals(ALERT_OPER)) { JmxUtils.checkParamsCount(ALERT_OPER, params, 1); SinkHandlerLogRecord slr = null; if (this.alertManager.getCount() > 0) { // This is creating a vector of all alerts just so I can then // use passed index into resultant vector -- needs to be // improved. slr = (SinkHandlerLogRecord) this.alertManager.getAll().get(((Integer) params[0]).intValue()); } return (slr != null) ? slr.toString() : null; } if (operationName.equals(PENDING_JOBS_OPER)) { JmxUtils.checkParamsCount(PENDING_JOBS_OPER, params, 0); try { return makeJobsTabularData(getJobHandler().getPendingJobs()); } catch (OpenDataException e) { throw new RuntimeOperationsException(new RuntimeException(e)); } } if (operationName.equals(COMPLETED_JOBS_OPER)) { JmxUtils.checkParamsCount(COMPLETED_JOBS_OPER, params, 0); try { return makeJobsTabularData(getJobHandler().getCompletedJobs()); } catch (OpenDataException e) { throw new RuntimeOperationsException(new RuntimeException(e)); } } if (operationName.equals(CRAWLEND_REPORT_OPER)) { JmxUtils.checkParamsCount(CRAWLEND_REPORT_OPER, params, 2); try { return getCrawlendReport((String) params[0], (String) params[1]); } catch (IOException e) { throw new RuntimeOperationsException(new RuntimeException(e)); } } throw new ReflectionException(new NoSuchMethodException(operationName), "Cannot find the operation " + operationName); }
From source file:com.clark.func.Functions.java
/** * <p>//www . j a va 2s. co m * Returns the desired Method much like <code>Class.getMethod</code>, * however it ensures that the returned Method is from a public class or * interface and not from an anonymous inner class. This means that the * Method is invokable and doesn't fall foul of Java bug <a * href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4071957" * >4071957</a>). * * <code><pre>Set set = Collections.unmodifiableSet(...); * Method method = ClassUtils.getPublicMethod(set.getClass(), "isEmpty", new Class[0]); * Object result = method.invoke(set, new Object[]);</pre></code> * </p> * * @param cls * the class to check, not null * @param methodName * the name of the method * @param parameterTypes * the list of parameters * @return the method * @throws NullPointerException * if the class is null * @throws SecurityException * if a a security violation occured * @throws NoSuchMethodException * if the method is not found in the given class or if the * metothod doen't conform with the requirements */ public static Method getPublicMethod(Class<?> cls, String methodName, Class<?> parameterTypes[]) throws SecurityException, NoSuchMethodException { Method declaredMethod = cls.getMethod(methodName, parameterTypes); if (Modifier.isPublic(declaredMethod.getDeclaringClass().getModifiers())) { return declaredMethod; } List<Class<?>> candidateClasses = new ArrayList<Class<?>>(); candidateClasses.addAll(getAllInterfaces(cls)); candidateClasses.addAll(getAllSuperclasses(cls)); for (Class<?> candidateClass : candidateClasses) { if (!Modifier.isPublic(candidateClass.getModifiers())) { continue; } Method candidateMethod; try { candidateMethod = candidateClass.getMethod(methodName, parameterTypes); } catch (NoSuchMethodException ex) { continue; } if (Modifier.isPublic(candidateMethod.getDeclaringClass().getModifiers())) { return candidateMethod; } } throw new NoSuchMethodException("Can't find a public method for " + methodName); }
From source file:com.clark.func.Functions.java
/** * <p>/*www . j av a2 s. co m*/ * Returns new instance of <code>klazz</code> created using constructor with * signature <code>parameterTypes</code> and actual arguments * <code>args</code>. * </p> * * <p> * The signatures should be assignment compatible. * </p> * * @param cls * the class to be constructed. * @param args * actual argument array * @param parameterTypes * parameter types array * @return new instance of <code>klazz</code> * * @throws NoSuchMethodException * if matching constructor cannot be found * @throws IllegalAccessException * thrown on the constructor's invocation * @throws InvocationTargetException * thrown on the constructor's invocation * @throws InstantiationException * thrown on the constructor's invocation * @see Constructor#newInstance */ public static <T> T invokeConstructor(Class<T> cls, Object[] args, Class<?>[] parameterTypes) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { if (parameterTypes == null) { parameterTypes = EMPTY_CLASS_ARRAY; } if (args == null) { args = EMPTY_OBJECT_ARRAY; } Constructor<T> ctor = getMatchingAccessibleConstructor(cls, parameterTypes); if (null == ctor) { throw new NoSuchMethodException("No such accessible constructor on object: " + cls.getName()); } return ctor.newInstance(args); }
From source file:com.clark.func.Functions.java
/** * <p>//from w w w. j a v a2 s . c o m * Returns new instance of <code>klazz</code> created using constructor with * signature <code>parameterTypes</code> and actual arguments * <code>args</code>. * </p> * * <p> * The signatures should match exactly. * </p> * * @param cls * the class to be constructed. * @param args * actual argument array * @param parameterTypes * parameter types array * @return new instance of <code>klazz</code> * * @throws NoSuchMethodException * if matching constructor cannot be found * @throws IllegalAccessException * thrown on the constructor's invocation * @throws InvocationTargetException * thrown on the constructor's invocation * @throws InstantiationException * thrown on the constructor's invocation * @see Constructor#newInstance */ public static <T> T invokeExactConstructor(Class<T> cls, Object[] args, Class<?>[] parameterTypes) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { if (args == null) { args = EMPTY_OBJECT_ARRAY; } if (parameterTypes == null) { parameterTypes = EMPTY_CLASS_ARRAY; } Constructor<T> ctor = getAccessibleConstructor(cls, parameterTypes); if (null == ctor) { throw new NoSuchMethodException("No such accessible constructor on object: " + cls.getName()); } return ctor.newInstance(args); }
From source file:com.clark.func.Functions.java
/** * <p>/*from w w w. j a v a 2 s . c o m*/ * Invoke a named method whose parameter type matches the object type. * </p> * * <p> * This method delegates the method search to * {@link #getMatchingAccessibleMethod(Class, String, Class[])}. * </p> * * <p> * This method supports calls to methods taking primitive parameters via * passing in wrapping classes. So, for example, a <code>Boolean</code> * object would match a <code>boolean</code> primitive. * </p> * * @param object * invoke method on this object * @param methodName * get method with this name * @param args * use these arguments - treat null as empty array * @param parameterTypes * match these parameters - treat null as empty array * @return The value returned by the invoked method * * @throws NoSuchMethodException * if there is no such accessible method * @throws InvocationTargetException * wraps an exception thrown by the method invoked * @throws IllegalAccessException * if the requested method is not accessible via reflection */ public static Object invokeMethod(Object object, String methodName, Object[] args, Class<?>[] parameterTypes) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { if (parameterTypes == null) { parameterTypes = EMPTY_CLASS_ARRAY; } if (args == null) { args = EMPTY_OBJECT_ARRAY; } Method method = getMatchingAccessibleMethod(object.getClass(), methodName, parameterTypes); if (method == null) { throw new NoSuchMethodException( "No such accessible method: " + methodName + "() on object: " + object.getClass().getName()); } return method.invoke(object, args); }
From source file:com.clark.func.Functions.java
/** * <p>/*from w w w . jav a2 s. c o m*/ * Invoke a method whose parameter types match exactly the parameter types * given. * </p> * * <p> * This uses reflection to invoke the method obtained from a call to * <code>getAccessibleMethod()</code>. * </p> * * @param object * invoke method on this object * @param methodName * get method with this name * @param args * use these arguments - treat null as empty array * @param parameterTypes * match these parameters - treat null as empty array * @return The value returned by the invoked method * * @throws NoSuchMethodException * if there is no such accessible method * @throws InvocationTargetException * wraps an exception thrown by the method invoked * @throws IllegalAccessException * if the requested method is not accessible via reflection */ public static Object invokeExactMethod(Object object, String methodName, Object[] args, Class<?>[] parameterTypes) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { if (args == null) { args = EMPTY_OBJECT_ARRAY; } if (parameterTypes == null) { parameterTypes = EMPTY_CLASS_ARRAY; } Method method = getAccessibleMethod(object.getClass(), methodName, parameterTypes); if (method == null) { throw new NoSuchMethodException( "No such accessible method: " + methodName + "() on object: " + object.getClass().getName()); } return method.invoke(object, args); }
From source file:com.clark.func.Functions.java
/** * <p>/*from w w w .j av a2 s . c o m*/ * Invoke a static method whose parameter types match exactly the parameter * types given. * </p> * * <p> * This uses reflection to invoke the method obtained from a call to * {@link #getAccessibleMethod(Class, String, Class[])}. * </p> * * @param cls * invoke static method on this class * @param methodName * get method with this name * @param args * use these arguments - treat null as empty array * @param parameterTypes * match these parameters - treat null as empty array * @return The value returned by the invoked method * * @throws NoSuchMethodException * if there is no such accessible method * @throws InvocationTargetException * wraps an exception thrown by the method invoked * @throws IllegalAccessException * if the requested method is not accessible via reflection */ public static Object invokeExactStaticMethod(Class<?> cls, String methodName, Object[] args, Class<?>[] parameterTypes) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { if (args == null) { args = EMPTY_OBJECT_ARRAY; } if (parameterTypes == null) { parameterTypes = EMPTY_CLASS_ARRAY; } Method method = getAccessibleMethod(cls, methodName, parameterTypes); if (method == null) { throw new NoSuchMethodException( "No such accessible method: " + methodName + "() on class: " + cls.getName()); } return method.invoke(null, args); }
From source file:com.clark.func.Functions.java
/** * <p>/*ww w. ja va2 s . c o m*/ * Invoke a named static method whose parameter type matches the object * type. * </p> * * <p> * This method delegates the method search to * {@link #getMatchingAccessibleMethod(Class, String, Class[])}. * </p> * * <p> * This method supports calls to methods taking primitive parameters via * passing in wrapping classes. So, for example, a <code>Boolean</code> * class would match a <code>boolean</code> primitive. * </p> * * * @param cls * invoke static method on this class * @param methodName * get method with this name * @param args * use these arguments - treat null as empty array * @param parameterTypes * match these parameters - treat null as empty array * @return The value returned by the invoked method * * @throws NoSuchMethodException * if there is no such accessible method * @throws InvocationTargetException * wraps an exception thrown by the method invoked * @throws IllegalAccessException * if the requested method is not accessible via reflection */ public static Object invokeStaticMethod(Class<?> cls, String methodName, Object[] args, Class<?>[] parameterTypes) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { if (parameterTypes == null) { parameterTypes = EMPTY_CLASS_ARRAY; } if (args == null) { args = EMPTY_OBJECT_ARRAY; } Method method = getMatchingAccessibleMethod(cls, methodName, parameterTypes); if (method == null) { throw new NoSuchMethodException( "No such accessible method: " + methodName + "() on class: " + cls.getName()); } return method.invoke(null, args); }