org.apache.commons.beanutils.MethodUtils Java Examples

The following examples show how to use org.apache.commons.beanutils.MethodUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExecutionPeriodsForExecutionYear.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public Object provide(Object source, Object currentValue) {

    ExecutionYear executionYear;
    try {
        executionYear = (ExecutionYear) MethodUtils.invokeMethod(source, "getExecutionYear", null);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    List<ExecutionSemester> periods = new ArrayList<ExecutionSemester>();
    if (executionYear != null) {
        periods.addAll(executionYear.getExecutionPeriodsSet());
    }

    return periods;
}
 
Example #2
Source File: ModuleConfiguration.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
 * This method is deprecated and won't do anything if the database repository file paths are null or empty.
 *
 * We use reflection here to avoid having to reference PersistenceService directly since it may or may not be on
 * our classpath depending on whether or not KSB is in use.
 */
@Deprecated
protected void loadOjbRepositoryFiles() {
    String persistenceServiceOjbName = "persistenceServiceOjb";
    if (getDatabaseRepositoryFilePaths() != null) {
        for (String repositoryLocation : getDatabaseRepositoryFilePaths()) {
            // Need the OJB persistence service because it is the only one ever using the database repository files
            if (getPersistenceService() == null) {
                setPersistenceService(GlobalResourceLoader.getService(persistenceServiceOjbName));
            }
            if (persistenceService == null) {
                setPersistenceService(applicationContext.getBean(persistenceServiceOjbName));
            }
            LOG.warn("Loading OJB Configuration in "
                    + getNamespaceCode()
                    + " module.  OJB is deprecated as of Rice 2.4: "
                    + repositoryLocation);
            try {
                MethodUtils.invokeExactMethod(persistenceService, "loadRepositoryDescriptor", repositoryLocation);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }

}
 
Example #3
Source File: StorageConverter.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Creates the FileSystemHandler and set all its properties.
 * Will also call the init method if it exists.
 */
private static FileSystemHandler getFileSystemHandler(Properties p, String fileSystemHandlerName) throws ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException{
    String clazz = p.getProperty(fileSystemHandlerName);
    log.info("Building FileSystemHandler: " + clazz);
    Class<? extends FileSystemHandler> fshClass = Class.forName(clazz).asSubclass(FileSystemHandler.class);
    FileSystemHandler fsh = fshClass.newInstance();

    Enumeration<String> propertyNames = (Enumeration<String>) p.propertyNames();
    while (propertyNames.hasMoreElements()) {
        String fullProperty = propertyNames.nextElement();
        if (fullProperty.startsWith(fileSystemHandlerName + ".")) {
            String property = fullProperty.substring(fullProperty.indexOf(".")+1);
            log.info("Setting property: " + property);
            BeanUtils.setProperty(fsh, property, p.getProperty(fullProperty));
        }
    }

    try {
        log.info("Check if there is a init method...");
        MethodUtils.invokeExactMethod(fsh, "init", (Object[])null);
        log.info("init method invoked...");
    } catch (NoSuchMethodException e) {
        log.info("No init method...");
    }
    log.info("Done with FileSystemHandler: " + clazz);
    return fsh;
}
 
Example #4
Source File: NavNodeTest.java    From spacewalk with GNU General Public License v2.0 5 votes vote down vote up
private void verifyBooleanSetterMethod(String methodname)
    throws Exception {
    Object[] args = { Boolean.TRUE };
    MethodUtils.invokeMethod(node, "set" + methodname, args);
    Boolean rc = (Boolean) MethodUtils.invokeMethod(node, "get" +
            methodname, null);
    assertTrue(rc.booleanValue());
}
 
Example #5
Source File: NavNodeTest.java    From spacewalk with GNU General Public License v2.0 5 votes vote down vote up
private void verifyStringSetterMethod(String methodname)
    throws Exception {
    Object[] args = { "value" };
    MethodUtils.invokeMethod(node, "set" + methodname, args);
    String rc = (String) MethodUtils.invokeMethod(node, "get" + methodname,
            null);
    assertEquals("value", rc);
}
 
Example #6
Source File: RiceUnitTestClassRunner.java    From rice with Educational Community License v2.0 5 votes vote down vote up
protected void setTestName(final Object test, final Method testMethod) throws Exception {
        String name = testMethod == null ? "" : testMethod.getName();
        final Method setNameMethod = MethodUtils.getAccessibleMethod(test.getClass(), "setName", new Class[]{String.class});
        if (setNameMethod != null) {
            setNameMethod.invoke(test, name);
        }
}
 
Example #7
Source File: LoadTimeWeavableTestRunner.java    From rice with Educational Community License v2.0 5 votes vote down vote up
protected void setTestName(final Object test, final Method testMethod) throws Exception {
    String name = testMethod == null ? "" : testMethod.getName();
    final Method setNameMethod = MethodUtils.getAccessibleMethod(test.getClass(), "setName",
            new Class[]{String.class});
    if (setNameMethod != null) {
        setNameMethod.invoke(test, name);
    }
}
 
Example #8
Source File: StorageConverter.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Creates the FileSystemHandler and set all its properties.
 * Will also call the init method if it exists.
 */
private static FileSystemHandler getFileSystemHandler(Properties p, String fileSystemHandlerName) throws ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException{
    String clazz = p.getProperty(fileSystemHandlerName);
    log.info("Building FileSystemHandler: " + clazz);
    Class<? extends FileSystemHandler> fshClass = Class.forName(clazz).asSubclass(FileSystemHandler.class);
    FileSystemHandler fsh = fshClass.newInstance();

    Enumeration<String> propertyNames = (Enumeration<String>) p.propertyNames();
    while (propertyNames.hasMoreElements()) {
        String fullProperty = propertyNames.nextElement();
        if (fullProperty.startsWith(fileSystemHandlerName + ".")) {
            String property = fullProperty.substring(fullProperty.indexOf(".")+1);
            log.info("Setting property: " + property);
            BeanUtils.setProperty(fsh, property, p.getProperty(fullProperty));
        }
    }

    try {
        log.info("Check if there is a init method...");
        MethodUtils.invokeExactMethod(fsh, "init", (Object[])null);
        log.info("init method invoked...");
    } catch (NoSuchMethodException e) {
        log.info("No init method...");
    }
    log.info("Done with FileSystemHandler: " + clazz);
    return fsh;
}
 
Example #9
Source File: StorageConverter.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Calls the objects destroy method is it exists.
 */
private static void destroy(Object o) throws IllegalAccessException, InvocationTargetException {
    if (o == null) return;
    log.info("Destroying " + o + "...");
    try {
        log.info("Check if there is a destroy method...");
        MethodUtils.invokeExactMethod(o, "destroy", (Object[])null);
        log.info("destroy method invoked...");
    } catch (NoSuchMethodException e) {
        log.info("No destroy method...");
    }
}
 
Example #10
Source File: JpaUtil.java    From javaee-lab with Apache License 2.0 5 votes vote down vote up
public <T> boolean isPk(ManagedType<T> mt, SingularAttribute<? super T, ?> attr) {
    try {
        Method m = MethodUtils.getAccessibleMethod(mt.getJavaType(), "get" + WordUtils.capitalize(attr.getName()), (Class<?>) null);
        if (m != null && m.getAnnotation(Id.class) != null) {
            return true;
        }

        Field field = mt.getJavaType().getField(attr.getName());
        return field.getAnnotation(Id.class) != null;
    } catch (Exception e) {
        return false;
    }
}
 
Example #11
Source File: NavNodeTest.java    From uyuni with GNU General Public License v2.0 5 votes vote down vote up
private void verifyStringSetterMethod(String methodname)
    throws Exception {
    Object[] args = { "value" };
    MethodUtils.invokeMethod(node, "set" + methodname, args);
    String rc = (String) MethodUtils.invokeMethod(node, "get" + methodname,
            null);
    assertEquals("value", rc);
}
 
Example #12
Source File: StorageConverter.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Calls the objects destroy method is it exists.
 */
private static void destroy(Object o) throws IllegalAccessException, InvocationTargetException {
    if (o == null) return;
    log.info("Destroying " + o + "...");
    try {
        log.info("Check if there is a destroy method...");
        MethodUtils.invokeExactMethod(o, "destroy", (Object[])null);
        log.info("destroy method invoked...");
    } catch (NoSuchMethodException e) {
        log.info("No destroy method...");
    }
}
 
Example #13
Source File: ModelColumnPluginTest.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * 测试excludes
 */
@Test
public void testExcludes() throws Exception {
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/ModelColumnPlugin/mybatis-generator-with-SeleciveEnhancedPlugin.xml");
    tool.generate(new AbstractShellCallback() {
        @Override
        public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
            ObjectUtil tbMapper = new ObjectUtil(sqlSession.getMapper(loader.loadClass(packagz + ".TbMapper")));

            ObjectUtil tb = new ObjectUtil(loader, packagz + ".Tb");
            tb.set("id", 121L);
            tb.set("incF3", 10L);
            tb.set("tsIncF2", 5L);
            // selective
            ObjectUtil TbColumnId = new ObjectUtil(loader, packagz + ".Tb$Column#id");
            ObjectUtil TbColumnField1 = new ObjectUtil(loader, packagz + ".Tb$Column#field1");
            ObjectUtil TbColumnTsIncF2 = new ObjectUtil(loader, packagz + ".Tb$Column#tsIncF2");
            Object columns = Array.newInstance(TbColumnField1.getCls(), 3);
            Array.set(columns, 0, TbColumnId.getObject());
            Array.set(columns, 1, TbColumnField1.getObject());
            Array.set(columns, 2, TbColumnTsIncF2.getObject());

            // sql(指定列)
            String sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "insertSelective", tb.getObject(), columns);
            Assert.assertEquals(sql, "insert into tb ( id , field_1 , inc_f2 ) values ( 121 , 'null' , 5 )");

            // sql(排除列)
            columns = MethodUtils.invokeStaticMethod(Class.forName(packagz + ".Tb$Column"), "excludes", columns);
            sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "insertSelective", tb.getObject(), columns);
            Assert.assertEquals(sql, "insert into tb ( inc_f1 , inc_f3 ) values ( null , 10 )");

            Object result = tbMapper.invoke("insertSelective", tb.getObject(), columns);
            Assert.assertEquals(result, 1);
        }
    });
}
 
Example #14
Source File: LoaderFromClass.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Find a method on the specified class whose name matches methodName,
 * and whose signature is:
 * <code> public static void foo(Digester d, String patternPrefix);</code>.
 *
 * @return null if no such method exists.
 */
public static Method locateMethod(Class<?> rulesClass, String methodName) 
                        throws PluginException {

    Class<?>[] paramSpec = { Digester.class, String.class };
    Method rulesMethod = MethodUtils.getAccessibleMethod(
        rulesClass, methodName, paramSpec);
        
    return rulesMethod;
}
 
Example #15
Source File: AnnotationUtils.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invokes an annotation method.
 *
 * @param annotationn the annotation has to be introspected.
 * @param method the method name to execute.
 * @return the annotation method value, null if any error occurs.
 */
private static Object invokeAnnotationMethod(Annotation annotation, String method) {
    try {
        return MethodUtils.invokeExactMethod(annotation, method, null);
    } catch (Throwable t) {
        return null;
    }
}
 
Example #16
Source File: SetNextRule.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Process the end of this element.
 */
@Override
public void end() throws Exception {

    // Identify the objects to be used
    Object child = digester.peek(0);
    Object parent = digester.peek(1);
    if (digester.log.isDebugEnabled()) {
        if (parent == null) {
            digester.log.debug("[SetNextRule]{" + digester.match +
                    "} Call [NULL PARENT]." +
                    methodName + "(" + child + ")");
        } else {
            digester.log.debug("[SetNextRule]{" + digester.match +
                    "} Call " + parent.getClass().getName() + "." +
                    methodName + "(" + child + ")");
        }
    }

    // Call the specified method
    Class<?> paramTypes[] = new Class<?>[1];
    if (paramType != null) {
        paramTypes[0] =
                digester.getClassLoader().loadClass(paramType);
    } else {
        paramTypes[0] = child.getClass();
    }
    
    if (useExactMatch) {
    
        MethodUtils.invokeExactMethod(parent, methodName,
            new Object[]{ child }, paramTypes);
            
    } else {
    
        MethodUtils.invokeMethod(parent, methodName,
            new Object[]{ child }, paramTypes);
    
    }
}
 
Example #17
Source File: SetRootRule.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Process the end of this element.
 */
@Override
public void end() throws Exception {

    // Identify the objects to be used
    Object child = digester.peek(0);
    Object parent = digester.root;
    if (digester.log.isDebugEnabled()) {
        if (parent == null) {
            digester.log.debug("[SetRootRule]{" + digester.match +
                    "} Call [NULL ROOT]." +
                    methodName + "(" + child + ")");
        } else {
            digester.log.debug("[SetRootRule]{" + digester.match +
                    "} Call " + parent.getClass().getName() + "." +
                    methodName + "(" + child + ")");
        }
    }

    // Call the specified method
    Class<?> paramTypes[] = new Class<?>[1];
    if (paramType != null) {
        paramTypes[0] =
                digester.getClassLoader().loadClass(paramType);
    } else {
        paramTypes[0] = child.getClass();
    }
    
    if (useExactMatch) {
    
        MethodUtils.invokeExactMethod(parent, methodName,
            new Object[]{ child }, paramTypes);
            
    } else {
    
        MethodUtils.invokeMethod(parent, methodName,
            new Object[]{ child }, paramTypes);
    
    }
}
 
Example #18
Source File: RpcServiceClient.java    From jigsaw-payment with Apache License 2.0 5 votes vote down vote up
/**
 * 将protobuf字节流转换为对应的message对象。
 *
 * @param messageClass
 * @return
 */
@SuppressWarnings("unchecked")
protected <T extends Message> T parseFrom(Class<T> messageClass, byte[] bytes) throws SystemException {
	T message = null;
	try {
		message = (T) MethodUtils.invokeStaticMethod(messageClass, "parseFrom", bytes);
	} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
		SystemException ex = new SystemException();
		ex.setErrorCode(500);
		ex.setMessage(e.getMessage());
		throw ex;
	}
	return message;
}
 
Example #19
Source File: TopicRule.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
@Override
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
public void end(final String namespace, final String name) throws Exception {
    Element subsection = getDigester().pop();
    String description = extractNodeContent(subsection);

    MethodUtils.invokeExactMethod(getDigester().peek(), "setValue", description);
}
 
Example #20
Source File: NavNodeTest.java    From uyuni with GNU General Public License v2.0 5 votes vote down vote up
private void verifyBooleanSetterMethod(String methodname)
    throws Exception {
    Object[] args = { Boolean.TRUE };
    MethodUtils.invokeMethod(node, "set" + methodname, args);
    Boolean rc = (Boolean) MethodUtils.invokeMethod(node, "get" +
            methodname, null);
    assertTrue(rc.booleanValue());
}
 
Example #21
Source File: ModelColumnPluginTest.java    From mybatis-generator-plugin with Apache License 2.0 4 votes vote down vote up
/**
 * 测试生成的model
 */
@Test
public void testModel() throws Exception {
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/ModelColumnPlugin/mybatis-generator.xml");
    tool.generate(new AbstractShellCallback() {
        @Override
        public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
            // 1. 普通model
            ObjectUtil TbColumnField1 = new ObjectUtil(loader, packagz + ".Tb$Column#field1");
            Assert.assertEquals(TbColumnField1.invoke("value"), "field_1");
            Assert.assertEquals(TbColumnField1.invoke("getValue"), "field_1");
            Assert.assertEquals(TbColumnField1.invoke("asc"), "field_1 ASC");
            Assert.assertEquals(TbColumnField1.invoke("desc"), "field_1 DESC");

            // 2. columnOverride
            ObjectUtil TbColumnTsIncF2 = new ObjectUtil(loader, packagz + ".Tb$Column#tsIncF2");
            Assert.assertEquals(TbColumnTsIncF2.invoke("value"), "inc_f2");

            // 3. withBlobs
            ObjectUtil TbBlobsColumnField1 = new ObjectUtil(loader, packagz + ".TbBlobs$Column#field1");
            Assert.assertEquals(TbBlobsColumnField1.invoke("value"), "field_1");
            ObjectUtil TbBlobsWithBLOBsColumnField2 = new ObjectUtil(loader, packagz + ".TbBlobsWithBLOBs$Column#field2");
            Assert.assertEquals(TbBlobsWithBLOBsColumnField2.invoke("value"), "field_2");

            // 4. key
            ObjectUtil TbKeysKeyColumnKey1 = new ObjectUtil(loader, packagz + ".TbKeysKey$Column#key1");
            Assert.assertEquals(TbKeysKeyColumnKey1.invoke("value"), "key_1");
            ObjectUtil TbKeysColumnKey1 = new ObjectUtil(loader, packagz + ".TbKeys$Column#key1");
            Assert.assertEquals(TbKeysColumnKey1.invoke("value"), "key_1");
            ObjectUtil TbKeysColumnField1 = new ObjectUtil(loader, packagz + ".TbKeys$Column#field1");
            Assert.assertEquals(TbKeysColumnField1.invoke("value"), "field_1");

            // 5. excludes 方法
            // 不排除
            Object columns = Array.newInstance(TbColumnField1.getCls(), 0);
            Object[] result = (Object[])(MethodUtils.invokeStaticMethod(Class.forName(packagz + ".Tb$Column"), "excludes", columns));
            Assert.assertEquals(result.length, 5);
            // 排除两个
            columns = Array.newInstance(TbColumnField1.getCls(), 2);
            Array.set(columns, 0, TbColumnField1.getObject());
            Array.set(columns, 1, TbColumnTsIncF2.getObject());
            result = (Object[])(MethodUtils.invokeStaticMethod(Class.forName(packagz + ".Tb$Column"), "excludes", columns));
            Assert.assertEquals(result.length, 3);
            for (Object obj : result){
                ObjectUtil column = new ObjectUtil(obj);
                if (column.invoke("value").equals("field_1") || column.invoke("value").equals("inc_f2")){
                    Assert.assertTrue(false);
                }
            }

            // 6. all 方法
            result = (Object[])(MethodUtils.invokeStaticMethod(Class.forName(packagz + ".Tb$Column"), "all", null));
            Assert.assertEquals(result.length, 5);
        }
    });
}
 
Example #22
Source File: XmlGatewayDescriptorRules.java    From knox with Apache License 2.0 4 votes vote down vote up
@Override
public void begin( String namespace, String name, Attributes attributes ) throws Exception {
  Digester digester = getDigester();
  digester.push( MethodUtils.invokeMethod( digester.peek(), method, NO_PARAMS ) );
}
 
Example #23
Source File: ContentProviderRegistry.java    From eclipsegraphviz with Eclipse Public License 1.0 4 votes vote down vote up
private Method getReaderMethod(Object reader, Class<?> sourceType) {
    Method method = MethodUtils.getMatchingAccessibleMethod(reader.getClass(), "read",
            new Class[] { sourceType });
    return method == null || method.getReturnType() == Void.class ? null : method;
}
 
Example #24
Source File: SetTopRule.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Process the end of this element.
 */
@Override
public void end() throws Exception {

    // Identify the objects to be used
    Object child = digester.peek(0);
    Object parent = digester.peek(1);
    
    if (digester.log.isDebugEnabled()) {
        if (child == null) {
            digester.log.debug("[SetTopRule]{" + digester.match +
                    "} Call [NULL CHILD]." +
                    methodName + "(" + parent + ")");
        } else {
            digester.log.debug("[SetTopRule]{" + digester.match +
                    "} Call " + child.getClass().getName() + "." +
                    methodName + "(" + parent + ")");
        }
    }

    // Call the specified method
    Class<?> paramTypes[] = new Class<?>[1];
    if (paramType != null) {
        paramTypes[0] =
                digester.getClassLoader().loadClass(paramType);
    } else {
        paramTypes[0] = parent.getClass();
    }

    if (useExactMatch) {
    
        MethodUtils.invokeExactMethod(child, methodName,
            new Object[]{ parent }, paramTypes);
            
    } else {
    
        MethodUtils.invokeMethod(child, methodName,
            new Object[]{ parent }, paramTypes);
    
    }
}
 
Example #25
Source File: CreateSample.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
public void test() throws Exception {
	List<Class<?>> classes = new ArrayList<Class<?>>();
	classes.add(AppStyle.class);
	classes.add(CenterServer.class);
	classes.add(Collect.class);
	classes.add(Dingding.class);
	classes.add(DumpRestoreData.class);
	classes.add(DumpRestoreStorage.class);
	classes.add(LogLevel.class);
	classes.add(Meeting.class);
	classes.add(Messages.class);
	classes.add(Node.class);
	classes.add(Person.class);
	classes.add(ProcessPlatform.class);
	classes.add(Qiyeweixin.class);
	classes.add(Query.class);
	classes.add(Token.class);
	classes.add(Vfs.class);
	classes.add(WorkTime.class);
	classes.add(ZhengwuDingding.class);
	classes.add(ExternalDataSource.class);
	classes.add(ExternalStorageSource.class);

	Collections.sort(classes, new Comparator<Class<?>>() {
		public int compare(Class<?> c1, Class<?> c2) {
			return c1.getCanonicalName().compareTo(c2.getCanonicalName());
		}
	});
	for (Class<?> cls : classes) {
		Object o = MethodUtils.invokeStaticMethod(cls, "defaultInstance", null);
		Map<String, Object> map = new LinkedHashMap<String, Object>();
		map = XGsonBuilder.convert(o, map.getClass());
		map = this.describe(cls, map);
		String name = StringUtils.lowerCase(cls.getSimpleName().substring(0, 1)) + cls.getSimpleName().substring(1)
				+ ".json";
		File file = new File(FileTools.parent(FileTools.parent(new File("./"))), "configSample/" + name);
		logger.print("create file:{}.", file.getAbsoluteFile());
		FileUtils.write(file, XGsonBuilder.toJson(map), DefaultCharset.charset);
	}
	this.convertExternalDataSource2ExternalDataSources();
	this.convertExternalStorageSource2ExternalStorageSources();
	this.renameNode();

}
 
Example #26
Source File: Beans.java    From components with Apache License 2.0 2 votes vote down vote up
/**
 * <p>Return an accessible property getter method for this property,
 * if there is one; otherwise return <code>null</code>.</p>
 *
 * @param clazz The class of the read method will be invoked on
 * @param descriptor Property descriptor to return a getter for
 * @return The read method
 */
Method getReadMethod(Class clazz, PropertyInfo descriptor) {
    return (MethodUtils.getAccessibleMethod(clazz, descriptor.getReadMethodName(), EMPTY_CLASS_PARAMETERS));
}
 
Example #27
Source File: Beans.java    From components with Apache License 2.0 2 votes vote down vote up
/**
 * <p>Return an accessible property setter method for this property,
 * if there is one; otherwise return <code>null</code>.</p>
 *
 * @param clazz The class of the read method will be invoked on
 * @param descriptor Property descriptor to return a setter for
 * @return The write method
 */
Method getWriteMethod(Class clazz, PropertyInfo descriptor) {
    return (MethodUtils.getAccessibleMethod(clazz, descriptor.getWriteMethodName(),
            new Class[]{descriptor.getWriteType()}));
}