Java Class.getMethod Examples

Java Class.getMethod - 30 examples found. These are the top rated real world Java examples of Class.getMethod extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
  @Override
  protected void actionPerformed(GuiButton guiButton) {
    if (guiButton.enabled) {
      if (guiButton.id == this.btnOpenDir.id) {
        boolean success = false;

        try {
          Class c = Class.forName("java.awt.Desktop");
          Object m = c.getMethod("getDesktop", new Class[0]).invoke((Object) null, new Object[0]);
          c.getMethod("browse", new Class[] {URI.class})
              .invoke(m, new Object[] {Settings.schematicDirectory.toURI()});
        } catch (Throwable e) {
          success = true;
        }

        if (success) {
          Settings.logger.logInfo("Opening via Sys class!");
          Sys.openURL("file://" + Settings.schematicDirectory.getAbsolutePath());
        }
      } else if (guiButton.id == this.btnDone.id) {
        loadSchematic();
        this.mc.displayGuiScreen(this.prevGuiScreen);
      } else {
        this.guiSchematicLoadSlot.actionPerformed(guiButton);
      }
    }
  }
Example #2
0
  static {
    try {
      final Properties properties = new Properties();
      try (InputStream byteSource =
          ShopConnector.class.getResourceAsStream("shop-mysql.properties")) {
        properties.load(byteSource);
      }

      final Class<?> dataSourceClass =
          Class.forName(
              "com.mysql.jdbc.jdbc2.optional.MysqlDataSource",
              true,
              Thread.currentThread().getContextClassLoader());
      final DataSource dataSource = (DataSource) dataSourceClass.newInstance();
      dataSourceClass
          .getMethod("setURL", String.class)
          .invoke(dataSource, properties.get("connectionUrl"));
      dataSourceClass
          .getMethod("setCharacterEncoding", String.class)
          .invoke(dataSource, properties.get("characterEncoding"));
      dataSourceClass
          .getMethod("setUser", String.class)
          .invoke(dataSource, properties.get("alias"));
      dataSourceClass
          .getMethod("setPassword", String.class)
          .invoke(dataSource, properties.get("password"));
      DATA_SOURCE = dataSource;
    } catch (final Exception exception) {
      throw new ExceptionInInitializerError(exception);
    }
  }
Example #3
0
  static {
    Class<Object> clazz;

    logger = LoggerManager.getLogger(Base64.class.getName());

    try {
      clazz = (Class<Object>) Class.forName("android.util.Base64");
      // Looking for encode( byte[] input, int flags)
      aMethod = clazz.getMethod("encode", byte[].class, Integer.TYPE);
      logger.info(clazz.getName() + " is available.");
    } catch (ClassNotFoundException x) {
    } // Ignore
    catch (Exception x) {
      logger.error("Failed to initialize use of android.util.Base64", x);
    }

    try {
      clazz = (Class<Object>) Class.forName("org.bouncycastle.util.encoders.Base64Encoder");
      bEncoder = clazz.newInstance();
      // Looking for encode( byte[] input, int offset, int length, OutputStream output)
      bMethod =
          clazz.getMethod("encode", byte[].class, Integer.TYPE, Integer.TYPE, OutputStream.class);
      logger.info(clazz.getName() + " is available.");
    } catch (ClassNotFoundException x) {
    } // Ignore
    catch (Exception x) {
      logger.error("Failed to initialize use of org.bouncycastle.util.encoders.Base64Encoder", x);
    }

    if (aMethod == null && bMethod == null)
      throw new IllegalStateException("No base64 encoder implementation is available.");
  }
  public void setParameterValues(Properties parameters) {
    String enumClassName = parameters.getProperty("enumClass");
    try {
      enumClass = Class.forName(enumClassName).asSubclass(Enum.class);
    } catch (ClassNotFoundException cfne) {
      throw new HibernateException("Enum class not found", cfne);
    }

    String identifierMethodName =
        parameters.getProperty("identifierMethod", DEFAULT_IDENTIFIER_METHOD_NAME);

    try {
      identifierMethod = enumClass.getMethod(identifierMethodName, new Class[0]);
      identifierType = identifierMethod.getReturnType();
    } catch (Exception e) {
      throw new HibernateException("Failed to obtain identifier method", e);
    }

    type = (NullableType) TypeFactory.basic(identifierType.getName());

    if (type == null)
      throw new HibernateException("Unsupported identifier type " + identifierType.getName());

    sqlTypes = new int[] {type.sqlType()};

    String valueOfMethodName =
        parameters.getProperty("valueOfMethod", DEFAULT_VALUE_OF_METHOD_NAME);

    try {
      valueOfMethod = enumClass.getMethod(valueOfMethodName, new Class[] {identifierType});
    } catch (Exception e) {
      throw new HibernateException("Failed to obtain valueOf method", e);
    }
  }
  private void calculateWrapSize(Rectangle bounds) {
    if (myWrapSize.width == -1 || myWrapSize.height == -1) {
      try {
        Object viewObject = myComponent.getViewInfo().getViewObject();
        Class<?> viewClass = viewObject.getClass();

        viewClass.getMethod("forceLayout").invoke(viewObject);
        viewClass
            .getMethod("measure", int.class, int.class)
            .invoke(viewObject, WRAP_CONTENT, WRAP_CONTENT);

        if (myWrapSize.width == -1) {
          myWrapSize.width = (Integer) viewClass.getMethod("getMeasuredWidth").invoke(viewObject);
        }
        if (myWrapSize.height == -1) {
          myWrapSize.height = (Integer) viewClass.getMethod("getMeasuredHeight").invoke(viewObject);
        }
      } catch (Throwable e) {
        if (myWrapSize.width == -1) {
          myWrapSize.width = bounds.width;
        }
        if (myWrapSize.height == -1) {
          myWrapSize.height = bounds.height;
        }
      }
    }
  }
  /**
   * @param context
   * @param simpleOnScaleGestureListener
   */
  public ScaleGestureDetector(
      Context context, SimpleOnScaleGestureListener simpleOnScaleGestureListener) {
    try {
      // check if class is available
      Class.forName("android.view.ScaleGestureDetector");

      // load class and methods
      Class<?> classRealScaleGestureDetector =
          Class.forName("com.jjoe64.graphview.compatible.RealScaleGestureDetector");
      method_getScaleFactor = classRealScaleGestureDetector.getMethod("getScaleFactor");
      method_isInProgress = classRealScaleGestureDetector.getMethod("isInProgress");
      method_onTouchEvent =
          classRealScaleGestureDetector.getMethod("onTouchEvent", MotionEvent.class);

      // create real ScaleGestureDetector
      Constructor<?> constructor =
          classRealScaleGestureDetector.getConstructor(
              Context.class, getClass(), SimpleOnScaleGestureListener.class);
      realScaleGestureDetector =
          constructor.newInstance(context, this, simpleOnScaleGestureListener);
    } catch (Exception e) {
      // not available
      Log.w("com.jjoe64.graphview", "*** WARNING *** No scaling available for graphs. Exception:");
      e.printStackTrace();
    }
  }