Example usage for org.apache.commons.lang3.reflect FieldUtils writeField

List of usage examples for org.apache.commons.lang3.reflect FieldUtils writeField

Introduction

In this page you can find the example usage for org.apache.commons.lang3.reflect FieldUtils writeField.

Prototype

public static void writeField(final Object target, final String fieldName, final Object value,
        final boolean forceAccess) throws IllegalAccessException 

Source Link

Document

Writes a Field .

Usage

From source file:io.rhiot.utils.Reflections.java

public static void writeField(Object object, String field, Object value) {
    try {/*from  www  .  ja  v a2 s  . c  o m*/
        FieldUtils.writeField(object, field, value, true);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.norconex.importer.handler.splitter.impl.FixedGoogleTranslator.java

public FixedGoogleTranslator() {
    super();// ww w. jav a  2  s .c  om
    try {
        FieldUtils.writeField(this, "isAvailable", true, true);
    } catch (IllegalAccessException e) {
        throw new ImporterRuntimeException("Cannot mark as available.", e);
    }
}

From source file:com.norconex.importer.handler.splitter.impl.FixedLingo24Translator.java

public FixedLingo24Translator() {
    super();//from  w ww.  j a v a 2 s  .  c  o m
    try {
        FieldUtils.writeField(this, "isAvailable", true, true);
    } catch (IllegalAccessException e) {
        throw new ImporterRuntimeException("Cannot mark as available.", e);
    }
}

From source file:com.norconex.importer.handler.splitter.impl.FixedGoogleTranslator.java

public void setApiKey(String apiKey) {
    try {//from  w  w  w.ja  v  a  2s  . com
        FieldUtils.writeField(this, "apiKey", apiKey, true);
    } catch (IllegalAccessException e) {
        throw new ImporterRuntimeException("Cannot set api key.", e);
    }
}

From source file:com.norconex.importer.handler.splitter.impl.FixedLingo24Translator.java

public void setUserKey(String userKey) {
    try {//ww  w . ja v  a 2  s.c om
        FieldUtils.writeField(this, "userKey", userKey, true);
    } catch (IllegalAccessException e) {
        throw new ImporterRuntimeException("Cannot set user key.", e);
    }
}

From source file:com.funtl.framework.smoke.core.modules.act.utils.ProcessDefUtils.java

public static void grantPermission(ActivityImpl activity, String assigneeExpression,
        String candidateGroupIdExpressions, String candidateUserIdExpressions) throws Exception {
    TaskDefinition taskDefinition = ((UserTaskActivityBehavior) activity.getActivityBehavior())
            .getTaskDefinition();//w w w.  jav a2 s  .c  o  m
    taskDefinition
            .setAssigneeExpression(assigneeExpression == null ? null : new FixedValue(assigneeExpression));
    FieldUtils.writeField(taskDefinition, "candidateUserIdExpressions",
            ExpressionUtils.stringToExpressionSet(candidateUserIdExpressions), true);
    FieldUtils.writeField(taskDefinition, "candidateGroupIdExpressions",
            ExpressionUtils.stringToExpressionSet(candidateGroupIdExpressions), true);

    Logger.getLogger(ProcessDefUtils.class)
            .info(String.format("granting previledges for [%s, %s, %s] on [%s, %s]", assigneeExpression,
                    candidateGroupIdExpressions, candidateUserIdExpressions,
                    activity.getProcessDefinition().getKey(), activity.getProperty("name")));
}

From source file:io.rhiot.component.kura.wifi.KuraAccessPointsProvider.java

private static void writeField(Object object, String field, Object value) {
    try {//from w w w .  j  a  va 2s .c o m
        FieldUtils.writeField(object, field, value, true);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.netflix.evcache.pool.EVCacheClientPoolTest.java

@Test
public void selectClient_hugeNumOfModOps_noException() throws Exception {
    // Arrange//from w ww. j av a2s.  c om

    // set up the object under test
    EVCacheNodeList evCacheNodeList = mock(EVCacheNodeList.class);
    EVCacheClientPoolManager evCacheClientPoolManager = mock(EVCacheClientPoolManager.class);

    EVCacheClientPool evCacheClientPool = new EVCacheClientPool("in a unit test", evCacheNodeList,
            (ThreadPoolExecutor) Executors.newFixedThreadPool(1), evCacheClientPoolManager);
    FieldUtils.writeField(evCacheClientPool, "numberOfModOps", new AtomicLong(0xFFFF_FFFF_FFFF_FFFFL), true);

    // Set up the method arguments
    EVCacheClient client1 = mock(EVCacheClient.class);
    EVCacheClient client2 = mock(EVCacheClient.class);
    List<EVCacheClient> clientsList = new ArrayList<>();
    clientsList.add(client1);
    clientsList.add(client2);

    // Ensure it's accessible
    // Yes it's private but this is a real bug we fixed.
    Method method = evCacheClientPool.getClass().getDeclaredMethod("selectClient", List.class);
    method.setAccessible(true);

    // Act
    Object ret = method.invoke(evCacheClientPool, clientsList);

    // Assert
    // The number set in numOfModOps should roll over to 0x1_0000_0000_0000_0000
    // so we should get client1 back
    EVCacheClient selected = (EVCacheClient) ret;
    assertSame(selected, client1);
}

From source file:com.adobe.cq.social.cleanup_srp.impl.TestCleanupServlet.java

/**
 * Setup for tests./*w  w  w  . j av  a2  s  .  c om*/
 * @throws IllegalAccessException on failure
 */
@Before
public void setUp() throws IllegalAccessException {
    FieldUtils.writeField(servlet, "socialUtils", socialUtils, true);
    FieldUtils.writeField(servlet, "ugcSearch", ugcSearch, true);

    SocialResourceConfiguration src = Mockito.mock(SocialResourceConfiguration.class);
    Mockito.when(src.getAsiPath()).thenReturn(asiPath);
    Mockito.when(socialUtils.getDefaultStorageConfig()).thenReturn(src);
}

From source file:com.pandich.dropwizard.curator.refresh.FieldRefresher.java

@Override
protected void doWrite(final Field element, final Object value) throws ReflectiveOperationException {
    FieldUtils.writeField(element, this.configuration, value, true);
}