Java Class.toString Examples

Java Class.toString - 30 examples found. These are the top rated real world Java examples of Class.toString extracted from open source projects. You can rate examples to help us improve the quality of examples.
  /**
   * We are allowing consumers of the SDK to register their own deriived classes from the base
   * models we have inside the SDK. This allows for cases where the consumer wants to add addtional
   * flags and functions to the model and yet have orginal parsed objects of his liking. Example
   * SFFile does not provide the isSynced flag. The consumer app can extend like :
   *
   * <p>SFFileEx extends SFFile <br>
   * { <br>
   * boolean mIsSync <br>
   * }
   *
   * @throws IllegalAccessException
   * @throws InstantiationException
   * @throws SFInvalidTypeException
   */
  public static void registerSubClass(SFV3ElementType elementType, Class<?> newClass)
      throws InstantiationException, IllegalAccessException, SFInvalidTypeException {
    if (newClass == null) {
      throw new SFInvalidTypeException(
          " NULL does not extend " + elementType.mOriginalClass.toString());
    }

    // test if the new class is a real extension of the type being replaced.
    if (!elementType.mOriginalClass.isInstance(newClass.newInstance())) {
      String msg =
          newClass.toString() + " does not extend " + elementType.mOriginalClass.toString();

      Logger.d(TAG, msg);

      throw new SFInvalidTypeException(msg);
    }

    Logger.d(
        TAG,
        "Successfully registered : "
            + newClass.toString()
            + " to replace "
            + elementType.mOriginalClass.toString());

    elementType.mOverrideClass = newClass;

    registerSubClass(elementType.mToString.replace(prefix, "").replace(suffix, ""), newClass);
  }
 /**
  * オブジェクトのフィールドにデータを設定する<br>
  * Integer、Float、Float[]、Stringにしか対応していない
  *
  * @param obj 設定対象オブジェクト
  * @param fl 設定対象フィールド
  * @param ty 設定対象フィールドの型
  * @param data 設定データ
  * @throws IllegalArgumentException
  * @throws IllegalAccessException
  */
 protected void dataSetter(Object obj, Field fl, Class ty, String data)
     throws IllegalArgumentException, IllegalAccessException {
   // Integer型のデータを設定
   if (ty.toString().equals("class java.lang.Integer")) {
     fl.set(obj, Integer.parseInt(data));
   }
   // Float型のデータを設定
   if (ty.toString().equals("class java.lang.Float")) {
     fl.set(obj, Float.parseFloat(data));
   }
   // String型のデータを設定(""の内側)
   if (ty.toString().equals("class java.lang.String")) {
     fl.set(obj, getDoubleQuoatString(data));
   }
   // Float[]型のデータを設定
   if (ty.toString().equals("class [Ljava.lang.Float;")) {
     String[] s;
     s = data.split(" ");
     Float[] f = new Float[s.length];
     for (int i = 0; i < s.length; i++) {
       f[i] = Float.parseFloat(s[i]);
     }
     fl.set(obj, f);
   }
 }
Example #3
0
  /**
   * Returns the {@link ComponentUI} for the specified {@link JComponent}.
   *
   * @param target the component for which the ComponentUI is requested
   * @return the {@link ComponentUI} for the specified {@link JComponent}
   */
  public ComponentUI getUI(JComponent target) {
    String classId = target.getUIClassID();
    Class cls = getUIClass(classId);
    if (cls == null) {
      getUIError("failed to locate UI class:" + classId);
      return null;
    }

    Method factory;

    try {
      factory = cls.getMethod("createUI", new Class[] {JComponent.class});
    } catch (NoSuchMethodException nme) {
      getUIError("failed to locate createUI method on " + cls.toString());
      return null;
    }

    try {
      return (ComponentUI) factory.invoke(null, new Object[] {target});
    } catch (java.lang.reflect.InvocationTargetException ite) {
      getUIError(
          "InvocationTargetException ("
              + ite.getTargetException()
              + ") calling createUI(...) on "
              + cls.toString());
      return null;
    } catch (Exception e) {
      getUIError("exception calling createUI(...) on " + cls.toString());
      return null;
    }
  }
  public static void registerSubClass(String originalClassName, Class<?> newClass)
      throws InstantiationException, IllegalAccessException, SFInvalidTypeException {
    if (newClass == null || originalClassName == null) {
      throw new SFInvalidTypeException(" NULL classes not allowed ");
    }

    Class originalClass = SFEntityTypeMap.getEntityTypeMap().get(originalClassName);

    if (originalClass == null) {
      throw new SFInvalidTypeException("Given Class does not exist");
    }

    // test if the new class is a real extension of the type being replaced.
    if (!originalClass.isInstance(newClass.newInstance())) {
      String msg = newClass.toString() + " does not extend " + originalClass.toString();

      Logger.d(TAG, msg);

      throw new SFInvalidTypeException(msg);
    }

    SFEntityTypeMap.getEntityTypeMap().put(originalClassName, newClass);
    SFDefaultGsonParser.routeSpecialClasses(originalClassName, newClass);

    Logger.d(
        TAG,
        "Successfully registered : "
            + newClass.toString()
            + " to replace "
            + originalClass.toString());
  }
 /**
  * Returns the RDFS Class URI for a model POJO class. The POJO class must contain a field named
  * 'RDFS_CLASS', and its value should be the class URI.
  *
  * @param clazz the Java class to extract the URI
  * @return the RDFS Class URI
  */
 public static <T extends Resource> URI getUriOfClass(Class<T> clazz) {
   URI typeUri = null;
   try {
     typeUri = (URI) clazz.getDeclaredField("RDFS_CLASS").get("");
     logger.debug("RDFS_CLASS is " + typeUri + " for class " + clazz.toString());
   } catch (Exception e) {
     logger.error("RDFS_CLASS attribute is not defined for the class " + clazz.toString());
   }
   return typeUri;
 }
Example #6
0
 /**
  * Get a {@link java.lang.reflect.Constructor Constructor} from a {@link java.lang.Class Class}
  * that you normally can't use.
  *
  * @param temp The {@link java.lang.Class Class} that you want to get the {@link
  *     java.lang.reflect.Constructor Constructor} form.
  * @param parameters The parameters of the {@link java.lang.reflect.Constructor Constructor} that
  *     you want to get.
  * @return The {@link java.lang.reflect.Constructor Constructor} that you requested and makes them
  *     accessible.
  */
 public static Constructor getConstructor(Class<?> temp, Class... parameters) {
   try {
     Constructor constructor = temp.getDeclaredConstructor(parameters);
     return constructor;
   } catch (NoSuchMethodException e) {
     Log.error("There is no constructor for the class : " + temp.toString() + " :");
     return null;
   } catch (SecurityException e) {
     Log.error("you can not access the constructor of this class : " + temp.toString() + " :");
     return null;
   }
 }