List of usage examples for org.apache.commons.lang3.reflect FieldUtils readDeclaredField
public static Object readDeclaredField(final Object target, final String fieldName, final boolean forceAccess) throws IllegalAccessException
From source file:jp.ryoyamamoto.poiutils.Sheets.java
/** * Gets the hyperlinks on the sheet./*ww w .j a v a2s. com*/ * * @param sheet * the sheet. * @return the hyperlinks on the sheet. */ @SuppressWarnings("unchecked") public static List<Hyperlink> getHyperlinks(Sheet sheet) { try { return (List<Hyperlink>) FieldUtils.readDeclaredField(sheet, "hyperlinks", true); } catch (IllegalAccessException e) { e.printStackTrace(); } return Collections.emptyList(); }
From source file:com.devaholic.android.test.activities.camera.CameraThroughAPITest.java
private void checkCameraPreviewIsNotStarted(CameraThroughAPI cameraThroughAPI) throws IllegalAccessException { Boolean isCameraStarted = (Boolean) FieldUtils.readDeclaredField(cameraThroughAPI, "isCameraStarted", true); assertThat("the Camera preview should not be started at this point", !isCameraStarted); }
From source file:com.devaholic.android.test.activities.camera.CameraThroughAPITest.java
private void checkCameraPreviewIsStarted(CameraThroughAPI cameraThroughAPI) throws IllegalAccessException { boolean isCameraStarted = (Boolean) FieldUtils.readDeclaredField(cameraThroughAPI, "isCameraStarted", true); assertThat("the Camera preview should be started at this point", isCameraStarted); }
From source file:com.devaholic.android.test.activities.camera.CameraThroughAPITest.java
/** * Open Camera test//from w ww . ja v a2s .com */ @Test public void openCameraTest() throws IllegalAccessException { CameraThroughAPI cameraThroughAPI = (CameraThroughAPI) controller.get(); checkCameraPreviewIsNotStarted(cameraThroughAPI); ImageView imgView = (ImageView) FieldUtils.readDeclaredField(cameraThroughAPI, "imgView", true); assertThat("Image viewer for the picture should be null at this point", imgView, nullValue()); CameraSurface cameraSurface = (CameraSurface) FieldUtils.readDeclaredField(cameraThroughAPI, "cameraSurface", true); assertThat("CameraSurface should not be started", cameraSurface, nullValue()); cameraThroughAPI = (CameraThroughAPI) controller.create().get(); checkCameraPreviewIsNotStarted(cameraThroughAPI); imgView = (ImageView) FieldUtils.readDeclaredField(cameraThroughAPI, "imgView", true); assertThat("There is no image viewer for the picture", imgView, notNullValue()); cameraSurface = (CameraSurface) FieldUtils.readDeclaredField(cameraThroughAPI, "cameraSurface", true); assertThat("CameraSurface did not start", cameraSurface, notNullValue()); }
From source file:com.berniesanders.fieldthebern.views.MapScreenView.java
private void injectSelf(Context context) { //This is a hack to safely get a reference to the activity. //Flow is internally already passing around the references in a private Map<Path,Context> //So we use a little hacky reflection tool to steal the activity ref //but hold it in a weak ref //TODO: we could probably change this to a "controller" PathContext pathContext = (PathContext) context; Map<Path, Context> contextMap = new HashMap<>(); try {/* w w w . j a va 2 s. c o m*/ contextMap = (Map<Path, Context>) FieldUtils.readDeclaredField(context, "contexts", true); } catch (IllegalAccessException e) { Timber.e(e, "error reading path contexts..."); e.printStackTrace(); } for (Context ctx : contextMap.values()) { if (ctx instanceof Activity) { Timber.v("We found an activity!"); activityWeakReference = new WeakReference<>((Activity) ctx); } } DaggerService.<MapScreen.Component>getDaggerComponent(context, DaggerService.DAGGER_SERVICE).inject(this); }
From source file:com.salesforce.ide.apex.internal.core.CompilerService.java
/** * This is temporary workaround to bypass the validation stage of the compiler while *still* doing the * additional_validate stage. We are bypassing the validation stage because it does a deep validation that we don't * have all the parts for yet in the offline compiler. Rather than stop all work on that, we bypass it so that we * can still do useful things like find all your types, find all your methods, etc. * //from ww w . ja va2s . c o m */ @SuppressWarnings("unchecked") private void callAdditionalPassVisitor(ApexCompiler compiler) { try { List<CodeUnit> allUnits = (List<CodeUnit>) FieldUtils.readDeclaredField(compiler, "allUnits", true); CompilerContext compilerContext = (CompilerContext) FieldUtils.readDeclaredField(compiler, "compilerContext", true); for (CodeUnit unit : allUnits) { Method getOperation = CompilerStage.ADDITIONAL_VALIDATE.getDeclaringClass() .getDeclaredMethod("getOperation"); getOperation.setAccessible(true); CompilerOperation operation = (CompilerOperation) getOperation .invoke(CompilerStage.ADDITIONAL_VALIDATE); operation.invoke(compilerContext, unit); } } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { logger.error("Failed to inokve additional validator", e); } }
From source file:io.openmessaging.rocketmq.consumer.LocalMessageCache.java
private ReadWriteLock getLockInProcessQueue(ProcessQueue pq) { try {/* w w w . j ava2s. c o m*/ return (ReadWriteLock) FieldUtils.readDeclaredField(pq, "lockTreeMap", true); } catch (IllegalAccessException e) { return null; } }
From source file:com.frank.search.solr.core.ResultHelper.java
private static Object getMappedId(Object o) { if (ClassUtils.hasProperty(o.getClass(), "id")) { try {/*w ww . jav a2 s . c o m*/ return FieldUtils.readDeclaredField(o, "id", true); } catch (IllegalAccessException e) { throw new MappingException("Id property could not be accessed!", e); } } for (java.lang.reflect.Field field : o.getClass().getDeclaredFields()) { Annotation annotation = AnnotationUtils.getAnnotation(field, Id.class); if (annotation != null) { try { return FieldUtils.readField(field, o, true); } catch (IllegalArgumentException e) { throw new MappingException("Id property could not be accessed!", e); } catch (IllegalAccessException e) { throw new MappingException("Id property could not be accessed!", e); } } } throw new MappingException("Id property could not be found!"); }
From source file:com.gargoylesoftware.htmlunit.HttpWebConnection.java
/** * Has the exact logic in HttpClientBuilder, but with the ability to configure * <code>socketFactory</code>. *///from w w w . j ava 2 s . c o m private PoolingHttpClientConnectionManager createConnectionManager(final HttpClientBuilder builder) { final ConnectionSocketFactory socketFactory = new SocksConnectionSocketFactory(); LayeredConnectionSocketFactory sslSocketFactory; try { sslSocketFactory = (LayeredConnectionSocketFactory) FieldUtils.readDeclaredField(builder, "sslSocketFactory", true); final SocketConfig defaultSocketConfig = (SocketConfig) FieldUtils.readDeclaredField(builder, "defaultSocketConfig", true); final ConnectionConfig defaultConnectionConfig = (ConnectionConfig) FieldUtils .readDeclaredField(builder, "defaultConnectionConfig", true); final boolean systemProperties = (Boolean) FieldUtils.readDeclaredField(builder, "systemProperties", true); final int maxConnTotal = (Integer) FieldUtils.readDeclaredField(builder, "maxConnTotal", true); final int maxConnPerRoute = (Integer) FieldUtils.readDeclaredField(builder, "maxConnPerRoute", true); HostnameVerifier hostnameVerifier = (HostnameVerifier) FieldUtils.readDeclaredField(builder, "hostnameVerifier", true); final SSLContext sslcontext = (SSLContext) FieldUtils.readDeclaredField(builder, "sslContext", true); if (sslSocketFactory == null) { final String[] supportedProtocols = systemProperties ? StringUtils.split(System.getProperty("https.protocols"), ',') : null; final String[] supportedCipherSuites = systemProperties ? StringUtils.split(System.getProperty("https.cipherSuites"), ',') : null; if (hostnameVerifier == null) { hostnameVerifier = SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER; } if (sslcontext != null) { sslSocketFactory = new SSLConnectionSocketFactory(sslcontext, supportedProtocols, supportedCipherSuites, hostnameVerifier); } else { if (systemProperties) { sslSocketFactory = new SSLConnectionSocketFactory( (SSLSocketFactory) SSLSocketFactory.getDefault(), supportedProtocols, supportedCipherSuites, hostnameVerifier); } else { sslSocketFactory = new SSLConnectionSocketFactory(SSLContexts.createDefault(), hostnameVerifier); } } } final PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager( RegistryBuilder.<ConnectionSocketFactory>create().register("http", socketFactory) .register("https", sslSocketFactory).build()); if (defaultSocketConfig != null) { connectionManager.setDefaultSocketConfig(defaultSocketConfig); } if (defaultConnectionConfig != null) { connectionManager.setDefaultConnectionConfig(defaultConnectionConfig); } if (systemProperties) { String s = System.getProperty("http.keepAlive", "true"); if ("true".equalsIgnoreCase(s)) { s = System.getProperty("http.maxConnections", "5"); final int max = Integer.parseInt(s); connectionManager.setDefaultMaxPerRoute(max); connectionManager.setMaxTotal(2 * max); } } if (maxConnTotal > 0) { connectionManager.setMaxTotal(maxConnTotal); } if (maxConnPerRoute > 0) { connectionManager.setDefaultMaxPerRoute(maxConnPerRoute); } return connectionManager; } catch (final IllegalAccessException e) { throw new RuntimeException(e); } }
From source file:net.sourceforge.pmd.lang.apex.ast.CompilerService.java
/** * This is temporary workaround to bypass the validation stage of the * compiler while *still* doing the additional_validate stage. We are * bypassing the validation stage because it does a deep validation that we * don't have all the parts for yet in the offline compiler. Rather than * stop all work on that, we bypass it so that we can still do useful things * like find all your types, find all your methods, etc. * *//*from www. j a va 2 s . c o m*/ @SuppressWarnings("unchecked") private void callAdditionalPassVisitor(ApexCompiler compiler) { try { List<CodeUnit> allUnits = (List<CodeUnit>) FieldUtils.readDeclaredField(compiler, "allUnits", true); CompilerContext compilerContext = (CompilerContext) FieldUtils.readDeclaredField(compiler, "compilerContext", true); for (CodeUnit unit : allUnits) { Method getOperation = CompilerStage.ADDITIONAL_VALIDATE.getDeclaringClass() .getDeclaredMethod("getOperation"); getOperation.setAccessible(true); CompilerOperation operation = (CompilerOperation) getOperation .invoke(CompilerStage.ADDITIONAL_VALIDATE); operation.invoke(compilerContext, unit); } } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new RuntimeException(e); } }