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


Java MethodUtils類代碼示例

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


MethodUtils類屬於org.apache.commons.beanutils包,在下文中一共展示了MethodUtils類的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: loadOjbRepositoryFiles

import org.apache.commons.beanutils.MethodUtils; //導入依賴的package包/類
/**
 * 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);
            }
        }
    }

}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:32,代碼來源:ModuleConfiguration.java

示例5: getProperty

import org.apache.commons.beanutils.MethodUtils; //導入依賴的package包/類
private static <T extends Number> List<T> getProperty(Collection<?> values, String property, T rawValue) {
    if (values == null || values.isEmpty()) {
        return Collections.<T> emptyList();
    }
    List<T> result = new ArrayList<T>(values.size());
    for (Object value : values) {
        try {
            String propertyValue = value.toString();
            if (property != null) {
                propertyValue = BeanUtils.getProperty(value, property);
            }
            Object key = MethodUtils.invokeExactMethod(rawValue, "valueOf", propertyValue);
            result.add((T) key);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            continue;
        }
    }
    return result;
}
 
開發者ID:wanghuizi,項目名稱:fengduo,代碼行數:21,代碼來源:CollectionUtils.java

示例6: getCurrentStatus

import org.apache.commons.beanutils.MethodUtils; //導入依賴的package包/類
/**
 * Retrieves the current platform status. The object returned will be created using the current (webapp) classlaoder,
 * preventing casting issues.
 * @return the current status of the platform, for safe use with the webapp classloader
 */
public PlatformStatus getCurrentStatus() {
    Object mgr = getStatusManager();

    if (mgr == null) {
        LOGGER.debug("Status manager unavailable");
        return new PlatformStatus();
    } else {
        try {
            Object status = MethodUtils.invokeExactMethod(mgr, "getCurrentStatus", new Object[0]);
            return convertStatusBetweenClassLoaders(status);
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
            throw new StatusProxyException("Unable to retrieve status from the manager instance", e);
        }
    }
}
 
開發者ID:motech,項目名稱:motech,代碼行數:21,代碼來源:PlatformStatusProxy.java

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: LogbackFactoryAccessor

import org.apache.commons.beanutils.MethodUtils; //導入依賴的package包/類
/**
 * Attempts to initialize a Logback logger factory via the given class loader.
 *  
 * @param cl the ClassLoader to use when fetching the factory
 */
public LogbackFactoryAccessor(ClassLoader cl) throws ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    // Get the singleton SLF4J binding, which may or may not be Logback, depending on the            
    // binding.
    Class clazz = cl.loadClass("org.slf4j.impl.StaticLoggerBinder");
    Method m1 = MethodUtils.getAccessibleMethod(clazz, "getSingleton", new Class[]{});
    Object singleton = m1.invoke(null, null);
    Method m = MethodUtils.getAccessibleMethod(clazz, "getLoggerFactory", new Class[]{});
    Object loggerFactory = m.invoke(singleton, null);

    // Check if the binding is indeed Logback
    Class loggerFactoryClass = cl.loadClass("ch.qos.logback.classic.LoggerContext");            
    if (!loggerFactoryClass.isInstance(loggerFactory)) {
        throw new RuntimeException("The singleton SLF4J binding was not Logback");
    }
    setTarget(loggerFactory);
}
 
開發者ID:andresol,項目名稱:psi-probe-plus,代碼行數:22,代碼來源:LogbackFactoryAccessor.java

示例13: getLogger

import org.apache.commons.beanutils.MethodUtils; //導入依賴的package包/類
/**
 * Returns the Logback logger with a given name.
 * 
 * @return the Logger with the given name
 */
public LogbackLoggerAccessor getLogger(String name) {
    try {
        Class clazz = getTarget().getClass();
        Method m = MethodUtils.getAccessibleMethod(clazz, "getLogger", new Class[] {String.class});
        Object logger = m.invoke(getTarget(), new Object[] {name});
        if (logger == null) {
            throw new NullPointerException(getTarget() + ".getLogger(\"" + name + "\") returned null");
        }
        LogbackLoggerAccessor accessor = new LogbackLoggerAccessor();
        accessor.setTarget(logger);
        accessor.setApplication(getApplication());
        return accessor;

    } catch (Exception e) {
        log.error(getTarget() + ".getLogger(\"" + name + "\") failed", e);
    }
    return null;
}
 
開發者ID:andresol,項目名稱:psi-probe-plus,代碼行數:24,代碼來源:LogbackFactoryAccessor.java

示例14: getAppenders

import org.apache.commons.beanutils.MethodUtils; //導入依賴的package包/類
/**
 * Returns a list of wrappers for all Logback appenders that have an
 * associated logger.
 * 
 * @return a list of {@link LogbackAppenderAccessor}s representing all
 *         appenders that are in use
 */
public List getAppenders() {
    List appenders = new ArrayList();
    try {
        Class clazz = getTarget().getClass();
        Method m = MethodUtils.getAccessibleMethod(clazz, "getLoggerList", new Class[]{});
        List loggers = (List) m.invoke(getTarget(), null);
        Iterator it = loggers.iterator();
        while (it.hasNext()) {
            LogbackLoggerAccessor accessor = new LogbackLoggerAccessor();
            accessor.setTarget(it.next());
            accessor.setApplication(getApplication());

            appenders.addAll(accessor.getAppenders());
        }
    } catch (Exception e) {
        log.error(getTarget() + ".getLoggerList() failed", e);
    }
    return appenders;
}
 
開發者ID:andresol,項目名稱:psi-probe-plus,代碼行數:27,代碼來源:LogbackFactoryAccessor.java

示例15: getRootLogger

import org.apache.commons.beanutils.MethodUtils; //導入依賴的package包/類
public Log4JLoggerAccessor getRootLogger() {
    try {
        Class clazz = (Class) getTarget();
        Method m = MethodUtils.getAccessibleMethod(clazz, "getRootLogger", new Class[]{});
        Object logger = m.invoke(null, null);
        if (logger == null) {
            throw new NullPointerException(getTarget().getClass().getName() + "#getRootLogger() returned null");
        }
        Log4JLoggerAccessor accessor = new Log4JLoggerAccessor();
        accessor.setTarget(logger);
        accessor.setApplication(getApplication());
        return accessor;
    } catch (Exception e) {
        log.error(getTarget().getClass().getName() + "#getRootLogger() failed", e);
    }
    return null;
}
 
開發者ID:andresol,項目名稱:psi-probe-plus,代碼行數:18,代碼來源:Log4JManagerAccessor.java


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