Java Class.getDeclaredField Examples

Java Class.getDeclaredField - 30 examples found. These are the top rated real world Java examples of Class.getDeclaredField extracted from open source projects. You can rate examples to help us improve the quality of examples.
  private static void removeCryptographyRestrictions() {
    if (!isRestrictedCryptography()) {
      return;
    }
    try {
      final Class<?> jceSecurity = Class.forName("javax.crypto.JceSecurity");
      final Class<?> cryptoPermissions = Class.forName("javax.crypto.CryptoPermissions");
      final Class<?> cryptoAllPermission = Class.forName("javax.crypto.CryptoAllPermission");

      final Field isRestrictedField = jceSecurity.getDeclaredField("isRestricted");
      isRestrictedField.setAccessible(true);
      isRestrictedField.set(null, false);

      final Field defaultPolicyField = jceSecurity.getDeclaredField("defaultPolicy");
      defaultPolicyField.setAccessible(true);
      final PermissionCollection defaultPolicy =
          (PermissionCollection) defaultPolicyField.get(null);

      final Field perms = cryptoPermissions.getDeclaredField("perms");
      perms.setAccessible(true);
      ((Map<?, ?>) perms.get(defaultPolicy)).clear();

      final Field instance = cryptoAllPermission.getDeclaredField("INSTANCE");
      instance.setAccessible(true);
      defaultPolicy.add((Permission) instance.get(null));

    } catch (final Exception e) {

    }
  }
Example #2
0
    private static boolean isSetException(Score score)
        throws NoSuchMethodException, NoSuchFieldException, IllegalAccessException,
            InvocationTargetException {
      Object craftScore = CRAFT_SCORE.cast(score);

      Object craftObjective = CRAFT_OBJECTIVE.cast(score.getObjective());
      Method craftHandle = CRAFT_OBJECTIVE.getDeclaredMethod("getHandle");
      craftHandle.setAccessible(true);
      Object craftObjectiveHandle = craftHandle.invoke(craftObjective);

      Field objective = CRAFT_SCORE.getDeclaredField("objective");
      objective.setAccessible(true);
      Object craftScoreboard = checkState(objective.get(craftScore));

      Field craftBoard = CRAFT_SCOREBOARD.getDeclaredField("board");
      craftBoard.setAccessible(true);
      Object scoreboard = craftBoard.get(craftScoreboard);
      Method playerObjectives = SCOREBOARD.getDeclaredMethod("getPlayerObjectives", String.class);
      playerObjectives.setAccessible(true);

      Field playerField = CRAFT_SCORE.getDeclaredField("entry");
      playerField.setAccessible(true);
      String playerName = (String) playerField.get(craftScore);
      Map map = (Map) playerObjectives.invoke(scoreboard, playerName);

      // return
      // objective.checkState().board.getPlayerObjectives(playerName).containsKey(objective.getHandle());
      return map.containsKey(craftObjectiveHandle);
    }
  @Override
  protected boolean installInterestFilter(StructuredViewer viewer) {
    if (commonNavigator == null) {
      commonNavigator = (CommonNavigator) super.getPartForAction();
    }

    try {
      // XXX: reflection
      Class<?> clazz2 = CoreExpressionFilter.class;
      filterExpressionField1 = clazz2.getDeclaredField("filterExpression"); // $NON-NLS-1$
      filterExpressionField1.setAccessible(true);

      Class<?> clazz1 = CommonFilterDescriptor.class;
      filterExpressionField2 = clazz1.getDeclaredField("filterExpression"); // $NON-NLS-1$
      filterExpressionField2.setAccessible(true);
    } catch (Exception e) {
      StatusHandler.log(
          new Status(
              IStatus.ERROR,
              ResourcesUiBridgePlugin.ID_PLUGIN,
              "Could not determine filter",
              e)); //$NON-NLS-1$
    }

    filterDescriptors =
        CommonFilterDescriptorManager.getInstance()
            .findVisibleFilters(commonNavigator.getNavigatorContentService());

    return super.installInterestFilter(viewer);
  }
  private void initializePluginAPI(TiWebView webView) {
    try {
      synchronized (this.getClass()) {
        // Initialize
        if (enumPluginStateOff == null) {
          Class<?> webSettings = Class.forName("android.webkit.WebSettings");
          Class<?> pluginState = Class.forName("android.webkit.WebSettings$PluginState");

          Field f = pluginState.getDeclaredField("OFF");
          enumPluginStateOff = (Enum<?>) f.get(null);
          f = pluginState.getDeclaredField("ON");
          enumPluginStateOn = (Enum<?>) f.get(null);
          f = pluginState.getDeclaredField("ON_DEMAND");
          enumPluginStateOnDemand = (Enum<?>) f.get(null);
          internalSetPluginState = webSettings.getMethod("setPluginState", pluginState);
          // Hidden APIs
          // http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/webkit/WebView.java;h=bbd8b95c7bea66b7060b5782fae4b3b2c4f04966;hb=4db1f432b853152075923499768639e14403b73a#l2558
          internalWebViewPause = webView.getClass().getMethod("onPause");
          internalWebViewResume = webView.getClass().getMethod("onResume");
        }
      }
    } catch (ClassNotFoundException e) {
      Log.e(TAG, "ClassNotFound: " + e.getMessage(), e);
    } catch (NoSuchMethodException e) {
      Log.e(TAG, "NoSuchMethod: " + e.getMessage(), e);
    } catch (NoSuchFieldException e) {
      Log.e(TAG, "NoSuchField: " + e.getMessage(), e);
    } catch (IllegalAccessException e) {
      Log.e(TAG, "IllegalAccess: " + e.getMessage(), e);
    }
  }
Example #5
0
  public static void cancelListViewBounceShadow(ListView listView) {
    try {
      Class<?> c = (Class<?>) Class.forName(AbsListView.class.getName());
      Field egtField = c.getDeclaredField("mEdgeGlowTop");
      Field egbBottom = c.getDeclaredField("mEdgeGlowBottom");
      egtField.setAccessible(true);
      egbBottom.setAccessible(true);
      Object egtObject = egtField.get(listView); // this 指的是ListiVew实例
      Object egbObject = egbBottom.get(listView);

      // egtObject.getClass() 实际上是一个 EdgeEffect 其中有两个重要属性 mGlow mEdge
      // 并且这两个属性都是Drawable类型
      Class<?> cc = (Class<?>) Class.forName(egtObject.getClass().getName());
      Field mGlow = cc.getDeclaredField("mGlow");
      mGlow.setAccessible(true);
      mGlow.set(egtObject, new ColorDrawable(Color.TRANSPARENT));
      mGlow.set(egbObject, new ColorDrawable(Color.TRANSPARENT));

      Field mEdge = cc.getDeclaredField("mEdge");
      mEdge.setAccessible(true);
      mEdge.set(egtObject, new ColorDrawable(Color.TRANSPARENT));
      mEdge.set(egbObject, new ColorDrawable(Color.TRANSPARENT));
    } catch (Exception e) {

    }
  }
Example #6
0
  public TextureLiquidsFX(
      int redMin,
      int redMax,
      int greenMin,
      int greenMax,
      int blueMin,
      int blueMax,
      int spriteIndex,
      String texture) {
    super(spriteIndex);

    try {
      Class<? extends Object> sizeClass = Class.forName("com.pclewis.mcpatcher.mod.TileSize");

      int_numPixels = sizeClass.getDeclaredField("int_numPixels").getInt(sizeClass);
      int_size = sizeClass.getDeclaredField("int_size").getInt(sizeClass);
      int_sizeMinus1 = sizeClass.getDeclaredField("int_sizeMinus1").getInt(sizeClass);
    } catch (Throwable t) {

    }

    this.redMin = redMin;
    this.redMax = redMax;
    this.greenMin = greenMin;
    this.greenMax = greenMax;
    this.blueMin = blueMin;
    this.blueMax = blueMax;
    this.texture = texture;

    field_1158_g = new float[int_numPixels];
    field_1157_h = new float[int_numPixels];
    field_1156_i = new float[int_numPixels];
    field_1155_j = new float[int_numPixels];
  }