コード例 #1
0
ファイル: JAWTUtil.java プロジェクト: rothwell/jogl
  static {
    JAWTJNILibLoader.loadAWTImpl();
    JAWTJNILibLoader.loadNativeWindow("awt");

    headlessMode = GraphicsEnvironment.isHeadless();

    boolean ok = false;
    Class jC = null;
    Method m = null;
    if (!headlessMode) {
      try {
        jC = Class.forName("com.jogamp.opengl.impl.awt.Java2D");
        m = jC.getMethod("isQueueFlusherThread", null);
        ok = true;
      } catch (Exception e) {
      }
    }
    j2dClazz = jC;
    isQueueFlusherThread = m;
    j2dExist = ok;

    AccessController.doPrivileged(
        new PrivilegedAction() {
          public Object run() {
            try {
              sunToolkitClass = Class.forName("sun.awt.SunToolkit");
              sunToolkitAWTLockMethod =
                  sunToolkitClass.getDeclaredMethod("awtLock", new Class[] {});
              sunToolkitAWTLockMethod.setAccessible(true);
              sunToolkitAWTUnlockMethod =
                  sunToolkitClass.getDeclaredMethod("awtUnlock", new Class[] {});
              sunToolkitAWTUnlockMethod.setAccessible(true);
            } catch (Exception e) {
              // Either not a Sun JDK or the interfaces have changed since 1.4.2 / 1.5
            }
            return null;
          }
        });
    boolean _hasSunToolkitAWTLock = false;
    if (null != sunToolkitAWTLockMethod && null != sunToolkitAWTUnlockMethod) {
      try {
        sunToolkitAWTLockMethod.invoke(null, null);
        sunToolkitAWTUnlockMethod.invoke(null, null);
        _hasSunToolkitAWTLock = true;
      } catch (Exception e) {
      }
    }
    hasSunToolkitAWTLock = _hasSunToolkitAWTLock;
    // useSunToolkitAWTLock = hasSunToolkitAWTLock;
    useSunToolkitAWTLock = false;
  }
コード例 #2
0
  public static final void main(String[] args) throws Exception {

    // Generate a PBE key
    SecretKeyFactory skFac = SecretKeyFactory.getInstance("PBE");
    SecretKey skey = skFac.generateSecret(new PBEKeySpec("test123".toCharArray()));

    // Initialize the PBE cipher
    Cipher cipher = Cipher.getInstance(ALGO);
    cipher.init(Cipher.ENCRYPT_MODE, skey);

    // Permit access to the Cipher.spi field (a CipherSpi object)
    Field spi = Cipher.class.getDeclaredField("spi");
    spi.setAccessible(true);
    Object value = spi.get(cipher);

    // Permit access to the CipherSpi.engineGetKeySize method
    Method engineGetKeySize =
        PKCS12PBECipherCore$PBEWithSHA1AndDESede.class.getDeclaredMethod(
            "engineGetKeySize", Key.class);
    engineGetKeySize.setAccessible(true);

    // Check the key size
    int keySize = (int) engineGetKeySize.invoke(value, skey);
    if (keySize == KEYSIZE) {
      System.out.println(ALGO + ".engineGetKeySize returns " + keySize + " bits, as expected");
      System.out.println("OK");
    } else {
      throw new Exception("ERROR: " + ALGO + " key size is incorrect");
    }
  }
コード例 #3
0
ファイル: InAppServer.java プロジェクト: orph/jujitsu
  private boolean invokeMethod(String line, PrintWriter out, Method method, String[] fields)
      throws IllegalAccessException, InvocationTargetException {
    ArrayList<Object> methodArguments = new ArrayList<Object>();

    Class<?>[] parameterTypes = method.getParameterTypes();
    if (parameterTypes.length == 2
        && parameterTypes[0] == PrintWriter.class
        && parameterTypes[1] == String.class) {
      // FIXME: there must be a better way to say "I want to parse the line myself."
      methodArguments.add(out);
      methodArguments.add(line);
    } else {
      int nextField = 1;
      for (Class<?> parameterType : parameterTypes) {
        if (parameterType == PrintWriter.class) {
          methodArguments.add(out);
        } else if (parameterType == String.class) {
          methodArguments.add(fields[nextField++]);
        }
        // FIXME: support other common types. "int" seems a likely first candidate.
      }
    }

    method.invoke(handler, methodArguments.toArray());
    return true;
  }
コード例 #4
0
ファイル: JAWTUtil.java プロジェクト: rothwell/jogl
 public static final boolean isJava2DQueueFlusherThread() {
   boolean b = false;
   if (j2dExist) {
     try {
       b = ((Boolean) isQueueFlusherThread.invoke(null, null)).booleanValue();
     } catch (Exception e) {
     }
   }
   return b;
 }
コード例 #5
0
ファイル: JAWTUtil.java プロジェクト: rothwell/jogl
 private static void awtUnlock() {
   if (useSunToolkitAWTLock) {
     try {
       sunToolkitAWTUnlockMethod.invoke(null, null);
     } catch (Exception e) {
       throw new NativeWindowException("SunToolkit.awtUnlock failed", e);
     }
   } else {
     JAWT.getJAWT().Unlock();
   }
 }
コード例 #6
0
ファイル: GTKStyle.java プロジェクト: susotajuraj/jdk8u-jdk
    public Object createValue(UIDefaults table) {
      try {
        Class c = Class.forName(className, true, Thread.currentThread().getContextClassLoader());

        if (methodName == null) {
          return c.newInstance();
        }
        Method m = c.getMethod(methodName, (Class[]) null);

        return m.invoke(c, (Object[]) null);
      } catch (ClassNotFoundException cnfe) {
      } catch (IllegalAccessException iae) {
      } catch (InvocationTargetException ite) {
      } catch (NoSuchMethodException nsme) {
      } catch (InstantiationException ie) {
      }
      return null;
    }
コード例 #7
0
  /**
   * Gets the features of a specific <tt>DiscoverInfo</tt> in the form of a read-only
   * <tt>Feature</tt> <tt>Iterator<tt/> by calling the internal method {@link
   * DiscoverInfo#getFeatures()}.
   *
   * @param discoverInfo the <tt>DiscoverInfo</tt> the features of which are to be retrieved
   * @return a read-only <tt>Feature</tt> <tt>Iterator</tt> which lists the features of the
   *     specified <tt>discoverInfo</tt>
   */
  @SuppressWarnings("unchecked")
  private static Iterator<DiscoverInfo.Feature> getDiscoverInfoFeatures(DiscoverInfo discoverInfo) {
    Method getFeaturesMethod;

    try {
      getFeaturesMethod = DiscoverInfo.class.getDeclaredMethod("getFeatures");
    } catch (NoSuchMethodException nsmex) {
      throw new UndeclaredThrowableException(nsmex);
    }
    getFeaturesMethod.setAccessible(true);
    try {
      return (Iterator<DiscoverInfo.Feature>) getFeaturesMethod.invoke(discoverInfo);
    } catch (IllegalAccessException iaex) {
      throw new UndeclaredThrowableException(iaex);
    } catch (InvocationTargetException itex) {
      throw new UndeclaredThrowableException(itex);
    }
  }