Esempio n. 1
0
  /**
   * Used by the parser to create a new instance of the given class and store it in the master
   * objects table under the given ID.
   *
   * @param objID A unique ID used to index objects in the master object table.
   * @param cls The class to instantiate.
   * @return The newly instantiated object.
   */
  public Object newInstance(Long objID, Class cls) throws ParseException {
    if (cls == null) throw new IllegalArgumentException("The class cannot be (null)!");

    Object obj = null;
    try {
      obj = cls.newInstance();
    } catch (Exception ex) {
      throw new ParseException(
          "Unable to instantiate class (" + cls + "):\n" + "  " + ex.toString());
    }

    if (pMasterTable.containsKey(objID))
      throw new ParseException("Duplicate object ID (" + objID + " encountered!");
    pMasterTable.put(objID, obj);

    return obj;
  }