List of usage examples for java.beans MethodDescriptor getMethod
public synchronized Method getMethod()
From source file:org.psnively.scala.beans.ScalaBeanInfo.java
private static PropertyDescriptor[] initPropertyDescriptors(BeanInfo beanInfo) { Map<String, PropertyDescriptor> propertyDescriptors = new TreeMap<String, PropertyDescriptor>( new PropertyNameComparator()); for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) { propertyDescriptors.put(pd.getName(), pd); }//from w w w .ja v a 2 s.c o m for (MethodDescriptor md : beanInfo.getMethodDescriptors()) { Method method = md.getMethod(); if (ReflectionUtils.isObjectMethod(method)) { continue; } if (isScalaSetter(method)) { addScalaSetter(propertyDescriptors, method); } else if (isScalaGetter(method)) { addScalaGetter(propertyDescriptors, method); } } return propertyDescriptors.values().toArray(new PropertyDescriptor[propertyDescriptors.size()]); }
From source file:org.mwc.debrief.editable.test.EditableTests.java
/** * test helper, to check that all of the object property getters/setters are * there// www .ja va 2s . co m * * @param toBeTested */ public static void testTheseParameters(final Editable toBeTested) { // check if we received an object System.out.println("testing " + toBeTested.getClass()); if (toBeTested == null) return; Assert.assertNotNull("Found editable object", toBeTested); final Editable.EditorType et = toBeTested.getInfo(); if (et == null) { Assert.fail("no editor type returned for"); return; } // first see if we return a custom bean descriptor final BeanDescriptor desc = et.getBeanDescriptor(); // did we get one? if (desc != null) { final Class<?> editorClass = desc.getCustomizerClass(); if (editorClass != null) { Object newInstance = null; try { newInstance = editorClass.newInstance(); } catch (final InstantiationException e) { e.printStackTrace(); // To change body of catch statement use File // | Settings | File Templates. } catch (final IllegalAccessException e) { e.printStackTrace(); // To change body of catch statement use File // | Settings | File Templates. } // check it worked Assert.assertNotNull("we didn't create the custom editor for:", newInstance); } else { // there isn't a dedicated editor, try the custom ones. // do the edits PropertyDescriptor[] pd = null; try { pd = et.getPropertyDescriptors(); } catch (Exception e) { org.mwc.debrief.editable.test.Activator.log(e); Assert.fail("problem fetching property editors for " + toBeTested.getClass()); } if (pd == null) { Assert.fail("problem fetching property editors for " + toBeTested.getClass()); return; } final int len = pd.length; if (len == 0) { System.out.println( "zero property editors found for " + toBeTested + ", " + toBeTested.getClass()); return; } // griddable property descriptors if (et instanceof Griddable) { pd = null; try { pd = ((Griddable) et).getGriddablePropertyDescriptors(); } catch (Exception e) { org.mwc.debrief.editable.test.Activator.log(e); Assert.fail("problem fetching griddable property editors for " + toBeTested.getClass()); } if (pd == null) { Assert.fail("problem fetching griddable property editors for " + toBeTested.getClass()); return; } } // the method names are checked when creating PropertyDescriptor // we haven't to test them } // whether there was a customizer class } // whether there was a custom bean descriptor // now try out the methods final MethodDescriptor[] methods = et.getMethodDescriptors(); if (methods != null) { for (int thisM = 0; thisM < methods.length; thisM++) { final MethodDescriptor method = methods[thisM]; final Method thisOne = method.getMethod(); final String theName = thisOne.getName(); Assert.assertNotNull(theName); } } }
From source file:com.reignite.messaging.server.SpringInitializedDestination.java
@Override public void afterPropertiesSet() throws Exception { if (target != null) { // introspect and cache methods BeanInfo info = Introspector.getBeanInfo(target.getClass(), Object.class); MethodDescriptor[] meths = info.getMethodDescriptors(); for (MethodDescriptor meth : meths) { Method method = meth.getMethod(); List<Method> methods = methodMap.get(method.getName()); if (methods == null) { methods = new ArrayList<Method>(); methodMap.put(method.getName(), methods); }/*from www .jav a 2 s. c o m*/ methods.add(method); } } initialized = true; }
From source file:com.interface21.beans.BeanWrapperImpl.java
public Object invoke(String methodName, Object[] args) throws BeansException { try {//from ww w . j a va 2s . com MethodDescriptor md = this.cachedIntrospectionResults.getMethodDescriptor(methodName); if (logger.isDebugEnabled()) logger.debug("About to invoke method [" + methodName + "]"); Object returnVal = md.getMethod().invoke(this.object, args); if (logger.isDebugEnabled()) logger.debug("Successfully invoked method [" + methodName + "]"); return returnVal; } catch (InvocationTargetException ex) { //if (ex.getTargetException() instanceof ClassCastException) // throw new TypeMismatchException(propertyChangeEvent, pd.getPropertyType(), ex); throw new MethodInvocationException(ex.getTargetException(), methodName); } catch (IllegalAccessException ex) { throw new FatalBeanException("Illegal attempt to invoke method [" + methodName + "] threw exception", ex); } catch (IllegalArgumentException ex) { throw new FatalBeanException("Illegal argument to method [" + methodName + "] threw exception", ex); } }
From source file:net.yasion.common.core.bean.wrapper.ExtendedBeanInfo.java
private List<Method> findCandidateWriteMethods(MethodDescriptor[] methodDescriptors) { List<Method> matches = new ArrayList<Method>(); for (MethodDescriptor methodDescriptor : methodDescriptors) { Method method = methodDescriptor.getMethod(); if (isCandidateWriteMethod(method)) { matches.add(method);// w ww . j a v a 2 s .c om } } // Sort non-void returning write methods to guard against the ill effects of // non-deterministic sorting of methods returned from Class#getDeclaredMethods // under JDK 7. See http://bugs.sun.com/view_bug.do?bug_id=7023180 Collections.sort(matches, new Comparator<Method>() { @Override public int compare(Method m1, Method m2) { return m2.toString().compareTo(m1.toString()); } }); return matches; }
From source file:org.rhq.bindings.ScriptEngineFactory.java
/** * Goes through the methods of the object found in the <code>scriptEngine</code>'s ENGINE_SCOPE * and for each of them generates a top-level function that is called the same name and accepts the same * parameters.//from www . java 2 s .c om * * @param scriptEngine the script engine to generate the top-level functions in * @param bindingName the name of the object in the script engine to generate the functions from * * @see ScriptEngineInitializer#generateIndirectionMethod(String, Method) * @see NoTopLevelIndirection */ public static void bindIndirectionMethods(ScriptEngine scriptEngine, String bindingName) { Object object = scriptEngine.get(bindingName); if (object == null) { LOG.debug("The script engine doesn't contain a binding called '" + bindingName + "'. No indirection functions will be generated."); return; } ScriptEngineInitializer initializer = getInitializer(scriptEngine.getFactory().getLanguageName()); try { BeanInfo beanInfo = Introspector.getBeanInfo(object.getClass(), Object.class); MethodDescriptor[] methodDescriptors = beanInfo.getMethodDescriptors(); Map<String, Set<Method>> overloadsPerMethodName = new HashMap<String, Set<Method>>(); for (MethodDescriptor methodDescriptor : methodDescriptors) { Method method = methodDescriptor.getMethod(); if (shouldIndirect(method)) { Set<Method> overloads = overloadsPerMethodName.get(method.getName()); if (overloads == null) { overloads = new HashSet<Method>(); overloadsPerMethodName.put(method.getName(), overloads); } overloads.add(method); } } for (Set<Method> overloads : overloadsPerMethodName.values()) { Set<String> methodDefs = initializer.generateIndirectionMethods(bindingName, overloads); for (String methodDef : methodDefs) { try { scriptEngine.eval(methodDef); } catch (ScriptException e) { LOG.warn("Unable to define global function declared as:\n" + methodDef, e); } } } } catch (IntrospectionException e) { LOG.debug("Could not inspect class " + object.getClass().getName() + ". No indirection methods for variable '" + bindingName + "' will be generated.", e); } }
From source file:org.springframework.beans.ExtendedBeanInfo.java
private List<Method> findCandidateWriteMethods(MethodDescriptor[] methodDescriptors) { List<Method> matches = new ArrayList<>(); for (MethodDescriptor methodDescriptor : methodDescriptors) { Method method = methodDescriptor.getMethod(); if (isCandidateWriteMethod(method)) { matches.add(method);//w ww . ja va2s. co m } } // Sort non-void returning write methods to guard against the ill effects of // non-deterministic sorting of methods returned from Class#getDeclaredMethods // under JDK 7. See http://bugs.sun.com/view_bug.do?bug_id=7023180 matches.sort((m1, m2) -> m2.toString().compareTo(m1.toString())); return matches; }