List of usage examples for java.lang.reflect Field getBoolean
@CallerSensitive @ForceInline public boolean getBoolean(Object obj) throws IllegalArgumentException, IllegalAccessException
From source file:org.apache.openjpa.enhance.Reflection.java
/** * Return the value of the given field in the given object. *//* ww w. ja va 2 s . c o m*/ public static boolean getBoolean(Object target, Field field) { if (target == null || field == null) return false; makeAccessible(field, field.getModifiers()); try { return field.getBoolean(target); } catch (Throwable t) { throw wrapReflectionException(t, _loc.get("get-field", target, field)); } }
From source file:org.acoveo.tools.Reflection.java
/** * Return the value of the given field in the given object. *//*w ww . j ava2s . c o m*/ public static boolean getBoolean(Object target, Field field) { if (target == null || field == null) return false; makeAccessible(field, field.getModifiers()); try { return field.getBoolean(target); } catch (Throwable t) { throw wrapReflectionException(t); } }
From source file:org.floens.chan.ui.controller.ThreadSlideController.java
public void onSlidingPaneLayoutStateRestored() { // SlidingPaneLayout does some annoying things for state restoring and incorrectly // tells us if the restored state was open or closed // We need to use reflection to get the private field that stores this correct state boolean restoredOpen = false; try {//from ww w .j a va2s .c o m Field field = SlidingPaneLayout.class.getDeclaredField("mPreservedOpenState"); field.setAccessible(true); restoredOpen = field.getBoolean(slidingPaneLayout); } catch (Exception e) { Logger.e(TAG, "Error getting restored open state with reflection", e); } if (restoredOpen != leftOpen) { leftOpen = restoredOpen; slideStateChanged(leftOpen); } }
From source file:io.teak.sdk.Amazon.java
public void init(Context context) { skuDetailsRequestMap = new HashMap<>(); skuPriceMap = new HashMap<>(); try {//from w w w . j a v a 2 s .com Class<?> purchasingListenerClass = Class.forName("com.amazon.device.iap.PurchasingListener"); InvocationHandler handler = new PurchasingListenerInvocationHandler(); Object proxy = Proxy.newProxyInstance(purchasingListenerClass.getClassLoader(), new Class[] { purchasingListenerClass }, handler); Class<?> purchasingServiceClass = Class.forName("com.amazon.device.iap.PurchasingService"); Method m = purchasingServiceClass.getMethod("registerListener", Context.class, purchasingListenerClass); m.invoke(null, context, proxy); if (Teak.isDebug) { Field sandbox = purchasingServiceClass.getDeclaredField("IS_SANDBOX_MODE"); Log.d(LOG_TAG, "Amazon In-App Purchasing 2.0 registered."); Log.d(LOG_TAG, " Sandbox Mode: " + sandbox.getBoolean(null)); } } catch (Exception e) { Log.e(LOG_TAG, "Reflection error: " + Log.getStackTraceString(e)); Teak.sdkRaven.reportException(e); } }
From source file:com.zlfun.framework.excel.ExcelUtils.java
private static String get(Object obj, Field field) { try {//w w w .j a v a 2 s . c o m if (!field.isAccessible()) { field.setAccessible(true); } if (field.getType() == int.class) { return String.valueOf(field.getInt(obj)); } else if (field.getType() == long.class) { return String.valueOf(field.getLong(obj)); } else if (field.getType() == double.class) { return String.valueOf(field.getDouble(obj)); } else if (field.getType() == byte.class) { return String.valueOf(field.getByte(obj)); } else if (field.getType() == boolean.class) { return String.valueOf(field.getBoolean(obj)); } else if (field.getType() == String.class) { if (field.get(obj) == null) { return ""; } return String.valueOf(field.get(obj)); } else if (field.getType() == Date.class) { if (field.get(obj) == null) { return ""; } return MiscDateUtils.getDateTime((Date) field.get(obj)); } } catch (Exception e) { } return ""; }
From source file:org.assertj.db.common.AbstractTest.java
@Before public void initiate() throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException { Field fieldLastSetup = DbSetupTracker.class.getDeclaredField("lastSetupLaunched"); Field fieldNextLaunch = DbSetupTracker.class.getDeclaredField("nextLaunchSkipped"); fieldLastSetup.setAccessible(true);/*w ww.j a v a 2 s . c o m*/ fieldNextLaunch.setAccessible(true); Boolean nextLaunchSkipped = fieldNextLaunch.getBoolean(dbSetupTracker); DbSetup lastSetupLaunched = (DbSetup) fieldLastSetup.get(dbSetupTracker); boolean skipLaunch = nextLaunchSkipped && DB_SETUP.equals(lastSetupLaunched); LOG.warning("--------------------------------------------------"); LOG.warning(getClass().getCanonicalName() + " - " + testNameRule.getMethodName() + " - skipLaunch : " + skipLaunch + " (" + nextLaunchSkipped + " && " + DB_SETUP.equals(lastSetupLaunched) + ")"); LOG.warning("--------------------------------------------------"); dbSetupTracker.launchIfNecessary(DB_SETUP); }
From source file:com.blackducksoftware.integration.hub.jenkins.site.BlackDuckHubUpdateSite.java
private FormValidation updateData(final String json, boolean signatureCheck) throws IOException { setDataTimestamp(System.currentTimeMillis()); final JSONObject o = JSONObject.fromObject(json); final int v = o.getInt("updateCenterVersion"); if (v != 1) { throw new IllegalArgumentException("Unrecognized update center version: " + v); }//from www. ja v a 2 s . c o m try { final Field signatureCheckField = UpdateSite.class.getField("signatureCheck"); signatureCheck = signatureCheckField.getBoolean(null); } catch (final Throwable t) { // ignore } if (signatureCheck) { final FormValidation e = verifySignature(o); if (e.kind != FormValidation.Kind.OK) { LOGGER.severe(e.renderHtml()); return e; } } LOGGER.info("Obtained the latest update center data file for Black Duck UpdateSource " + getId()); getDataFile().write(json); return FormValidation.ok(); }
From source file:net.larry1123.elec.util.test.config.AbstractConfigTest.java
public void booleanTest(String fieldName, Field testField) { try {//from w w w . jav a2 s. c o m Assert.assertTrue((getPropertiesFile().getBoolean(fieldName) == testField.getBoolean(getConfigBase()))); } catch (IllegalAccessException e) { assertFailFieldError(fieldName); } }
From source file:com.cloudbees.jenkins.plugins.enterpriseplugins.CloudBeesUpdateSite.java
/** * This is the endpoint that receives the update center data file from the browser. * Mirrors {@link UpdateSite#doPostBack(org.kohsuke.stapler.StaplerRequest)} as there is no other way to override * the verification of the signature.// w w w. j a v a 2 s. c om */ @Override public FormValidation doPostBack(StaplerRequest req) throws IOException, GeneralSecurityException { setDataTimestamp(System.currentTimeMillis()); String json = hudson.util.IOUtils.toString(req.getInputStream(), "UTF-8"); JSONObject o = JSONObject.fromObject(json); int v = o.getInt("updateCenterVersion"); if (v != 1) { throw new IllegalArgumentException("Unrecognized update center version: " + v); } boolean signatureCheck = true; try { Field signatureCheckField = UpdateSite.class.getField("signatureCheck"); signatureCheck = signatureCheckField.getBoolean(null); } catch (Throwable t) { // ignore } if (signatureCheck) { FormValidation e = verifySignature(o); if (e.kind != FormValidation.Kind.OK) { LOGGER.severe(e.renderHtml()); return e; } } LOGGER.info("Obtained the latest update center data file for UpdateSource " + getId()); getDataFile().write(json); return FormValidation.ok(); }
From source file:org.dcm4che2.tool.dcm2dcm.Dcm2Dcm.java
/** * Check if a reader is reading compressed data */// w w w . j a v a 2 s . co m private boolean isCompressed(ImageReader reader) throws NoSuchFieldException, IllegalAccessException { Class<?> clazz = reader.getClass(); java.lang.reflect.Field compressed = clazz.getDeclaredField("compressed"); compressed.setAccessible(true); return compressed.getBoolean(reader); }