/**
   * Adds this object on the object bench. If you pass null as instanceName the object will have a
   * predefined name. If the object is not a valid one nothing will happen.
   *
   * @param instanceName The name you want this object to have on the bench.
   * @throws ProjectNotOpenException if the project to which this object belongs has been closed by
   *     the user.
   * @throws PackageNotFoundException if the package to which this object belongs has been deleted
   *     by the user.
   */
  public void addToBench(String instanceName)
      throws ProjectNotOpenException, PackageNotFoundException {
    if (objectWrapper == null) {
      return;
    }

    // Not rational to add a null object, is it ?
    if (objectWrapper.getObject().isNullObject()) {
      return;
    }

    // If you want you may set the instance name here. Otherwise accept default
    if (instanceName != null) {
      objectWrapper.setName(instanceName);
    }

    // This should really always exists, no need to check
    Package aPackage = wrapperId.getBluejPackage();
    PkgMgrFrame aFrame = wrapperId.getPackageFrame();

    ObjectBench aBench = aFrame.getObjectBench();
    aBench.addObject(objectWrapper);

    // load the object into runtime scope
    aPackage
        .getDebugger()
        .addObject(aPackage.getId(), objectWrapper.getName(), objectWrapper.getObject());
  }
  /**
   * Removes this object from the object bench. This will also remove it from the view of the object
   * bench. Once the object is removed from the bench it will not be available again.
   *
   * @throws ProjectNotOpenException if the project to which this object belongs has been closed by
   *     the user.
   * @throws PackageNotFoundException if the package to which this object belongs has been deleted
   *     by the user.
   */
  public void removeFromBench() throws ProjectNotOpenException, PackageNotFoundException {
    Package aPackage = wrapperId.getBluejPackage();
    PkgMgrFrame aFrame = wrapperId.getPackageFrame();

    ObjectBench aBench = aFrame.getObjectBench();
    aBench.removeObject(objectWrapper, aPackage.getId());

    objectWrapper = null;
  }
  /**
   * Return the class of this object. Similar to Reflection API. Note the naming inconsistency,
   * which avoids a clash with <code>java.lang.Object.getClass()</code>
   *
   * @return The bClass value
   * @throws ProjectNotOpenException if the project to which this object belongs has been closed by
   *     the user.
   * @throws ClassNotFoundException if the class has been deleted by the user.
   * @throws PackageNotFoundException if the Package has been deleted by the user.
   */
  public BClass getBClass()
      throws ProjectNotOpenException, PackageNotFoundException, ClassNotFoundException {
    // BClasses are retrieved from the BlueJ classTarget
    ClassTarget classTarget = wrapperId.getClassTarget();

    if (classTarget == null) {
      // Not a project class; exists in a library or the Java runtime
      wrapperId.getJavaClass(); // will throw ClassNotFoundException if not loadable
      return BClass.getBClass(wrapperId);
    }

    // There is only one instance of BClass for each ClassTarget
    return classTarget.getBClass();
  }
  /**
   * Returns the package this object belongs to.
   *
   * @return The package value
   * @throws ProjectNotOpenException if the project to which this object belongs has been closed by
   *     the user.
   * @throws PackageNotFoundException if the package to which this object belongs has been deleted
   *     by the user.
   */
  public BPackage getPackage() throws ProjectNotOpenException, PackageNotFoundException {
    Package bluejPkg = wrapperId.getBluejPackage();

    return bluejPkg.getBPackage();
  }
 /**
  * Returns the underlying BlueJ package. Should remain visible only to package members.
  *
  * @return The packageFrame value
  * @throws ProjectNotOpenException if the project to which this object belongs has been closed by
  *     the user.
  * @throws PackageNotFoundException if the package to which this object belongs has been deleted
  *     by the user.
  */
 PkgMgrFrame getPackageFrame() throws ProjectNotOpenException, PackageNotFoundException {
   return wrapperId.getPackageFrame();
 }