/**
  * Initializes a newly created {@link PortletWindow}, the default implementation sets up the
  * appropriate {@link WindowState} and {@link javax.portlet.PortletMode}
  */
 protected void initializePortletWindowData(
     HttpServletRequest request, PortletWindowData portletWindowData) {
   final IStylesheetDescriptor stylesheetDescriptor = getThemeStylesheetDescriptor(request);
   final IPortletEntityId portletEntityId = portletWindowData.getPortletEntityId();
   final IPortletEntity portletEntity =
       this.portletEntityRegistry.getPortletEntity(request, portletEntityId);
   final WindowState entityWindowState = portletEntity.getWindowState(stylesheetDescriptor);
   if (persistentWindowStates.contains(entityWindowState)) {
     portletWindowData.setWindowState(entityWindowState);
   } else if (entityWindowState != null) {
     // Set of persistent window states must have changed, nuke the old value
     this.logger.warn(
         "PortletEntity.windowState="
             + entityWindowState
             + " but that state is not in the set of persistent WindowStates. PortletEntity.windowState will be set to null");
     portletEntity.setWindowState(stylesheetDescriptor, null);
     this.portletEntityRegistry.storePortletEntity(request, portletEntity);
   }
 }
  @Override
  public IPortletWindow getOrCreateStatelessPortletWindow(
      HttpServletRequest request, IPortletWindowId basePortletWindowId) {
    // Need the basePortletWindowId to be an instance of PortletWindowIdImpl so that we can extract
    // the entity ID
    if (!(basePortletWindowId instanceof PortletWindowIdImpl)) {
      final String basePortletWindowIdStr = basePortletWindowId.getStringId();
      basePortletWindowId = this.getPortletWindowId(request, basePortletWindowIdStr);
    }

    // Get the entity ID for the portlet window
    final IPortletEntityId portletEntityId =
        ((PortletWindowIdImpl) basePortletWindowId).getPortletEntityId();

    // Create the stateless ID
    final PortletWindowIdImpl statelessPortletWindowId =
        this.createPortletWindowId(STATELESS_PORTLET_WINDOW_ID, portletEntityId);

    // See if there is already a request cached stateless window
    IPortletWindow statelessPortletWindow =
        this.getPortletWindow(request, statelessPortletWindowId);
    if (statelessPortletWindow != null) {
      return statelessPortletWindow;
    }

    // Lookup the base portlet window to clone the stateless from
    final IPortletWindow basePortletWindow = this.getPortletWindow(request, basePortletWindowId);

    final PortletWindowCache<PortletWindowData> statelessPortletWindowDataMap =
        this.getStatelessPortletWindowDataMap(request, true);

    // If no base to clone from lookup the entity and pluto definition data
    if (basePortletWindow == null) {
      final IPortletEntity portletEntity =
          this.portletEntityRegistry.getPortletEntity(request, portletEntityId);
      if (portletEntity == null) {
        throw new IllegalArgumentException(
            "No IPortletEntity could be found for "
                + portletEntity
                + " while creating stateless portlet window for "
                + basePortletWindowId);
      }

      final IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
      final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
      final PortletDefinition portletDescriptor =
          this.portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId);

      final PortletWindowData portletWindowData =
          new PortletWindowData(statelessPortletWindowId, portletEntityId);
      statelessPortletWindowDataMap.storeWindow(portletWindowData);

      statelessPortletWindow =
          new StatelessPortletWindowImpl(portletWindowData, portletEntity, portletDescriptor);
    }
    // Clone the existing base window
    else {
      final PortletWindowData portletWindowData =
          new PortletWindowData(statelessPortletWindowId, portletEntityId);
      portletWindowData.setExpirationCache(basePortletWindow.getExpirationCache());
      portletWindowData.setPortletMode(basePortletWindow.getPortletMode());
      portletWindowData.setWindowState(basePortletWindow.getWindowState());
      portletWindowData.setPublicRenderParameters(basePortletWindow.getPublicRenderParameters());
      portletWindowData.setRenderParameters(basePortletWindow.getRenderParameters());

      statelessPortletWindowDataMap.storeWindow(portletWindowData);

      final IPortletEntity portletEntity = basePortletWindow.getPortletEntity();
      final PortletDefinition portletDescriptor =
          basePortletWindow.getPlutoPortletWindow().getPortletDefinition();
      statelessPortletWindow =
          new StatelessPortletWindowImpl(portletWindowData, portletEntity, portletDescriptor);
    }

    // Cache the stateless window in the request
    final PortletWindowCache<IPortletWindow> portletWindowMap = this.getPortletWindowMap(request);
    portletWindowMap.storeWindow(statelessPortletWindow);

    return statelessPortletWindow;
  }