當前位置: 首頁>>代碼示例>>Java>>正文


Java MethodUtils.invokeMethod方法代碼示例

本文整理匯總了Java中org.apache.commons.beanutils.MethodUtils.invokeMethod方法的典型用法代碼示例。如果您正苦於以下問題:Java MethodUtils.invokeMethod方法的具體用法?Java MethodUtils.invokeMethod怎麽用?Java MethodUtils.invokeMethod使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.beanutils.MethodUtils的用法示例。


在下文中一共展示了MethodUtils.invokeMethod方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: toMap

import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
/**
 * 將一個JavaBean對象的所有屬性封裝在Map中並返回,
 * 注意隻能將擁有Getter方法的屬性才能取出並封裝到Map中
 *
 * @param bean 需要轉換的Bean對象
 * @return 返回一個Map , 失敗返回null
 */
public static <T extends Object> Map<String, Object> toMap(T bean) {
    Map<String, Object> map = null;
    try {
        map = PropertyUtils.describe(bean);
        map.remove("class");
        StringBuilder methodName = new StringBuilder("get");
        for (String property : map.keySet()) {
            methodName.delete(3, methodName.length()).append(property.substring(0, 1).toUpperCase())
                    .append(property.substring(1));
            Object o = MethodUtils.invokeMethod(bean, methodName.toString(), null);
            map.put(property, o);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return map;
}
 
開發者ID:FlyingHe,項目名稱:UtilsMaven,代碼行數:25,代碼來源:CommonUtils.java

示例2: execute

import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
public void execute(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
	response.setCharacterEncoding("UTF-8");
	response.setContentType("text/xml;charset=utf8");
	PrintWriter pw = response.getWriter();
	String beanId = (String) request.getParameter("beanId");
	String methodName = (String) request.getParameter("methodName");
	String parameter = (String) request.getParameter("parameter");
	if (StringUtils.isNotEmpty(beanId) && StringUtils.isNotEmpty(methodName)) {
		try {
			Object object = DoradoContext.getAttachedWebApplicationContext().getBean(beanId);
			Object[] arguments = null;
			if (StringUtils.isNotEmpty(parameter)) {
				arguments = (Object[]) SerializationUtils.deserialize(new Base64(true).decode(parameter));
			}
			MethodUtils.invokeMethod(object, methodName, arguments);
			log.info("invoke refreshCache method [" + beanId + "#" + methodName + "] success");
			pw.print("ok");
		} catch (Exception e) {
			log.error("invoke refreshCache method [" + beanId + "#" + methodName + "] error," + e.getMessage());
			pw.print("error");
		}
	}
}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:24,代碼來源:RefreshCacheController.java

示例3: executeMethod

import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
private static Object executeMethod(Object o, String methodName) {
	Object newObject = null;
	try {
		if (o instanceof RepositoryItem) {
			RepositoryItem repositoryItem = (RepositoryItem) o;
			if (repositoryItem.getItemDescriptor().hasProperty(methodName)) {
				newObject = repositoryItem.getPropertyValue(methodName);
			}
		} else if (o instanceof Map) {
			Map map = (Map) o;
			newObject = map.get(methodName);
		} else {
			methodName = "get" + upperCaseFirstLetter(methodName);
			newObject = MethodUtils.invokeMethod(o, methodName, null);
		}
	} catch (Exception e) {
		// dont care
	}
	return newObject;
}
 
開發者ID:varelma,項目名稱:atg-generics,代碼行數:21,代碼來源:BeanUtils.java

示例4: createDir

import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
@Override
public Vfs.Dir createDir(URL url) {
    try {
        File tmpFile = File.createTempFile("vfs-jndi-bundle", ".jar");

        // we need to load this resource from the server context using the server ClassLoader
        // we use reflections to call the service exposed by the server
        BundleContext bundleContext = FrameworkUtil.getBundle(JndiUrlType.class).getBundleContext();
        Object jndiService = OSGiServiceUtils.findService(bundleContext, JNDI_SERVICE);

        // copy to the resource to the temp file
        MethodUtils.invokeMethod(jndiService, WRITE_TO_FILE_METHOD,
                new Object[] {url.toString(), tmpFile.getAbsolutePath()});

        return new TmpDir(tmpFile);
    } catch (IOException | InvocationTargetException | NoSuchMethodException | IllegalAccessException e) {
        throw new IllegalArgumentException("Unable to create mvn url for " + url, e);
    }
}
 
開發者ID:motech,項目名稱:motech,代碼行數:20,代碼來源:JndiUrlType.java

示例5: getHandlers

import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
public List getHandlers() {
    List handlerAccessors = new ArrayList();
    try {
        Object handlers[] = (Object[]) MethodUtils.invokeMethod(getTarget(), "getHandlers", null);
        for (int h = 0; h < handlers.length; h++) {
            Object handler = handlers[h];
            Jdk14HandlerAccessor handlerAccessor = wrapHandler(handler, h);
            if (handlerAccessor != null) {
                handlerAccessors.add(handlerAccessor);
            }
        }
    } catch (Exception e) {
        log.error(getTarget().getClass().getName() + "#handlers inaccessible", e);
    }
    return handlerAccessors;
}
 
開發者ID:andresol,項目名稱:psi-probe-plus,代碼行數:17,代碼來源:Jdk14LoggerAccessor.java

示例6: getLevel

import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
public String getLevel() {
    try {
        Object level = null;
        Object target = getTarget();
        while (level == null && target != null) {
            level = getLevelInternal(target);
            target = MethodUtils.invokeMethod(target, "getParent", null);
        }
        if (level == null && isJuliRoot()) {
            return "INFO";
        } else {
            return (String) MethodUtils.invokeMethod(level, "getName", null);
        }
    } catch (Exception e) {
        log.error(getTarget().getClass().getName() + "#getLevel() failed", e);
    }
    return null;
}
 
開發者ID:andresol,項目名稱:psi-probe-plus,代碼行數:19,代碼來源:Jdk14LoggerAccessor.java

示例7: getAppenders

import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
/**
 * Returns all appenders of this logger.
 * 
 * @return a list of {@link LogbackAppenderAccessor}s
 */
public List getAppenders() {
    List appenders = new ArrayList();
    try {
        Iterator it =  (Iterator) MethodUtils.invokeMethod(getTarget(), "iteratorForAppenders", null);
        while (it.hasNext()) {
            Object appender = it.next();
            List siftedAppenders = getSiftedAppenders(appender);
            if (siftedAppenders != null) {
                for (int i = 0; i < siftedAppenders.size(); i++) {
                    Object siftedAppender = siftedAppenders.get(i);
                    wrapAndAddAppender(siftedAppender, appenders);
                }
            } else {
                wrapAndAddAppender(appender, appenders);
            }
        }
    } catch (Exception e) {
        log.error(getTarget().getClass().getName() + "#getAppenders() failed", e);
    }
    return appenders;
}
 
開發者ID:andresol,項目名稱:psi-probe-plus,代碼行數:27,代碼來源:LogbackLoggerAccessor.java

示例8: getAppender

import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
/**
 * Returns the appender of this logger with the given name.
 * 
 * @param name the name of the appender to return
 * @return the appender with the given name, or null if no such
 *         appender exists for this logger
 */
public LogbackAppenderAccessor getAppender(String name) {
    try {
        Object appender = MethodUtils.invokeMethod(getTarget(), "getAppender", name);
        if (appender == null) {
            List appenders = getAppenders();
            for (int i = 0; i < appenders.size(); i++) {
                LogbackAppenderAccessor wrappedAppender = (LogbackAppenderAccessor) appenders.get(i);
                if (wrappedAppender.getIndex().equals(name)) {
                    return wrappedAppender;
                }
            }
        }
        return wrapAppender(appender);
    } catch (Exception e) {
        log.error(getTarget().getClass().getName() + "#getAppender() failed", e);
    }
    return null;
}
 
開發者ID:andresol,項目名稱:psi-probe-plus,代碼行數:26,代碼來源:LogbackLoggerAccessor.java

示例9: provide

import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
@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;
}
 
開發者ID:FenixEdu,項目名稱:fenixedu-academic,代碼行數:18,代碼來源:ExecutionPeriodsForExecutionYear.java

示例10: invokeFactoryMethod

import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
protected T invokeFactoryMethod(Object factory)
{
	try
	{
		return (T) MethodUtils.invokeMethod(factory, getMethodName(), getArgs());
	}
	catch( Exception e )
	{
		throw new RuntimeException(e);
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:13,代碼來源:FactoryMethodLocator.java

示例11: replaceField

import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
public static void replaceField(Customer current, Customer to) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
	Field[] fields = Customer.class.getFields();
	for (Field field : fields) {
		if (!"id".equalsIgnoreCase(field.getName())) {
			String getter = "get" + StringUtils.capitalize(field.getName());
			String setter = "set" + StringUtils.capitalize(field.getName());
			
			Object value = MethodUtils.invokeMethod(to, getter, ArrayUtils.EMPTY_OBJECT_ARRAY);
			if (value != null) {
				MethodUtils.invokeMethod(current, setter, new Object[]{value});
			}
		}
	}
}
 
開發者ID:dynamo2,項目名稱:tianma,代碼行數:15,代碼來源:CustomerImport.java

示例12: invokeMethod

import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
/**
    * Invoca un metodo sobre un objeto
    * @param obj El objeto sobre el que se invoca el metodo (si es null se intenta llamar a un m�todo est�tico)
    * @param methodName nombre del metodo a invocar
    * @param argsTypes tipos de los argumentos a invocar
    * @param argsValues valores de los argumentos
    * @return El objeto devuelto tras la invocacion del metodo
    * @throws ReflectionException si ocurre algun error
    */
   @SuppressWarnings("unchecked")
public static <T> T invokeMethod(final Object obj,
   								 final String methodName,final Class<?>[] argsTypes,final Object[] argsValues) {
   	if (obj == null || methodName == null) throw new IllegalArgumentException(Throwables.message("Cannot invoke {} method on null object instance",
   																							     (methodName != null ? methodName : "null"),
   																							     (obj != null ? obj.getClass() : "null")));
   	try {
          return (T)MethodUtils.invokeMethod(obj,methodName,argsValues,argsTypes);
   	} catch (Throwable th) { 
          throw ReflectionException.of(th);
   	} 
   }
 
開發者ID:opendata-euskadi,項目名稱:r01fb,代碼行數:22,代碼來源:ReflectionUtils.java

示例13: moveToTrash

import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
@Override
@Transactional
public void moveToTrash(Object instance, Long entityVersion) {
    Class<?> trashClass = HistoryTrashClassHelper.getClass(instance, EntityType.TRASH,
            getBundleContext());

    if (null != trashClass) {
        LOGGER.debug("Moving {} to trash", instance);

        // create and save a trash instance
        LOGGER.debug("Creating trash instance for: {}", instance);

        Object trash = create(trashClass, instance, null);

        LOGGER.debug("Created trash instance for: {}", instance);

        try {
            MethodUtils.invokeMethod(trash, "setSchemaVersion", entityVersion);
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
            LOGGER.error("Failed to set schema version of the trash instance.");
        }

        PersistenceManager manager = getPersistenceManagerFactory().getPersistenceManager();

        manager.makePersistent(trash);
    } else {
        throw new IllegalStateException(
                "Not found the trash class for " + instance.getClass().getName()
        );
    }
}
 
開發者ID:motech,項目名稱:motech,代碼行數:32,代碼來源:TrashServiceImpl.java

示例14: getLogger

import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
public Jdk14LoggerAccessor getLogger(String name) {
    try {
        Object logger = MethodUtils.invokeMethod(getTarget(), "getLogger", name);
        if (logger == null) {
            throw new NullPointerException(getTarget().getClass().getName() + "#getLogger(\"" + name + "\") returned null");
        }
        Jdk14LoggerAccessor accessor = new Jdk14LoggerAccessor();
        accessor.setTarget(logger);
        accessor.setApplication(getApplication());
        return accessor;
    } catch (Exception e) {
        log.error(getTarget().getClass().getName() + "#getLogger(\"" + name + "\") failed", e);
    }
    return null;
}
 
開發者ID:andresol,項目名稱:psi-probe-plus,代碼行數:16,代碼來源:Jdk14ManagerAccessor.java

示例15: setLevel

import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
public void setLevel(String newLevelStr) {
    try {
        Object level = MethodUtils.invokeMethod(getTarget(), "getLevel", null);
        Object newLevel = MethodUtils.invokeMethod(level, "parse", newLevelStr);
        MethodUtils.invokeMethod(getTarget(), "setLevel", newLevel);
    } catch (Exception e) {
        log.error(getTarget().getClass().getName() + "#setLevel(\"" + newLevelStr + "\") failed", e);
    }
}
 
開發者ID:andresol,項目名稱:psi-probe-plus,代碼行數:10,代碼來源:Jdk14HandlerAccessor.java


注:本文中的org.apache.commons.beanutils.MethodUtils.invokeMethod方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。