List of usage examples for java.lang NoSuchMethodException NoSuchMethodException
public NoSuchMethodException(String s)
NoSuchMethodException
with a detail message. From source file:controllerTas.config.xml.TasControllerConfigXmlParser.java
private void invokeSet(Object o, Class clazz, String nodeName, Object param) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { String nameMethod = "set" + nodeName.substring(0, 1).toUpperCase() + nodeName.substring(1); log.debug("Going to invoke " + nameMethod + " on Object of " + clazz); Class returnType = this.getClassMethodIfExists(clazz, nameMethod); if (returnType == null) { throw new NoSuchMethodException("Non ho trovato il metodo " + nameMethod); }//w w w. j a v a 2 s.co m Method m = clazz.getMethod(nameMethod, returnType); this.typeAwareInvokeSet(o, m, param, returnType); }
From source file:org.mule.transport.rmi.RmiConnector.java
/** * Helper method for Dispatchers and Receives to extract the correct method from * a Remote object/*from ww w .j a v a2s.c o m*/ * * @param remoteObject The remote object on which to invoke the method * @param event The current event being processed * @throws org.mule.api.MuleException * @throws NoSuchMethodException * @throws ClassNotFoundException */ public Method getMethodObject(Remote remoteObject, MuleEvent event, OutboundEndpoint outboundEndpoint) throws MuleException, NoSuchMethodException, ClassNotFoundException { EndpointURI endpointUri = outboundEndpoint.getEndpointURI(); String methodName = MapUtils.getString(endpointUri.getParams(), MuleProperties.MULE_METHOD_PROPERTY, null); if (null == methodName) { methodName = (String) event.getMessage().removeProperty(MuleProperties.MULE_METHOD_PROPERTY, PropertyScope.INVOCATION); if (null == methodName) { throw new MessagingException(RmiMessages.messageParamServiceMethodNotSet(), event); } } Class[] argTypes = getArgTypes( event.getMessage().getInvocationProperty(RmiConnector.PROPERTY_SERVICE_METHOD_PARAM_TYPES), event); try { return remoteObject.getClass().getMethod(methodName, argTypes); } catch (NoSuchMethodException e) { throw new NoSuchMethodException(CoreMessages.methodWithParamsNotFoundOnObject(methodName, ArrayUtils.toString(argTypes), remoteObject.getClass()).toString()); } catch (SecurityException e) { throw e; } }
From source file:app.commons.ReflectionUtils.java
/** * We cannot use <code>clazz.getMethod(String name, Class<?>... parameterTypes)</code> because it only returns public methods. *///ww w .j a v a 2 s . c om private static Method getMethod(Class clazz, String methodName, Class<?>... parameterTypes) { Class currentClass = clazz; while (currentClass != null) { try { Method method = currentClass.getDeclaredMethod(methodName, parameterTypes); method.setAccessible(true); return method; } catch (NoSuchMethodException e) { currentClass = currentClass.getSuperclass(); } } throw new RuntimeException(new NoSuchMethodException(methodName)); }
From source file:com.liusoft.dlog4j.action.ActionExtend.java
/** * ?//from w ww.jav a 2 s. c o m * * @param mapping * @param form * @param req * @param res * @param methodName * @param value * @return * @throws Exception */ private ActionForward callActionMethod(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res, String methodName, String value) throws Exception { Method doMethod = null; Object params[] = (Object[]) null; for (int i = 0; i < methodParams.length; i++) { try { doMethod = getClass().getDeclaredMethod(methodName, methodParams[i]); if (doMethod == null) continue; Class[] param_classes = doMethod.getParameterTypes(); if (param_classes.length == 4) params = new Object[] { mapping, form, req, res }; else params = new Object[] { mapping, form, req, res, value }; break; } catch (NoSuchMethodException excp) { } } if (doMethod != null) { if (paramMapping(doMethod.getName())) BeanUtils.populate(this, req.getParameterMap()); Object ret = doMethod.invoke(this, params); Class returnType = doMethod.getReturnType(); if (returnType.equals(ActionForward.class)) return (ActionForward) ret; if (returnType.equals(String.class)) return new ActionForward((String) ret, true); if (returnType.equals(void.class) || returnType.equals(Void.class)) return null; throw new UnsupportedReturnTypeException(ret.getClass().getName()); } throw new NoSuchMethodException(getClass().getName() + ":" + methodName); }
From source file:org.apache.camel.util.IntrospectionSupport.java
public static Method getPropertySetter(Class<?> type, String propertyName) throws NoSuchMethodException { String name = "set" + ObjectHelper.capitalize(propertyName); for (Method method : type.getMethods()) { if (isSetter(method) && method.getName().equals(name)) { return method; }//from w w w . j a v a2 s . co m } throw new NoSuchMethodException(type.getCanonicalName() + "." + name); }
From source file:it.scoppelletti.mobilepower.app.AbstractActivity.java
public Member resolveMember(Class<?> clazz, int memberCode) { Member member;/* w w w . jav a 2s . c o m*/ try { switch (memberCode) { case AbstractActivity.METHOD_GETACTIONBAR: member = clazz.getMethod("getActionBar"); 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:com.p5solutions.core.jpa.orm.MapUtilityImpl.java
protected Method[] getMethodsGetterAndSetter(Class<?> targetClazz, String fieldName) { // String[] p = path.split("\\.", 2); // if the field name is not null or empty, then its probably valid. if (Comparison.isNotEmpty(fieldName)) { Method[] methods = new Method[2]; // get the field name from index 0, since we only splice by a // maximum of 2 // String fieldName = p[0]; // find the getter method, make sure it exists Method getterMethod = ReflectionUtility.findGetterMethod(targetClazz, fieldName); if (getterMethod == null) { throw new RuntimeException(new NoSuchMethodException( "No getter method found when using field name [" + fieldName + "] as search pattern!")); }/*w ww . j ava 2 s . c o m*/ // find the setter method, make sure it exists Method setterMethod = ReflectionUtility.findSetterMethod(targetClazz, getterMethod); if (setterMethod == null) { throw new RuntimeException(new NoSuchMethodException( "No setter method found when using field name [" + fieldName + "] as search pattern!")); } methods[0] = getterMethod; methods[1] = setterMethod; return methods; } return null; }
From source file:org.mule.module.launcher.application.CompositeApplicationClassLoader.java
private Method findDeclaredMethod(ClassLoader classLoader, String methodName, Class<?>... params) throws NoSuchMethodException { Class clazz = classLoader.getClass(); while (clazz != null) { try {/*w w w . j a va 2 s. c o m*/ Method findLibraryMethod = clazz.getDeclaredMethod(methodName, params); findLibraryMethod.setAccessible(true); return findLibraryMethod; } catch (NoSuchMethodException e) { clazz = clazz.getSuperclass(); } } throw new NoSuchMethodException( String.format("Cannot find a method '%s' with the given parameter types '%s'", methodName, Arrays.toString(params))); }
From source file:com.softmotions.commons.bean.BeanUtils.java
/** * Sets a property at the given bean.//from ww w . j a v a 2 s . co m * * @param bean The bean to set a property at. * @param propertyName The name of the property to set. * @param value The value to set for the property. * @throws BeanException In case the bean access failed. */ public static void setProperty(Object bean, String propertyName, Object value) throws BeanException { Class valueClass = null; try { // getting property object from bean using "setNnnn", where nnnn is parameter name Method setterMethod = null; // first trying form getPropertyNaae for regular value String setterName = "set" + Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1); Class paramClass = bean.getClass(); if (value != null) { valueClass = value.getClass(); Class[] setterArgTypes = new Class[] { valueClass }; setterMethod = paramClass.getMethod(setterName, setterArgTypes); } else { Method[] methods = paramClass.getMethods(); for (int i = 0; i < methods.length; i++) { Method m = methods[i]; if (m.getName().equals(setterName) && (m.getParameterTypes().length == 1)) { setterMethod = m; break; } } } if (setterMethod == null) { throw new NoSuchMethodException(setterName); } Object[] setterArgs = new Object[] { value }; setterMethod.invoke(bean, setterArgs); } catch (NoSuchMethodError | NoSuchMethodException ex) { throw new BeanException("No setter method found for property '" + propertyName + "' and type " + valueClass + " at given bean from class " + bean.getClass().getName() + ".", ex); } catch (InvocationTargetException ex) { throw new BeanException("Property '" + propertyName + "' could not be set for given bean from class " + bean.getClass().getName() + ".", ex); } catch (IllegalAccessException ex) { throw new BeanException("Property '" + propertyName + "' could not be accessed for given bean from class " + bean.getClass().getName() + ".", ex); } }
From source file:com.enioka.jqm.tools.JobManagerHandler.java
@SuppressWarnings("unchecked") @Override//from ww w . j ava 2 s. c o m public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { ClassLoader initial = null; String methodName = method.getName(); Class<?>[] classes = method.getParameterTypes(); jqmlogger.trace("An engine API method was called: " + methodName + " with nb arguments: " + classes.length); try { initial = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); shouldKill(); if (classes.length == 0) { if ("jobApplicationId".equals(methodName)) { return jd.getId(); } else if ("parentID".equals(methodName)) { return ji.getParentId(); } else if ("jobInstanceID".equals(methodName)) { return ji.getId(); } else if ("canBeRestarted".equals(methodName)) { return jd.isCanBeRestarted(); } else if ("applicationName".equals(methodName)) { return jd.getApplicationName(); } else if ("sessionID".equals(methodName)) { return ji.getSessionID(); } else if ("application".equals(methodName)) { return application; } else if ("module".equals(methodName)) { return jd.getModule(); } else if ("keyword1".equals(methodName)) { return ji.getKeyword1(); } else if ("keyword2".equals(methodName)) { return ji.getKeyword2(); } else if ("keyword3".equals(methodName)) { return ji.getKeyword3(); } else if ("definitionKeyword1".equals(methodName)) { return jd.getKeyword1(); } else if ("definitionKeyword2".equals(methodName)) { return jd.getKeyword2(); } else if ("definitionKeyword3".equals(methodName)) { return jd.getKeyword3(); } else if ("userName".equals(methodName)) { return ji.getUserName(); } else if ("parameters".equals(methodName)) { return params; } else if ("defaultConnect".equals(methodName)) { return this.defaultCon; } else if ("getDefaultConnection".equals(methodName)) { return this.getDefaultConnection(); } else if ("getWorkDir".equals(methodName)) { return getWorkDir(); } else if ("yield".equals(methodName)) { return null; } else if ("waitChildren".equals(methodName)) { waitChildren(); return null; } } else if ("sendMsg".equals(methodName) && classes.length == 1 && classes[0] == String.class) { sendMsg((String) args[0]); return null; } else if ("sendProgress".equals(methodName) && classes.length == 1 && classes[0] == Integer.class) { sendProgress((Integer) args[0]); return null; } else if ("enqueue".equals(methodName) && classes.length == 10 && classes[0] == String.class) { return enqueue((String) args[0], (String) args[1], (String) args[2], (String) args[3], (String) args[4], (String) args[5], (String) args[6], (String) args[7], (String) args[8], (Map<String, String>) args[9]); } else if ("enqueueSync".equals(methodName) && classes.length == 10 && classes[0] == String.class) { return enqueueSync((String) args[0], (String) args[1], (String) args[2], (String) args[3], (String) args[4], (String) args[5], (String) args[6], (String) args[7], (String) args[8], (Map<String, String>) args[9]); } else if ("addDeliverable".equals(methodName) && classes.length == 2 && classes[0] == String.class && classes[1] == String.class) { return addDeliverable((String) args[0], (String) args[1]); } else if ("waitChild".equals(methodName) && classes.length == 1 && (args[0] instanceof Integer)) { waitChild((Integer) args[0]); return null; } else if ("hasEnded".equals(methodName) && classes.length == 1 && (args[0] instanceof Integer)) { return hasEnded((Integer) args[0]); } else if ("hasSucceeded".equals(methodName) && classes.length == 1 && (args[0] instanceof Integer)) { return hasSucceeded((Integer) args[0]); } else if ("hasFailed".equals(methodName) && classes.length == 1 && (args[0] instanceof Integer)) { return hasFailed((Integer) args[0]); } throw new NoSuchMethodException(methodName); } finally { Thread.currentThread().setContextClassLoader(initial); } }