List of usage examples for java.lang NoSuchMethodException NoSuchMethodException
public NoSuchMethodException(String s)
NoSuchMethodException
with a detail message. From source file:org.robobinding.util.ConstructorUtils.java
/** * <p>/*from w w w . jav a 2 s . c o m*/ * Returns a new instance of the specified class choosing the right * constructor from the list of parameter types. * </p> * * <p> * This locates and calls a constructor. The constructor signature must * match the parameter types by assignment compatibility. * </p> * * @param <T> * the type to be constructed * @param cls * the class to be constructed, not null * @param args * the array of arguments, null treated as empty * @param parameterTypes * the array of parameter types, null treated as empty * @return new instance of <code>cls</code>, not null * * @throws NoSuchMethodException * if a matching constructor cannot be found * @throws IllegalAccessException * if invocation is not permitted by security * @throws InvocationTargetException * if an error occurs on invocation * @throws InstantiationException * if an error occurs on instantiation * @see Constructor#newInstance */ public static <T> T invokeConstructor(final Class<T> cls, Object[] args, Class<?>[] parameterTypes) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { if (parameterTypes == null) { parameterTypes = ArrayUtils.EMPTY_CLASS_ARRAY; } if (args == null) { args = ArrayUtils.EMPTY_OBJECT_ARRAY; } final Constructor<T> ctor = getMatchingAccessibleConstructor(cls, parameterTypes); if (ctor == null) { throw new NoSuchMethodException("No such accessible constructor on object: " + cls.getName()); } return ctor.newInstance(args); }
From source file:IntrospectionUtil.java
protected static Method findInheritedMethod(Package pack, Class clazz, String methodName, Class[] args, boolean strictArgs) throws NoSuchMethodException { if (clazz == null) throw new NoSuchMethodException("No class"); if (methodName == null) throw new NoSuchMethodException("No method name"); Method method = null;//from w w w .j a v a 2 s. c o m Method[] methods = clazz.getDeclaredMethods(); for (int i = 0; i < methods.length && method == null; i++) { if (methods[i].getName().equals(methodName) && isInheritable(pack, methods[i]) && checkParams(methods[i].getParameterTypes(), args, strictArgs)) method = methods[i]; } if (method != null) { return method; } else return findInheritedMethod(clazz.getPackage(), clazz.getSuperclass(), methodName, args, strictArgs); }
From source file:org.openamf.invoker.SpringBeanInvoker.java
private RankedMethod getServiceMethod(Class serviceClass, String methodName, List parameters) throws SecurityException, NoSuchMethodException { RankedMethod serviceMethod = null;//from www . j a v a 2s . com Method[] methods = serviceClass.getMethods(); List rankedMethods = new ArrayList(methods.length); for (int i = 0; i < methods.length; i++) { Method method = methods[i]; RankedMethod rankedMethod = new RankedMethod(method, methodName, parameters); if (rankedMethod.isInvokable()) { rankedMethods.add(rankedMethod); } } if (rankedMethods.size() > 0) { Collections.sort(rankedMethods); RankedMethod topRankedMethod = (RankedMethod) rankedMethods.get(0); serviceMethod = topRankedMethod; } if (serviceMethod == null) { String errorDesc = serviceClass + "." + methodName + "(" + parameters + ")"; throw new NoSuchMethodException(errorDesc); } return serviceMethod; }
From source file:com.curl.orb.servlet.InstanceManagementUtil.java
/** * Get static Method./*from w w w .j av a 2 s. c om*/ */ public static Method getStaticMethod(Class<?> cls, String methodName, Object[] arguments) throws NoSuchMethodException { Method method = MethodUtils.getMatchingAccessibleMethod(cls, methodName, getArgumentClasses(arguments)); if (method == null) throw new NoSuchMethodException("No such accessible method: " + methodName + "() on object"); return method; }
From source file:com.github.dozermapper.core.propertydescriptor.JavaBeanPropertyDescriptor.java
/** * PropertyDescriptor may lose the references to the write and read methods during * garbage collection. If the methods can't be found, we should retry once to * ensure that our PropertyDescriptor hasn't gone bad and the method really * isn't there./*from www .j a v a 2 s .c o m*/ * * @param writeMethod {@code true} to look for the write method for a property, * {@code false} to look for the read method * @return the method or {@code null} * @throws NoSuchMethodException if we've already retried finding the method once * @see <a href="https://github.com/DozerMapper/dozer/issues/118">Dozer mapping stops working</a> */ private Method retryMissingMethod(boolean writeMethod) throws NoSuchMethodException { if (propertyDescriptorsRefreshed) { throw new NoSuchMethodException("Unable to determine " + (writeMethod ? "write" : "read") + " method for Field: '" + fieldName + "' in Class: " + clazz); } else { refreshPropertyDescriptors(); return writeMethod ? getWriteMethod() : getReadMethod(); } }
From source file:com.bstek.dorado.data.resolver.manager.DataResolverInterceptorInvoker.java
public Object invoke(MethodInvocation methodInvocation) throws Throwable { Method proxyMethod = methodInvocation.getMethod(); if (!proxyMethod.getName().equals(INTERCEPTING_METHOD_NAME)) { return methodInvocation.proceed(); }/* w w w.j a va 2 s . co m*/ if (interceptor == null) { interceptor = BeanFactoryUtils.getBean(interceptorName); } Method[] methods = MethodAutoMatchingUtils.getMethodsByName(interceptor.getClass(), methodName); if (methods.length == 0) { throw new NoSuchMethodException(resourceManager.getString("dorado.common/methodNotFoundInInterceptor", interceptorName, methodName)); } DataResolver dataResolver = (DataResolver) methodInvocation.getThis(); MethodAutoMatchingException[] exceptions = new MethodAutoMatchingException[4]; int i = 0; try { try { return invokeInterceptorByParamName(dataResolver, methods, methodInvocation, false); } catch (MoreThanOneMethodsMatchsException e) { throw e; } catch (MethodAutoMatchingException e) { exceptions[i++] = e; } catch (AbortException e) { // do nothing } try { return invokeInterceptorByParamName(dataResolver, methods, methodInvocation, true); } catch (MoreThanOneMethodsMatchsException e) { throw e; } catch (MethodAutoMatchingException e) { exceptions[i++] = e; } catch (AbortException e) { // do nothing } try { return invokeInterceptorByParamType(dataResolver, methods, methodInvocation, false); } catch (MoreThanOneMethodsMatchsException e) { throw e; } catch (MethodAutoMatchingException e) { exceptions[i++] = e; } catch (AbortException e) { // do nothing } try { return invokeInterceptorByParamType(dataResolver, methods, methodInvocation, true); } catch (MoreThanOneMethodsMatchsException e) { throw e; } catch (MethodAutoMatchingException e) { exceptions[i++] = e; } catch (AbortException e) { // do nothing } } catch (MethodAutoMatchingException e) { exceptions[i++] = e; } for (MethodAutoMatchingException e : exceptions) { if (e == null) { break; } logger.error(e.getMessage()); } throw new IllegalArgumentException(resourceManager.getString("dorado.common/noMatchingMethodError", interceptor.getClass().getName(), methodName)); }
From source file:org.apache.olingo.ext.proxy.commons.EntitySetInvocationHandler.java
@Override public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { if ("filter".equals(method.getName()) || "orderBy".equals(method.getName()) || "top".equals(method.getName()) || "skip".equals(method.getName()) || "expand".equals(method.getName()) || "select".equals(method.getName())) { invokeSelfMethod(method, args);//from w ww . j a v a 2 s . c o m return proxy; } else if (isSelfMethod(method)) { return invokeSelfMethod(method, args); } else { throw new NoSuchMethodException(method.getName()); } }
From source file:org.mypsycho.beans.DefaultInvoker.java
public Object get(Object bean, PropertyDescriptor prop) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { Method readMethod = getReadMethod(bean.getClass(), prop); if (readMethod == null) { throw new NoSuchMethodException( "Property '" + prop.getName() + "' has no getter method in class '" + bean.getClass() + "'"); }/*from w w w .j a v a2 s . c o m*/ // Call the property getter and return the value return invokeMethod(readMethod, bean, EMPTY_OBJECT_ARRAY); }
From source file:it.scoppelletti.mobilepower.app.AbstractDialogFragment.java
public Member resolveMember(Class<?> clazz, int memberCode) { Member member;/*from ww w .j a v a2s. com*/ try { switch (memberCode) { case AbstractDialogFragment.CTOR_ALERTDIALOGBUILDER: member = clazz.getConstructor(Context.class, Integer.TYPE); break; default: throw new NoSuchMethodException(String.format("Unexpected memberCode %1$d.", memberCode)); } } catch (Exception ex) { throw new UnsupportedOperationException(ex.getMessage(), ex); } return member; }
From source file:org.dhatim.javabean.factory.BasicFactoryDefinitionParser.java
/** * Creates a StaticMethodFactory object. * * @param factoryDefinition//from w ww .j ava 2s. c o m * @param className * @param methodDef * @return * @throws ClassNotFoundException * @throws SecurityException * @throws NoSuchMethodException */ private Factory<?> createStaticMethodFactory(String factoryDefinition, String className, String methodDef) throws ClassNotFoundException, SecurityException, NoSuchMethodException { Class<?> factoryClass = ClassUtil.forName(className, this.getClass()); Method factoryMethod = factoryClass.getMethod(methodDef); if (!Modifier.isStatic(factoryMethod.getModifiers())) { throw new NoSuchMethodException( "No static method with the name '" + methodDef + "' can be found on the class '" + className + "' while processing the factory definition '" + factoryDefinition + "'."); } return new StaticMethodFactory(factoryDefinition, factoryMethod); }