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


Java FieldUtils.writeField方法代碼示例

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


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

示例1: writeAllFieldsOfType

import org.apache.commons.lang3.reflect.FieldUtils; //導入方法依賴的package包/類
public static <T> void writeAllFieldsOfType(Object o, T t, Class<T> c) throws IllegalAccessException
{
	boolean wroteSomething = false;

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

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

示例2: checkCommands

import org.apache.commons.lang3.reflect.FieldUtils; //導入方法依賴的package包/類
private void checkCommands(final String os, final String... command) throws ReflectiveOperationException {
	final URL[] urLs = ((URLClassLoader) Main.class.getClassLoader()).getURLs();
	ThreadClassLoaderScope scope = null;
	try {
		System.setProperty("os.name", os);
		final URLClassLoader urlClassLoader = new URLClassLoader(urLs, null);
		scope = new ThreadClassLoaderScope(urlClassLoader);
		final Object terra = urlClassLoader.loadClass("org.ligoj.app.plugin.prov.terraform.TerraformUtils").newInstance();
		final Object mock = MethodUtils.invokeStaticMethod(urlClassLoader.loadClass("org.mockito.Mockito"), "mock",
				urlClassLoader.loadClass("org.ligoj.bootstrap.resource.system.configuration.ConfigurationResource"));
		FieldUtils.writeField(terra, "configuration", mock, true);
		Assert.assertEquals(Arrays.asList(command),
				((ProcessBuilder) MethodUtils.invokeMethod(terra, true, "newBuilder", new Object[] { new String[] { "terraform" } }))
						.command());
	} finally {
		IOUtils.closeQuietly(scope);
	}
}
 
開發者ID:ligoj,項目名稱:plugin-prov,代碼行數:19,代碼來源:TerraformUtilsTest.java

示例3: getModifiedRetrofit

import org.apache.commons.lang3.reflect.FieldUtils; //導入方法依賴的package包/類
private Retrofit getModifiedRetrofit(boolean isEnabled) {
    MockableCallAdapterFactory factory = MockableCallAdapterFactory.getInstance(context, isEnabled);

    List<CallAdapter.Factory> factories = new ArrayList<>();
    factories.add(factory);
    factories.addAll(retrofit.callAdapterFactories());

    try {
        FieldUtils.writeField(retrofitBuilder, "adapterFactories", factories, true);
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }

    factory.setFactory(retrofit.callFactory());

    retrofit = retrofitBuilder.build();

    return retrofit;
}
 
開發者ID:GabrielSamojlo,項目名稱:OffIt,代碼行數:20,代碼來源:OffIt.java

示例4: setup

import org.apache.commons.lang3.reflect.FieldUtils; //導入方法依賴的package包/類
@Before
public void setup() throws IllegalAccessException {
	servletContext = Mockito.mock(ServletContext.class);
	servlet = new BackendProxyServlet() {
		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;

		{
			_log = Log.getLogger("junit");
		}

		@Override
		public ServletContext getServletContext() {
			return servletContext;
		}
	};

	FieldUtils.writeField(servlet, "_log", Mockito.mock(Logger.class), true);
	callback = Mockito.mock(Callback.class);
}
 
開發者ID:ligoj,項目名稱:bootstrap,代碼行數:23,代碼來源:BackendProxyServletTest.java

示例5: setup

import org.apache.commons.lang3.reflect.FieldUtils; //導入方法依賴的package包/類
@Before
public void setup() throws IllegalAccessException {
  MockitoAnnotations.initMocks(this);
  List<String> yamlExtensions = new ArrayList<>();
  yamlExtensions.add(".yaml");
  yamlExtensions.add(".yml");
  FieldUtils.writeField(seed, "yamlExtensions", yamlExtensions, true);
  FieldUtils.writeField(seed, "protocol", CONSUL_PROTOCOL, true);
  FieldUtils.writeField(seed, "host", CONSUL_HOST, true);
  FieldUtils.writeField(seed, "port", CONSUL_PORT, true);
  FieldUtils.writeField(seed, "globalPrefix", CONSUL_GLOBAL_PREFIX, true);
  FieldUtils.writeField(seed, "failLimit", FAIL_LIMIT, true);
  FieldUtils.writeField(seed, "waitTimeBetweenFails", WAIT_TIME, true);
  FieldUtils.writeField(seed, "configPath", CONFIG_PATH, true);
  List<String> acceptableFileExtenstions = new ArrayList<>();
  acceptableFileExtenstions.addAll(yamlExtensions);
  acceptableFileExtenstions.add(".properties");
  FieldUtils.writeField(seed, "acceptablePropertyExtensions", acceptableFileExtenstions, true);
  consul = seed.getConsul();
  assertNotNull("Unable to get Consul instance for testing (check that Consul is running).",
      consul);
  kvClient = consul.keyValueClient();
  assertNotNull("Key Value Client is null.  Can't run tests", kvClient);
}
 
開發者ID:edgexfoundry,項目名稱:core-config-seed,代碼行數:25,代碼來源:EdgeXConfigSeedTest.java

示例6: testCheckException

import org.apache.commons.lang3.reflect.FieldUtils; //導入方法依賴的package包/類
@Test
public void testCheckException() throws Exception {
	TestCassandraHealthCheck testCassandraHealthCheck = new TestCassandraHealthCheck(TEST_SERVER);
	testCassandraHealthCheck.cluster = testCluster;
	FieldUtils.writeField(testCassandraHealthCheck, "logger", loggerMock, true);
	Mockito.when(session.execute(Matchers.anyString())).thenThrow(new RuntimeException("crap"));
	Result result = testCassandraHealthCheck.check();

	Assert.assertFalse(result.isHealthy());
	Mockito.verify(session).close();
	Mockito.verify(session).execute(Matchers.anyString());
	Assert.assertEquals(1, testCluster.nbrTimesCloseCalled);

	ArgumentCaptor<ContextedRuntimeException> exCaptor = ArgumentCaptor.forClass(ContextedRuntimeException.class);
	Mockito.verify(loggerMock).error(Matchers.anyString(), exCaptor.capture());
	Assert.assertEquals(3, exCaptor.getValue().getContextLabels().size());
	Assert.assertEquals(result.getError(), exCaptor.getValue());
}
 
開發者ID:BreakTheMonolith,項目名稱:btm-DropwizardHealthChecks,代碼行數:19,代碼來源:CassandraHealthCheckTest.java

示例7: injectContainers

import org.apache.commons.lang3.reflect.FieldUtils; //導入方法依賴的package包/類
private void injectContainers() {
  List<Field> fields = FieldUtils.getFieldsListWithAnnotation(testClass, InjectContainer.class);
  for (Field field : fields) {
    if (!Container.class.isAssignableFrom(field.getType())) {
      continue;
    }

    InjectContainer container = field.getAnnotation(InjectContainer.class);
    Container instance = controller.getContainer(container.name(), field.getType().asSubclass(Container.class));
    LOG.info("Binding [{}] -> [{}]", container.name(), instance.getName());
    try {
      FieldUtils.writeField(field, target, instance, true);
    } catch (IllegalAccessException e) {
      throw new IllegalStateException("Could not set field:" + field.getName());
    }
  }
}
 
開發者ID:Qorr,項目名稱:Hvalspik,代碼行數:18,代碼來源:HvalspikRunner.java

示例8: testNetworkFluctuation

import org.apache.commons.lang3.reflect.FieldUtils; //導入方法依賴的package包/類
@Test
public void testNetworkFluctuation() throws Exception {
    SuperMarket superMarket = new SuperMarket();
    HttpDiscountService mockedHttpDiscountService = mock(HttpDiscountService.class);
    FieldUtils.writeField(superMarket, "httpDiscountService", mockedHttpDiscountService, true);

    when(mockedHttpDiscountService.getDiscountFromRemoteService())
            .thenThrow(new SocketTimeoutException())
            .thenCallRealMethod();

    float price = superMarket.checkout(10);

    // 10 * 3.5 * 0.5 = 17.5
    assertEquals(price, 17.5f);
    verify(mockedHttpDiscountService, times(2)).getDiscountFromRemoteService();
}
 
開發者ID:WalterInSH,項目名稱:unit-testing,代碼行數:17,代碼來源:SuperMarketTest.java

示例9: setEntityField

import org.apache.commons.lang3.reflect.FieldUtils; //導入方法依賴的package包/類
private void setEntityField(E entity, Field[] fields, String fieldName, String value)
{
    Optional<Field> opt = Arrays.stream(fields)
            .filter(f -> f.getName().equalsIgnoreCase(fieldName)).findFirst();

    if (!opt.isPresent()){
        return;
    }

    Field field = opt.get();

    try {
        FieldUtils.writeField(field, entity, ReflectionUtils.convertStringToType(value, field), true);
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}
 
開發者ID:epam,項目名稱:JDI,代碼行數:18,代碼來源:EntityTable.java

示例10: set

import org.apache.commons.lang3.reflect.FieldUtils; //導入方法依賴的package包/類
@Override
public Mapper set(final String name, final Object value) {
    if (RESERVED_NAMES.containsKey(name)) {
        try {
            FieldUtils.writeField(this, RESERVED_NAMES.get(name), value, true);
        } catch (Exception e) {
            throw new RuntimeException(format("Failed to set Assignment.%s to %s", name, value), e);
        }
    }
    if (overrides.containsKey(name)) {
        return this;
    }
    if (value instanceof PlanOutOpRandom) {
        final PlanOutOpRandom random = (PlanOutOpRandom)value;
        if (!random.hasArg("salt")) {
            random.setArg("salt", name);
        }
        data.put(name, random.executeWithLogging(this));
    } else {
        data.put(name, value);
    }
    return this;
}
 
開發者ID:Glassdoor,項目名稱:planout4j,代碼行數:24,代碼來源:Assignment.java

示例11: writeProperty

import org.apache.commons.lang3.reflect.FieldUtils; //導入方法依賴的package包/類
private void writeProperty(Property p, Object value)
{
	try
	{
		Object oldValue = readProperty(p);
		
		FieldUtils.writeField(model, p.name, value, true);
		
		if(DataModel.class.isInstance(model))
			((DataModel) model).pcs.firePropertyChange(p.name, oldValue, value);
	}
	catch (IllegalAccessException e)
	{
		e.printStackTrace();
	}
}
 
開發者ID:justin-espedal,項目名稱:polydes,代碼行數:17,代碼來源:PropertiesPage.java

示例12: initializeInterceptor

import org.apache.commons.lang3.reflect.FieldUtils; //導入方法依賴的package包/類
private void initializeInterceptor() {
    AbstractWebApplication application = (AbstractWebApplication) getApplication();
    for (Field field : ReflectionUtils.getAllFields(this.getClass())) {
        if (field.getAnnotation(Setting.class) != null) {
            Setting setting = field.getAnnotation(Setting.class);
            if (field.getType() != FileUpload.class
                    && field.getType() != FileUpload[].class) {
                try {
                    FieldUtils.writeField(
                            field,
                            this,
                            application.select(setting.name(),
                                    field.getType()), true);
                } catch (IllegalAccessException e) {
                }
            }
        }
    }

    org.apache.wicket.markup.html.form.TextField<String> repository = (org.apache.wicket.markup.html.form.TextField<String>) getFormComponent("repository");
    getForm().add(new LocalRepositoryValidator(repository));

}
 
開發者ID:PkayJava,項目名稱:pluggable,代碼行數:24,代碼來源:InstallationPage.java

示例13: initializeInterceptor

import org.apache.commons.lang3.reflect.FieldUtils; //導入方法依賴的package包/類
private void initializeInterceptor() {
    AbstractWebApplication application = (AbstractWebApplication) getApplication();
    for (Field field : ReflectionUtils.getAllFields(this.getClass())) {
        if (field.getAnnotation(Setting.class) != null) {
            Setting setting = field.getAnnotation(Setting.class);
            if (field.getType() != FileUpload.class
                    && field.getType() != FileUpload[].class) {
                try {
                    FieldUtils.writeField(
                            field,
                            this,
                            application.select(setting.name(),
                                    field.getType()), true);
                } catch (IllegalAccessException e) {
                }
            }
        }
    }

    org.apache.wicket.markup.html.form.TextField<String> local = (org.apache.wicket.markup.html.form.TextField<String>) getFormComponent("repository");
    getForm().add(new LocalRepositoryValidator(local));

}
 
開發者ID:PkayJava,項目名稱:pluggable,代碼行數:24,代碼來源:ApplicationSettingPage.java

示例14: parseInputList

import org.apache.commons.lang3.reflect.FieldUtils; //導入方法依賴的package包/類
private static void parseInputList(Object target, String[] values, Field field) throws ReflectiveOperationException, ParseException {
    List convertedValues = new ArrayList();
    Class type = getCollectionComponentType(field);
    for (String value : values) {
        Object val = convertValue(value, type);
        convertedValues.add(val);
    }
    if (field.getType().isArray()) {
        Object array = Array.newInstance(field.getType().getComponentType(), convertedValues.size());
        for (int i = 0; i < convertedValues.size(); i++) {
            Array.set(array, i, convertedValues.get(i));
        }
        FieldUtils.writeField(field, target, array, true);
    } else {
        Collection c = (Collection) getInstantiatableListType(field.getType()).newInstance();
        c.addAll(convertedValues);
        FieldUtils.writeField(field, target, c, true);
    }
}
 
開發者ID:Adobe-Consulting-Services,項目名稱:acs-aem-commons,代碼行數:20,代碼來源:AnnotatedFieldDeserializer.java

示例15: lookup

import org.apache.commons.lang3.reflect.FieldUtils; //導入方法依賴的package包/類
@Override
public Wagon lookup(String roleHint) throws Exception {
    if ("http".equals(roleHint)) {
        if (useLightweightHttpWagon) {
            LightweightHttpWagon lightweightHttpWagon = new LightweightHttpWagon();
            FieldUtils.writeField(lightweightHttpWagon, "authenticator", new LightweightHttpWagonAuthenticator(), true);
            return lightweightHttpWagon;
        } else {
            return new HttpWagon();
        }
    } else if ("https".equals(roleHint)) {
        if (useLightweightHttpWagon) {
            LightweightHttpsWagon lightweightHttpsWagon = new LightweightHttpsWagon();
            FieldUtils.writeField(lightweightHttpsWagon, "authenticator", new LightweightHttpWagonAuthenticator(), true);
            return lightweightHttpsWagon;
        } else {
            return new HttpWagon();
        }
    } else if ("file".equals(roleHint)) {
        return new FileWagon();
    }
    return null;
}
 
開發者ID:release-engineering,項目名稱:redhat-repository-validator,代碼行數:24,代碼來源:InternalWagonProvider.java


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