/**
  * Register a new object with the document so it can maintain a master index of objects by ID.
  *
  * @param object
  */
 public void registerObject(InDesignObject object) {
   String id = object.getId();
   if (id == null || this.objectsById.containsKey(id)) {
     id = assignObjectId();
     object.setId(id);
   }
   this.objectsById.put(object.getId(), object);
   object.setDocument(this);
 }
  /**
   * @param class1
   * @param dataSource
   * @return
   * @throws Exception
   * @throws InstantiationException
   */
  private InDesignComponent newObject(Class<? extends InDesignObject> clazz, Element dataSource)
      throws Exception {
    logger.debug("newObject(): Creating new " + clazz.getSimpleName() + "...");
    InDesignObject obj = (InDesignObject) clazz.newInstance();
    obj.setDocument(this);
    if (dataSource != null) {
      logger.debug("newObject():   From element " + dataSource.getNodeName() + "...");
      obj.loadObject(dataSource);
      String selfValue = dataSource.getAttribute(PROP_SELF);
      if (selfValue != null && !"".equals(selfValue.trim())) {
        String id = InxHelper.decodeRawValueToSingleString(selfValue);
        obj.setId(id);
        this.registerObject(obj);
      } else {
        assignIdAndRegister(obj);
      }

    } else {
      assignIdAndRegister(obj);
    }
    logger.debug("newObject(): New object has ID [" + obj.getId() + "]");
    return obj;
  }
 /** @param newObject */
 protected void assignIdAndRegister(InDesignObject newObject) {
   newObject.setId(this.assignObjectId());
   registerObject(newObject);
 }