List of usage examples for java.lang NoSuchMethodException NoSuchMethodException
public NoSuchMethodException(String s)
NoSuchMethodException
with a detail message. From source file:javadz.beanutils.PropertyUtilsBean.java
/** * Return the value of the specified mapped property of the specified * bean, with no type conversions./*w w w . j a v a2 s . c om*/ * * @param bean Bean whose property is to be extracted * @param name Mapped property name of the property value to be extracted * @param key Key of the property value to be extracted * @return the mapped property value * * @exception IllegalAccessException if the caller does not have * access to the property accessor method * @exception InvocationTargetException if the property accessor method * throws an exception * @exception NoSuchMethodException if an accessor method for this * propety cannot be found */ public Object getMappedProperty(Object bean, String name, String key) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { if (bean == null) { throw new IllegalArgumentException("No bean specified"); } if (name == null) { throw new IllegalArgumentException("No name specified for bean class '" + bean.getClass() + "'"); } if (key == null) { throw new IllegalArgumentException( "No key specified for property '" + name + "' on bean class " + bean.getClass() + "'"); } // Handle DynaBean instances specially if (bean instanceof DynaBean) { DynaProperty descriptor = ((DynaBean) bean).getDynaClass().getDynaProperty(name); if (descriptor == null) { throw new NoSuchMethodException( "Unknown property '" + name + "'+ on bean class '" + bean.getClass() + "'"); } return (((DynaBean) bean).get(name, key)); } Object result = null; // Retrieve the property descriptor for the specified property PropertyDescriptor descriptor = getPropertyDescriptor(bean, name); if (descriptor == null) { throw new NoSuchMethodException( "Unknown property '" + name + "'+ on bean class '" + bean.getClass() + "'"); } if (descriptor instanceof MappedPropertyDescriptor) { // Call the keyed getter method if there is one Method readMethod = ((MappedPropertyDescriptor) descriptor).getMappedReadMethod(); readMethod = MethodUtils.getAccessibleMethod(bean.getClass(), readMethod); if (readMethod != null) { Object[] keyArray = new Object[1]; keyArray[0] = key; result = invokeMethod(readMethod, bean, keyArray); } else { throw new NoSuchMethodException("Property '" + name + "' has no mapped getter method on bean class '" + bean.getClass() + "'"); } } else { /* means that the result has to be retrieved from a map */ Method readMethod = getReadMethod(bean.getClass(), descriptor); if (readMethod != null) { Object invokeResult = invokeMethod(readMethod, bean, EMPTY_OBJECT_ARRAY); /* test and fetch from the map */ if (invokeResult instanceof java.util.Map) { result = ((java.util.Map) invokeResult).get(key); } } else { throw new NoSuchMethodException("Property '" + name + "' has no mapped getter method on bean class '" + bean.getClass() + "'"); } } return result; }
From source file:net.lightbody.bmp.proxy.jetty.util.jmx.ModelMBeanImpl.java
public Object invoke(String name, Object[] params, String[] signature) throws MBeanException, ReflectionException { if (log.isDebugEnabled()) log.debug("invoke " + name); String methodKey = name + "("; if (signature != null) for (int i = 0; i < signature.length; i++) methodKey += (i > 0 ? "," : "") + signature[i]; methodKey += ")"; try {// w w w . j a v a 2 s .c o m Method method = (Method) _method.get(methodKey); if (method == null) throw new NoSuchMethodException(methodKey); Object o = _object; if (method.getDeclaringClass().isInstance(this)) o = this; return method.invoke(o, params); } catch (NoSuchMethodException e) { log.warn(LogSupport.EXCEPTION, e); throw new ReflectionException(e); } catch (IllegalAccessException e) { log.warn(LogSupport.EXCEPTION, e); throw new MBeanException(e); } catch (InvocationTargetException e) { log.warn(LogSupport.EXCEPTION, e); throw new ReflectionException((Exception) e.getTargetException()); } }
From source file:org.mypsycho.beans.PropertyUtilsBean.java
/** * <p>//from ww w.j a v a2 s . c om * Retrieve the property descriptor for the specified property of the specified bean, or return * <code>null</code> if there is no such descriptor. This method resolves indexed and nested * property references in the same manner as other methods in this class, except that if the * last (or only) name element is indexed, the descriptor for the last resolved property itself * is returned. * </p> * * @param bean Bean for which a property descriptor is requested * @param simpleName name of the property for which a property descriptor is requested * (no nested property supported) * @return the property descriptor * @exception IllegalAccessException if the caller does not have * access to the property accessor method * @exception IllegalArgumentException if <code>bean</code> or <code>name</code> is null * @exception IllegalArgumentException if a nested reference to a * property returns null * @exception InvocationTargetException if the property accessor method * throws an exception * @exception NoSuchMethodException if an accessor method for this * propety cannot be found */ public PropertyDescriptor getPropertyDescriptor(Class<?> beanClass, String name) throws NoSuchMethodException { PropertyDescriptor[] descriptors = getPropertyDescriptors(beanClass); for (PropertyDescriptor descriptor : descriptors) { if (name.equals(descriptor.getName())) { if (descriptor instanceof StubDescriptor) { throw new NoSuchMethodException("No property '" + name + "' at " + beanClass.getName()); } return (descriptor); } } PropertyDescriptor result; try { result = new MappedPropertyDescriptor(name, beanClass); } catch (IntrospectionException ie) { try { result = new StubDescriptor(name); } catch (IntrospectionException e) { return null; } } PropertyDescriptor[] newDescriptors = new PropertyDescriptor[descriptors.length + 1]; System.arraycopy(descriptors, 0, newDescriptors, 0, descriptors.length); newDescriptors[descriptors.length] = result; descriptorsCache.put(beanClass, newDescriptors); if (result instanceof StubDescriptor) { throw new NoSuchMethodException("No property '" + name + "' at " + beanClass.getName()); } return result; }
From source file:shared.utils.ReflectUtils.java
/** * ???//from ww w.j a v a 2 s . c om * * @param clazz * @param methodName ??method1(int, String)?????????method2 * @return * @throws NoSuchMethodException * @throws ClassNotFoundException * @throws IllegalStateException ??????? */ public static Method findMethodByMethodSignature(Class<?> clazz, String methodName, String[] parameterTypes) throws NoSuchMethodException, ClassNotFoundException { String signature = clazz.getName() + "." + methodName; if (parameterTypes != null && parameterTypes.length > 0) { signature = signature + StringUtils.join(parameterTypes); } Method method = Signature_METHODS_CACHE.get(signature); if (method != null) { return method; } if (parameterTypes == null) { List<Method> finded = new ArrayList<Method>(); for (Method m : clazz.getMethods()) { if (m.getName().equals(methodName)) { finded.add(m); } } if (finded.isEmpty()) { throw new NoSuchMethodException("No such method " + methodName + " in class " + clazz); } if (finded.size() > 1) { String msg = String.format("Not unique method for method name(%s) in class(%s), find %d methods.", methodName, clazz.getName(), finded.size()); throw new IllegalStateException(msg); } method = finded.get(0); } else { Class<?>[] types = new Class<?>[parameterTypes.length]; for (int i = 0; i < parameterTypes.length; i++) { types[i] = ReflectUtils.name2class(parameterTypes[i]); } method = clazz.getMethod(methodName, types); } Signature_METHODS_CACHE.put(signature, method); return method; }
From source file:eu.qualityontime.commons.QPropertyUtilsBean.java
public Object _getMappedProperty(final Object bean, final String name, final String key) throws Exception { if (bean == null) { throw new IllegalArgumentException("No bean specified"); }/*from w ww . j a v a 2s . c o m*/ if (name == null) { throw new IllegalArgumentException("No name specified for bean class '" + bean.getClass() + "'"); } if (key == null) { throw new IllegalArgumentException( "No key specified for property '" + name + "' on bean class " + bean.getClass() + "'"); } Object result = null; if (name.startsWith("@")) { Object invokeResult = FieldUtils.readField(bean, trimAnnotations(name)); if (null == invokeResult) { if (name.endsWith("?")) return null; else throw new NestedNullException(); } if (invokeResult instanceof java.util.Map) { return ((java.util.Map<?, ?>) invokeResult).get(key); } else throw new NoSuchFieldException("Field '" + name + "' is not mapped in '" + bean.getClass() + "'"); } // Retrieve the property descriptor for the specified property final PropertyDescriptor descriptor = getPropertyDescriptor(bean, trimAnnotations(name)); if (descriptor == null) { throw new NoSuchMethodException( "Unknown property '" + name + "'+ on bean class '" + bean.getClass() + "'"); } else if (descriptor instanceof MappedPropertyDescriptor) { // Call the keyed getter method if there is one Method readMethod = ((MappedPropertyDescriptor) descriptor).getMappedReadMethod(); readMethod = MethodUtils.getAccessibleMethod(bean.getClass(), readMethod); if (readMethod != null) { final Object[] keyArray = new Object[1]; keyArray[0] = key; result = invokeMethod(readMethod, bean, keyArray); } else { throw new NoSuchMethodException("Property '" + name + "' has no mapped getter method on bean class '" + bean.getClass() + "'"); } } else { /* means that the result has to be retrieved from a map */ final Method readMethod = getReadMethod(bean.getClass(), descriptor); if (readMethod != null) { final Object invokeResult = invokeMethod(readMethod, bean, EMPTY_OBJECT_ARRAY); /* test and fetch from the map */ if (invokeResult instanceof java.util.Map) { result = ((java.util.Map<?, ?>) invokeResult).get(key); } } else { throw new NoSuchMethodException("Property '" + name + "' has no mapped getter method on bean class '" + bean.getClass() + "'"); } } return result; }
From source file:org.jabsorb.ng.JSONRPCBridge.java
/** * Gets the methods that can be called on the given object * //from w ww .j av a 2 s .c o m * @param objectID * The id of the object or 0 if it is a class * @param className * The name of the class of the object - only required if * objectID==0 * @param methodName * The name of method in the request * @return A map of AccessibleObjectKeys to a Collection of * AccessibleObjects * @throws NoSuchMethodException * If the method cannot be found in the class */ private Map<AccessibleObjectKey, List<? extends AccessibleObject>> getAccessibleObjectMap(final int objectID, final String className, final String methodName) throws NoSuchMethodException { final Map<AccessibleObjectKey, List<? extends AccessibleObject>> methodMap = new HashMap<AccessibleObjectKey, List<? extends AccessibleObject>>(); // if it is not an object if (objectID == 0) { final ObjectInstance oi = resolveObject(className); final ClassData classData = resolveClass(className); // Look up the class, object instance and method objects if (oi != null) { methodMap.putAll(ClassAnalyzer.getClassData(oi.getClazz()).getMethodMap()); } // try to get the constructor data else if (methodName.equals(CONSTRUCTOR_FLAG)) { try { methodMap.putAll(ClassAnalyzer.getClassData(lookupClass(className)).getConstructorMap()); } catch (final Exception e) { throw new NoSuchMethodException(JSONRPCResult.MSG_ERR_NOCONSTRUCTOR); } } // else it must be static else if (classData != null) { methodMap.putAll(classData.getStaticMethodMap()); } else { throw new NoSuchMethodException(JSONRPCResult.MSG_ERR_NOMETHOD); } } // else it is an object, so we can get the member methods else { final ObjectInstance oi = resolveObject(new Integer(objectID)); if (oi == null) { throw new NoSuchMethodException(); } final ClassData cd = ClassAnalyzer.getClassData(oi.getClazz()); methodMap.putAll(cd.getMethodMap()); } return methodMap; }
From source file:org.jgentleframework.utils.ReflectUtils.java
/** * Tr v? <code>declared method</code> c support trong <code>clazz</code> * c ch nh da trn tn <code>name</code> v <code>paramTypes</code>. * Nu <code>class</code> hin ti khng support Method cn tm th s tm * trong <code>SuperClass</code> ca <code>class</code> c ch nh, nu * nh khng tn ti bt k <code>Method</code> no tng ng, mt ngoi l * {@link NoSuchMethodException} s c nm ra. * /* www .j a v a 2 s . com*/ * @param clazz * Class Object cn truy vn. * @param name * tn method cn truy vn. * @param paramTypes * mng array cc Class Object Type tham s truy?n ca method. * @return tr v? Method mun truy vn * @throws NoSuchMethodException * nm ra ngoi l ny nu nh khng tm thy bt k method no * tng ng c trong clazz hoc trong cc SuperClass ca n. */ public static Method getSupportedMethod(Class<?> clazz, String name, Class<?>[] paramTypes) throws NoSuchMethodException { if (clazz == null) { throw new NoSuchMethodException("Method '" + name + "' is not existed."); } try { return clazz.getDeclaredMethod(name, paramTypes); } catch (NoSuchMethodException ex) { return getSupportedMethod(clazz.getSuperclass(), name, paramTypes); } }
From source file:com.cyberway.issue.crawler.settings.ComplexType.java
public Object invoke(String arg0, Object[] arg1, String[] arg2) throws MBeanException, ReflectionException { throw new ReflectionException(new NoSuchMethodException("No methods to invoke.")); }
From source file:org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine.java
private Object invokeImpl(final Object thiz, final String name, final Object args[]) throws ScriptException, NoSuchMethodException { if (name == null) { throw new NullPointerException("Method name can not be null"); }/*from w w w . j a v a 2 s . c om*/ try { if (thiz != null) { return InvokerHelper.invokeMethod(thiz, name, args); } } catch (MissingMethodException mme) { throw new NoSuchMethodException(mme.getMessage()); } catch (Exception e) { throw new ScriptException(e); } return callGlobal(name, args); }
From source file:org.apache.tomcat.util.IntrospectionUtils.java
public static Object callMethod1(Object target, String methodN, Object param1, String typeParam1, ClassLoader cl) throws Exception { if (target == null || param1 == null) { d("Assert: Illegal params " + target + " " + param1); }/*from w ww .j ava 2 s. c o m*/ if (dbg > 0) d("callMethod1 " + target.getClass().getName() + " " + param1.getClass().getName() + " " + typeParam1); Class params[] = new Class[1]; if (typeParam1 == null) params[0] = param1.getClass(); else params[0] = cl.loadClass(typeParam1); Method m = findMethod(target.getClass(), methodN, params); if (m == null) throw new NoSuchMethodException(target.getClass().getName() + " " + methodN); return m.invoke(target, new Object[] { param1 }); }