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


Java FieldUtils.writeStaticField方法代碼示例

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


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

示例1: writeAllStaticFieldsOfType

import org.apache.commons.lang3.reflect.FieldUtils; //導入方法依賴的package包/類
@SuppressWarnings({ "rawtypes" })
public static <T> void writeAllStaticFieldsOfType(Class d, T t, Class c) throws IllegalAccessException
{
	boolean wroteSomething = false;

       for (Field f : FieldUtils.getAllFields(d))
	{
       	if (Modifier.isStatic(f.getModifiers()) && f.getType().equals(c))
       	{
       		FieldUtils.writeStaticField(f, t, true);
       		wroteSomething = true;
       	}
	}

       if (!wroteSomething)
       	throw new IllegalAccessException();
}
 
開發者ID:orbwoi,項目名稱:UniversalRemote,代碼行數:18,代碼來源:InjectionHandler.java

示例2: apply

import org.apache.commons.lang3.reflect.FieldUtils; //導入方法依賴的package包/類
@Override
public Statement apply(final Statement base, final Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            System.setProperty(Constants.LOG4J_LOG_EVENT_FACTORY, TestLogEventFactory.class.getName());
            resetLogEventFactory(new TestLogEventFactory());
            try {
                base.evaluate();
            } finally {
                System.clearProperty(Constants.LOG4J_LOG_EVENT_FACTORY);
                resetLogEventFactory(new DefaultLogEventFactory());
            }
        }

        private void resetLogEventFactory(final LogEventFactory logEventFactory) throws IllegalAccessException {
            final Field field = FieldUtils.getField(LoggerConfig.class, "LOG_EVENT_FACTORY", true);
            FieldUtils.removeFinalModifier(field, true);
            FieldUtils.writeStaticField(field, logEventFactory, false);
        }
    };
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:23,代碼來源:LogEventFactoryTest.java

示例3: writeStaticFieldOfType

import org.apache.commons.lang3.reflect.FieldUtils; //導入方法依賴的package包/類
@SuppressWarnings({ "rawtypes" })
public static <T> void writeStaticFieldOfType(Class d, T t, Class<T> c) throws IllegalAccessException
{

       for (Field f : FieldUtils.getAllFields(d))
	{
       	if (Modifier.isStatic(f.getModifiers()) && f.getType().equals(c))
       	{
       		FieldUtils.writeStaticField(f, t, true);
       		return;
       	}
	}

       throw new IllegalAccessException();
}
 
開發者ID:orbwoi,項目名稱:UniversalRemote,代碼行數:16,代碼來源:InjectionHandler.java

示例4: setUp

import org.apache.commons.lang3.reflect.FieldUtils; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
	FieldUtils.writeStaticField(CommandUtils.class, "logger", loggerMock, true);
	commandStr = ArgumentCaptor.forClass(String.class);

	config = new DockerComposeConfiguration(TEST_YAML);
}
 
開發者ID:BreakTheMonolith,項目名稱:DockerProcessAPI,代碼行數:8,代碼來源:ComposeCommandUtilsTest.java

示例5: writeStatic

import org.apache.commons.lang3.reflect.FieldUtils; //導入方法依賴的package包/類
/**
 * Write static final field on given class.
 *
 * @param klass The class.
 * @param name The field name.
 * @param value The new field value.
 * @param <T> Type of value to write.
 */
public static <T> void writeStatic(Class<?> klass, String name, T value) {
	try {
		Field field = FieldUtils.getField(klass, name, true);
		FieldUtils.removeFinalModifier(field);
		FieldUtils.writeStaticField(field, value, true);
	} catch (Exception ex) {
		throw new AssertionError(ex);
	}
}
 
開發者ID:mjeanroy,項目名稱:node-maven-plugin,代碼行數:18,代碼來源:ReflectUtils.java

示例6: writeStaticFinal

import org.apache.commons.lang3.reflect.FieldUtils; //導入方法依賴的package包/類
/**
 * Write value on given static final field.
 *
 * @param klass The class.
 * @param name The field name.
 * @param value The new field value.
 */
public static void writeStaticFinal(Class<?> klass, String name, Object value) {
	Field field = FieldUtils.getDeclaredField(klass, name, true);
	FieldUtils.removeFinalModifier(field);

	try {
		FieldUtils.writeStaticField(field, value, true);
	} catch (IllegalAccessException ex) {
		throw new AssertionError(ex);
	}
}
 
開發者ID:mjeanroy,項目名稱:junit-servers,代碼行數:18,代碼來源:Fields.java

示例7: setUp

import org.apache.commons.lang3.reflect.FieldUtils; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
	FieldUtils.writeStaticField(DockerCommandUtils.class, "logger", loggerMock, true);
	FieldUtils.writeStaticField(CommandUtils.class, "logger", loggerMock, true);
	logArgStr = ArgumentCaptor.forClass(String.class);
}
 
開發者ID:BreakTheMonolith,項目名稱:DockerProcessAPI,代碼行數:7,代碼來源:DockerCommandUtilsTest.java

示例8: tearDown

import org.apache.commons.lang3.reflect.FieldUtils; //導入方法依賴的package包/類
@After
public void tearDown() throws Exception {
	FieldUtils.writeStaticField(DockerCommandUtils.class, "logger",
			LoggerFactory.getLogger(DockerCommandUtils.LOGGER_LABEL), true);
}
 
開發者ID:BreakTheMonolith,項目名稱:DockerProcessAPI,代碼行數:6,代碼來源:DockerCommandUtilsTest.java

示例9: resetClock

import org.apache.commons.lang3.reflect.FieldUtils; //導入方法依賴的package包/類
public static void resetClock(final Class<?> clazz) throws IllegalAccessException {
    System.clearProperty(ClockFactory.PROPERTY_NAME);
    final Field field = FieldUtils.getField(clazz, "CLOCK", true);
    FieldUtils.removeFinalModifier(field, true);
    FieldUtils.writeStaticField(field, ClockFactory.getClock(), false);
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:7,代碼來源:ClockFactoryTest.java


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