public BridgeRequestScopeImpl(
      PortletConfig portletConfig,
      PortletContext portletContext,
      PortletRequest portletRequest,
      String idPrefix) {

    this.attributeMap = new HashMap<String, Object>();

    long timeInMillis = Calendar.getInstance().getTimeInMillis();
    this.idPrefix = idPrefix;
    this.idSuffix = Long.toString(timeInMillis);

    BridgeConfigFactory bridgeConfigFactory =
        (BridgeConfigFactory) BridgeFactoryFinder.getFactory(BridgeConfigFactory.class);
    BridgeConfig bridgeConfig = bridgeConfigFactory.getBridgeConfig();
    this.excludedAttributeNames = new ArrayList<String>();

    // Get the list of excluded BridgeRequestScope attributes from the faces-config.xml descriptors.
    Set<String> facesConfigExcludedAttributeNames = bridgeConfig.getExcludedRequestAttributes();

    // Get the list of excluded BridgeRequestScope attributes from the WEB-INF/portlet.xml
    // descriptor.
    @SuppressWarnings("unchecked")
    List<String> portletContextExcludedAttributeNames =
        (List<String>)
            portletContext.getAttribute(
                Bridge.BRIDGE_PACKAGE_PREFIX
                    + portletConfig.getPortletName()
                    + BridgeConstants.CHAR_PERIOD
                    + Bridge.EXCLUDED_REQUEST_ATTRIBUTES);

    // Combine the two lists into a single list of excluded BridgeRequestScope attributes.
    if (facesConfigExcludedAttributeNames != null) {
      this.excludedAttributeNames.addAll(facesConfigExcludedAttributeNames);
    }

    if (portletContextExcludedAttributeNames != null) {
      this.excludedAttributeNames.addAll(portletContextExcludedAttributeNames);
    }

    this.preExistingAttributeNames = getPreExistingRequestAttributeNames(portletRequest);

    Bridge.PortletPhase portletPhase =
        (Bridge.PortletPhase) portletRequest.getAttribute(Bridge.PORTLET_LIFECYCLE_PHASE);

    if ((portletPhase == Bridge.PortletPhase.ACTION_PHASE)
        || (portletPhase == Bridge.PortletPhase.EVENT_PHASE)) {
      beganInActionOrEventRequest = true;
    }
  }
  public BridgeRequestScopeImpl(
      PortletConfig portletConfig, PortletContext portletContext, PortletRequest portletRequest) {

    this.dateCreated = Calendar.getInstance().getTimeInMillis();

    portletName = portletConfig.getPortletName();

    PortletSession portletSession = portletRequest.getPortletSession();
    String sessionId = portletSession.getId();
    this.idPrefix = portletName + ":::" + sessionId + ":::";
    this.idSuffix = Long.toString(Calendar.getInstance().getTimeInMillis());

    BridgeConfigFactory bridgeConfigFactory =
        (BridgeConfigFactory) BridgeFactoryFinder.getFactory(BridgeConfigFactory.class);
    BridgeConfig bridgeConfig = bridgeConfigFactory.getBridgeConfig();
    this.excludedAttributeNames = new ArrayList<String>();

    // Get the list of excluded BridgeRequestScope attributes from the faces-config.xml descriptors.
    Set<String> facesConfigExcludedAttributeNames = bridgeConfig.getExcludedRequestAttributes();

    // Get the list of excluded BridgeRequestScope attributes from the WEB-INF/portlet.xml
    // descriptor.
    @SuppressWarnings("unchecked")
    List<String> portletContextExcludedAttributeNames =
        (List<String>)
            portletContext.getAttribute(
                Bridge.BRIDGE_PACKAGE_PREFIX
                    + portletName
                    + StringPool.PERIOD
                    + Bridge.EXCLUDED_REQUEST_ATTRIBUTES);

    // Combine the two lists into a single list of excluded BridgeRequestScope attributes.
    if (facesConfigExcludedAttributeNames != null) {
      this.excludedAttributeNames.addAll(facesConfigExcludedAttributeNames);
    }

    if (portletContextExcludedAttributeNames != null) {
      this.excludedAttributeNames.addAll(portletContextExcludedAttributeNames);
    }

    this.portletMode = PortletMode.VIEW;
    this.preExistingAttributeNames = getPreExistingRequestAttributeNames(portletRequest);

    this.beganInPhase =
        (Bridge.PortletPhase) portletRequest.getAttribute(Bridge.PORTLET_LIFECYCLE_PHASE);
  }
  @SuppressWarnings("unchecked")
  @Override
  public void init(PortletConfig portletConfig) {

    PortletContext portletContext = portletConfig.getPortletContext();

    synchronized (portletContext) {
      bridgeFactoryCache =
          (Map<Class<? extends FactoryWrapper<?>>, FactoryWrapper<?>>)
              portletContext.getAttribute(BRIDGE_FACTORY_CACHE);

      if (bridgeFactoryCache == null) {
        bridgeFactoryCache = new HashMap<Class<? extends FactoryWrapper<?>>, FactoryWrapper<?>>();
        portletContext.setAttribute(BRIDGE_FACTORY_CACHE, bridgeFactoryCache);
      }
    }

    BridgeConfigFactory bridgeConfigFactory = new BridgeConfigFactoryImpl(portletConfig);
    bridgeFactoryCache.put(BridgeConfigFactory.class, bridgeConfigFactory);
    bridgeConfig = bridgeConfigFactory.getBridgeConfig();
  }
  public ExternalContextCompatImpl(
      PortletContext portletContext,
      PortletRequest portletRequest,
      PortletResponse portletResponse) {

    this.portletContext = portletContext;
    this.portletRequest = portletRequest;
    this.portletResponse = portletResponse;

    // Get the bridge configuration.
    BridgeConfigFactory bridgeConfigFactory =
        (BridgeConfigFactory) BridgeFactoryFinder.getFactory(BridgeConfigFactory.class);
    this.bridgeConfig = bridgeConfigFactory.getBridgeConfig();

    // Get the BridgeContext.
    this.bridgeContext = BridgeContext.getCurrentInstance();

    this.incongruityContext = bridgeContext.getIncongruityContext();

    // Determine whether or not lifecycle incongruities should be managed.
    this.manageIncongruities =
        BooleanHelper.toBoolean(
            bridgeContext.getInitParameter(BridgeConfigConstants.PARAM_MANAGE_INCONGRUITIES), true);
  }