示例#1
0
  /**
   * Adds an object to this inspector.
   *
   * @param o the object that is to be added
   * @param objID object id of the object that shall be replaced
   */
  public synchronized void replaceObject(Object newObj, int objID)
      throws InterfaceChangedException {

    if (newObj == null) {
      throw new IllegalArgumentException("Argument \"null\" not supported!");
    }

    // objects.getById(objID).setObject(newObj);
    Collection<Object> instances = getObjectsByClassName(newObj.getClass().getName());

    if (instances.size() <= objID) {
      addObject(newObj);
    } else {

      Object oldObj = getObject(objID);

      ObjectDescription oDescOld = getObjectDescription(oldObj);
      ObjectDescription oDescNew = generateObjectDescription(newObj, objID, false);

      if (oDescOld.getSignature().equals(oDescNew.getSignature())) {

        removeObject(objID);
        addObject(newObj, objID);
        objectDescriptions.add(oDescNew);
      } else {
        throw new InterfaceChangedException(
            "Cannot replace object because the interface of the new"
                + " class and the old class are not equal!");
      }
    }
  }