コード例 #1
0
ファイル: MappingUtils.java プロジェクト: hbaojun/midao
  /**
   * Checks if Instance extends specified Class {@link Class#isAssignableFrom(Class)} is not used as
   * Class might not be available and String representation can only be used
   *
   * @param object Instance which would be checked
   * @param superClassName Class with which it would be checked
   * @return true if Instance extends specified Parent
   */
  public static boolean objectExtends(Object object, String superClassName) {
    AssertUtils.assertNotNull(object);

    boolean result = false;

    Class superClass = object.getClass().getSuperclass();

    if (superClass.getName().equals(superClassName) == true) {
      result = true;
    }

    return result;
  }
コード例 #2
0
ファイル: MappingUtils.java プロジェクト: hbaojun/midao
  /**
   * Checks if instance is of specified class
   *
   * @param object Instance which would be checked
   * @param className Class name with which it would be checked
   * @return true if Instance is of specified class
   */
  public static boolean objectInstanceOf(Object object, String className) {
    AssertUtils.assertNotNull(object);

    boolean result = false;

    Class clazz = object.getClass();

    if (clazz.getName().equals(className) == true) {
      result = true;
    }

    return result;
  }
コード例 #3
0
ファイル: MappingUtils.java プロジェクト: hbaojun/midao
  /**
   * Checks if Instance implements specified Interface {@link Class#isAssignableFrom(Class)} is not
   * used as Interface might not be available and String representation can only be used
   *
   * @param object Instance which would be checked
   * @param interfaceClass Interface with which it would be checked
   * @return true if Instance implements specified Interface
   */
  public static boolean objectImplements(Object object, String interfaceClass) {
    AssertUtils.assertNotNull(object);

    boolean result = false;

    Class[] interfaces = object.getClass().getInterfaces();
    for (int i = 0; i < interfaces.length; i++) {
      if (interfaces[i].getName().equals(interfaceClass) == true) {
        result = true;
        break;
      }
    }

    return result;
  }
コード例 #4
0
ファイル: MappingUtils.java プロジェクト: hbaojun/midao
  /**
   * Checks if instance can be cast to specified Class
   *
   * @param object Instance which would be checked
   * @param className Class name with which it would be checked
   * @return true if Instance can be cast to specified class
   * @throws org.midao.jdbc.core.exception.MjdbcException
   */
  public static boolean objectAssignableTo(Object object, String className) throws MjdbcException {
    AssertUtils.assertNotNull(object);

    boolean result = false;

    Class clazz = null;
    try {
      clazz = Class.forName(className);
    } catch (ClassNotFoundException ex) {
      throw new MjdbcException(ex);
    }

    result = clazz.isAssignableFrom(object.getClass());

    return result;
  }
コード例 #5
0
ファイル: MappingUtils.java プロジェクト: hbaojun/midao
  /**
   * Returns class field value Is used to return Constants
   *
   * @param object Class field of which would be returned
   * @param fieldName field name
   * @return field value
   * @throws org.midao.jdbc.core.exception.MjdbcException if field is not present or access is
   *     prohibited
   */
  public static Object returnField(Object object, String fieldName) throws MjdbcException {
    AssertUtils.assertNotNull(object);

    Object result = null;

    Field field = null;
    try {
      field = object.getClass().getField(fieldName);
      result = field.get(object);
    } catch (NoSuchFieldException ex) {
      throw new MjdbcException(ex);
    } catch (IllegalAccessException ex) {
      throw new MjdbcException(ex);
    }

    return result;
  }