/** * Gets the named method with a method signature matching classTypes from the given insance * and returns it as an object. * @param instance the object instance * @param methodName the method name * @param classTypes the method argument types */ public static Method getMethod(Object instance, String methodName, Class[] classTypes) throws NoSuchMethodException { Method accessMethod = getMethod(instance.getClass(), methodName, classTypes); accessMethod.setAccessible(true); return accessMethod; }
/** * Return the named method with a method signature matching classTypes from the given class. * @param thisClass the class containing the method * @param methodName the name of the method * @param classTypes the method argument types */ public static Method getMethod(Class thisClass, String methodName, Class[] classTypes) throws NoSuchMethodException { if (thisClass == null) throw new NoSuchMethodException("Invalid method : " + methodName); try { return thisClass.getDeclaredMethod(methodName, classTypes); } catch (NoSuchMethodException e) { return getMethod(thisClass.getSuperclass(), methodName, classTypes); } }
/** * Sets values according to the selected product. */ private void processSelectedProducts(int productId, String propertyName) { DefaultIOParametersPanel ioParametersPanel = getDefaultIOParametersPanel(); List<SourceProductSelector> sourceProductSelectorList = ioParametersPanel.getSourceProductSelectorList(); Product selectedProduct = sourceProductSelectorList.get(productId).getSelectedProduct(); try { if (selectedProduct != null) { //String bands = String.join(",", selectedProduct.getBandGroup().getNodeNames()); BindingContext bindingContext = getBindingContext(); PropertySet propertySet = bindingContext.getPropertySet(); //PrivilegedAccessor.invokeMethod((DefaultSingleTargetProductDialog)this, "updateValueSet", new Object[]{selectedProduct, propertySet.getDescriptor(propertyName)}); Method m = PrivilegedAccessor.getMethod((DefaultSingleTargetProductDialog) this, "updateValueSet", new Class[]{PropertyDescriptor.class, Product.class}); m.invoke(null, new Object[]{propertySet.getDescriptor(propertyName), selectedProduct}); //propertySet.getDescriptor(propertyName)//.getDescriptor().setValueSet(ValueSet.parseValueSet(bands, String.class)); } } catch (Exception ex) { throw new OperatorException("Could not update band list as parameter: " + ex.getMessage()); } //update also the target product name according to slave if (productId != SLAVE_PRODUCT_ID) { selectedProduct = sourceProductSelectorList.get(SLAVE_PRODUCT_ID).getSelectedProduct(); } if (selectedProduct != null) { TargetProductSelectorModel targetProductSelectorModel = getTargetProductSelector().getModel(); targetProductSelectorModel.setProductName(selectedProduct.getName() + getTargetProductNameSuffix()); } }
Method m = PrivilegedAccessor.getMethod((DefaultSingleTargetProductDialog) this, "updateValueSet", new Class[]{PropertyDescriptor.class, Product.class});