本文整理汇总了Java中org.apache.commons.lang3.reflect.MethodUtils.invokeExactMethod方法的典型用法代码示例。如果您正苦于以下问题:Java MethodUtils.invokeExactMethod方法的具体用法?Java MethodUtils.invokeExactMethod怎么用?Java MethodUtils.invokeExactMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang3.reflect.MethodUtils
的用法示例。
在下文中一共展示了MethodUtils.invokeExactMethod方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: formatObjectGraph
import org.apache.commons.lang3.reflect.MethodUtils; //导入方法依赖的package包/类
@Override
public String formatObjectGraph(Object graph) throws ReflectiveOperationException, ClassCastException {
StringBuilder out = new StringBuilder();
Enumeration attrs = (Enumeration) MethodUtils.invokeExactMethod(graph, "getAttributeNames");
@SuppressWarnings("unchecked")
ArrayList<String> attrList = Collections.list(attrs);
Collections.sort(attrList);
out.append("{");
int size = attrList.size();
for (int i = 0; i < size; i++) {
String attrName = attrList.get(i);
Object attrValue = MethodUtils.invokeExactMethod(graph, "getAttribute", attrName);
out.append(attrName);
out.append('=');
out.append(attrValue);
if (i != size - 1) {
out.append(",\n\n");
}
}
out.append("}");
return out.toString();
}
示例2: addItemToCollection
import org.apache.commons.lang3.reflect.MethodUtils; //导入方法依赖的package包/类
private void addItemToCollection(Object object, String fieldName, Object value)
throws IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
Object collection = null;
try {
collection = FieldUtils.readField(object, fieldName);
if (!(collection instanceof Collection)) {
collection = null;
}
} catch (Exception e) {
// Do nothing -> just using this to check if we have to use the field or the addXxxx() method
}
if (collection != null) {
MethodUtils.invokeExactMethod(collection, "add", new Object[]{value}, new Class[]{Object.class});
} else {
MethodUtils.invokeExactMethod(object, "add" + StringUtils.capitalize(fieldName), value);
}
}
示例3: saveEntity
import org.apache.commons.lang3.reflect.MethodUtils; //导入方法依赖的package包/类
/**
* @param dbEntities
* @param aEntity
* @throws SdiException
*/
private void saveEntity( List<Object> dbEntities, Object aEntity ) throws SdiException
{
if ( myDryRun )
{
myLog.trace( "DryRun: Going to save entity: " + aEntity );
try
{
MethodUtils.invokeExactMethod( aEntity, "setId", new Object[] { Long.valueOf( myDummyId ) } );
}
catch ( Throwable t )
{
throw new SdiException( "Entity has no 'setId( Long )' method", t, SdiException.EXIT_CODE_UNKNOWN_ERROR );
}
myDummyId++;
}
else
{
myLog.trace( "Going to save entity: " + aEntity );
myEntityManager.persist( aEntity );
} // if..else myDryRun
dbEntities.add( aEntity );
}
示例4: getter
import org.apache.commons.lang3.reflect.MethodUtils; //导入方法依赖的package包/类
/**
* Get property value from an object with the getter method.
*
* @param object the object where the property live in
* @param fieldName property name
* @return property value. {@code null} if the common java bean accessor method has tried.
*/
public static Object getter(final Object object,String fieldName){
Object property = null;
StringBuilder s = new StringBuilder("get");
s.append(StringUtils.capitalize(fieldName));
try{
property = MethodUtils.invokeExactMethod(object,s.toString());
}catch (Exception e){
//try with isXXX
StringBuilder s2 = new StringBuilder("is");
s2.append(StringUtils.capitalize(fieldName));
try{
property = MethodUtils.invokeExactMethod(object,s2.toString());
}catch (Exception ee){
LOG.error("Exception",ee);
}
}
return property;
}
示例5: validate
import org.apache.commons.lang3.reflect.MethodUtils; //导入方法依赖的package包/类
@Override
public T validate(String input) {
Object result = null;
V validator = getValidator();
try {
result = (Boolean) MethodUtils.invokeExactMethod(
validator, VALIDATE_METHOD_NAME, input);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
Logger.getLogger(AbstractFormValidator.class.getName()).log(Level.SEVERE, null, ex);
}
if (result != null) {
return (T) result;
}
return null;
}
示例6: invokeSingleCommand
import org.apache.commons.lang3.reflect.MethodUtils; //导入方法依赖的package包/类
private void invokeSingleCommand(Command command) {
try {
MethodUtils.invokeExactMethod(commandService, "handle", command);
}
catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
示例7: formatObjectGraph
import org.apache.commons.lang3.reflect.MethodUtils; //导入方法依赖的package包/类
@Override
public String formatObjectGraph(Object graph) throws ReflectiveOperationException, ClassCastException {
Enumeration attrs = (Enumeration) MethodUtils.invokeExactMethod(graph, "getAttributeNames");
ArrayList attrList = Collections.list(attrs);
Collections.sort(attrList);
return attrList.toString();
}
示例8: value
import org.apache.commons.lang3.reflect.MethodUtils; //导入方法依赖的package包/类
/** Calls the value() method of the given enum. */
public static <E extends Enum<E>> String value(E type) /*throws NoSuchMethodException, IllegalAccessException, InvocationTargetException*/ {
try {
return (String) MethodUtils.invokeExactMethod(type, "value",
new Object[]{});
} catch (Exception e) {
return null;
}
}
示例9: getStr
import org.apache.commons.lang3.reflect.MethodUtils; //导入方法依赖的package包/类
public static <E extends Enum<E>> String getStr(E type) /*throws NoSuchMethodException, IllegalAccessException, InvocationTargetException*/ {
try {
return (String) MethodUtils.invokeExactMethod(type, "getStr",
new Object[]{});
} catch (Exception e) {
return null;
}
}
示例10: isValid
import org.apache.commons.lang3.reflect.MethodUtils; //导入方法依赖的package包/类
@Override
public boolean isValid(String input) {
Boolean result = Boolean.FALSE;
V validator = getValidator();
try {
result = (Boolean) MethodUtils.invokeExactMethod(
validator, IS_VALID_METHOD_NAME, input);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
Logger.getLogger(AbstractFormValidator.class.getName()).log(Level.SEVERE, null, ex);
}
return result;
}