public Set<Portlet> getPortlets() throws PortletInvokerException {
    Set<Portlet> portlets = new HashSet<Portlet>(super.getPortlets());
    Registration registration = RegistrationLocal.getRegistration();

    if (registration != null) {
      Set<PortletContext> contexts = registration.getKnownPortletContexts();
      for (PortletContext context : contexts) {
        try {
          portlets.add(super.getPortlet(context));
        } catch (NoSuchPortletException e) {
          final RegistrationSPI registrationSPI = getRegistrationAsSPI();
          try {
            registrationSPI.removePortletContext(context);
            log.debug(
                "Removed '"
                    + context
                    + "' from Registration '"
                    + registration.getRegistrationHandle()
                    + "' because it cannot be resolved anymore.");
          } catch (RegistrationException e1) {
            throw new PortletInvokerException(e1);
          }
        }
      }
    }

    return portlets;
  }
  public List<DestroyCloneFailure> destroyClones(List<PortletContext> portletContexts)
      throws IllegalArgumentException, PortletInvokerException, UnsupportedOperationException {
    RegistrationSPI registration = getRegistrationAsSPI();

    if (registration != null) {
      for (PortletContext portletContext : portletContexts) {
        checkOperationIsAllowed(portletContext, registration, "destroyClones");
      }
    }

    List<DestroyCloneFailure> cloneFailures = super.destroyClones(portletContexts);
    boolean noFailures = cloneFailures.isEmpty();

    if (registration != null) {
      for (PortletContext portletContext : portletContexts) {
        // only remove the portlet context if there are no failures or it's not part of the failed
        // clones
        if (noFailures
            || !cloneFailures.contains(new DestroyCloneFailure(portletContext.getId()))) {
          try {
            registration.removePortletContext(portletContext);
          } catch (RegistrationException e) {
            throw new PortletInvokerException(
                "Couldn't remove portlet context '"
                    + portletContext
                    + "' to registration '"
                    + registration.getRegistrationHandle()
                    + "'",
                e);
          }
        }
      }
    }

    return cloneFailures;
  }