本文整理匯總了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;
}