当前位置: 首页>>代码示例>>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;未经允许,请勿转载。