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


Java MethodUtils.getAccessibleMethod方法代碼示例

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


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

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

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

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

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

示例5: getLogger

import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
public Log4JLoggerAccessor getLogger(String name) {
    try {
        Class clazz = (Class) getTarget();
        Method m = MethodUtils.getAccessibleMethod(clazz, "getLogger", new Class[] {String.class});
        Object logger = m.invoke(null, new Object[] {name});
        if (logger == null) {
            throw new NullPointerException(getTarget().getClass().getName() + "#getLogger(\"" + name + "\") returned null");
        }
        Log4JLoggerAccessor accessor = new Log4JLoggerAccessor();
        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,代碼行數:18,代碼來源:Log4JManagerAccessor.java

示例6: setTestName

import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
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);
    }
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:9,代碼來源:LoadTimeWeavableTestRunner.java

示例7: setTestName

import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
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);
        }
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:8,代碼來源:RiceUnitTestClassRunner.java

示例8: testBeanClass

import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
@Override
public boolean testBeanClass(Class<?> klass, Object[] constructorArgs) {
	this.setFailureReason(null);
	Object bean = InstantiationUtils.safeNewInstance(klass, constructorArgs);
	if (bean instanceof Serializable) {
		InjectionUtils.injectValues(bean, valueGeneratorFactory, false);
		
		Serializable sBean = (Serializable)bean;
		Serializable sBeanReconstituted = null;
		byte[] serializedObj;
		try {
			serializedObj = SerializationUtils.serialize(sBean);			
			sBeanReconstituted = SerializationUtils.deserialize(serializedObj);
		} catch (Throwable e) {
			this.setFailureReason("Error serializing bean that implements serializable");
			throw new BeanTesterException("Error serializing bean that implements serializable", e)
				.addContextValue("class", klass.getName());
		}
		
		/*
		 * An equals() test is only valid if the bean isn't relying on Object.equals().
		 */
		Method equalsMethod = MethodUtils.getAccessibleMethod(klass, "equals", Object.class);
		if ( !equalsMethod.getDeclaringClass().equals(Object.class) && !sBean.equals(sBeanReconstituted)) {
			this.setFailureReason("Bean implements serializable, but the reconstituted bean doesn't equal it's original");
			throw new BeanTesterException("Bean implements serializable, but the reconstituted bean doesn't equal it's original")
			.addContextValue("class", klass.getName());
		}
	}
	return true;
}
 
開發者ID:Force66,項目名稱:BeanTester,代碼行數:32,代碼來源:SerializableTest.java

示例9: isPk

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

示例10: Jdk14ManagerAccessor

import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
public Jdk14ManagerAccessor(ClassLoader cl) throws ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    Class clazz = cl.loadClass("java.util.logging.LogManager");
    Method getManager = MethodUtils.getAccessibleMethod(clazz, "getLogManager", new Class[]{});
    Object manager = getManager.invoke(null, null);
    if (manager == null) {
        throw new NullPointerException(clazz.getName() + ".getLogManager() returned null");
    }
    setTarget(manager);
}
 
開發者ID:andresol,項目名稱:psi-probe-plus,代碼行數:10,代碼來源:Jdk14ManagerAccessor.java

示例11: setLevel

import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
public void setLevel(String newLevelStr) {
    try {
        Class levelClass = getTarget().getClass().getClassLoader().loadClass("java.util.logging.Level");
        Method parse = MethodUtils.getAccessibleMethod(levelClass, "parse", String.class);
        Object newLevel = parse.invoke(null, new Object[] {newLevelStr});
        MethodUtils.invokeMethod(getTarget(), "setLevel", newLevel);
    } catch (Exception e) {
        log.error(getTarget().getClass().getName() + "#setLevel(\"" + newLevelStr + "\") failed", e);
    }
}
 
開發者ID:andresol,項目名稱:psi-probe-plus,代碼行數:11,代碼來源:Jdk14LoggerAccessor.java

示例12: Log4JManagerAccessor

import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
public Log4JManagerAccessor(ClassLoader cl) throws ClassNotFoundException {
    Class clazz = cl.loadClass("org.apache.log4j.LogManager");
    Method m = MethodUtils.getAccessibleMethod(clazz, "exists", new Class[] {String.class});
    if (m == null) {
        throw new RuntimeException("The LogManager is part of the slf4j bridge.");
    }
    setTarget(clazz);
}
 
開發者ID:andresol,項目名稱:psi-probe-plus,代碼行數:9,代碼來源:Log4JManagerAccessor.java

示例13: register

import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
@Override
public synchronized void register(String topic, EventHandler eventHandler) {
    final Method eventHandlerMethod = MethodUtils.getAccessibleMethod(eventHandler.getClass(), "handleEvent", Event.class);

    final AnnotatedObserver ao = new AnnotatedObserver(eventHandler, eventHandlerMethod);
    ao.setTopic(topic);

    final Collection<AnnotatedObserver> topicObservers = getOrCreateObserversForTopic(topic);
    topicObservers.add(ao);
}
 
開發者ID:ventilb,項目名稱:stagediver.fx-eventbus,代碼行數:11,代碼來源:EventBusImpl.java

示例14: getReadMethod

import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
/**
 * <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));
}
 
開發者ID:Talend,項目名稱:components,代碼行數:12,代碼來源:Beans.java

示例15: getWriteMethod

import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
/**
 * <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()}));
}
 
開發者ID:Talend,項目名稱:components,代碼行數:13,代碼來源:Beans.java


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