protected DataMapping findDataFlow(
      Interaction interaction, String parameterId, Direction direction)
      throws WebApplicationException {
    DataMapping ret = null;
    ApplicationContext definition = interaction.getDefinition();

    if ((null != definition) && !isEmpty(parameterId)) {
      AccessPoint outParam = findParameterDefinition(interaction, parameterId, direction);
      if (null == outParam) {
        if (InteractionDataFlowUtils.supportDataMappingIds()) {
          ret = definition.getDataMapping(direction, parameterId);
        }
      } else {
        List<DataMapping> allDataMappings = definition.getAllDataMappings();
        for (DataMapping dataMapping : allDataMappings) {
          if (outParam.equals(dataMapping.getApplicationAccessPoint())) {
            ret = dataMapping;
            break;
          }
        }
      }
    }

    if (ret == null) {
      throw new WebApplicationException(Status.NOT_FOUND);
    }

    return ret;
  }
  protected AccessPoint findParameterDefinition(
      Interaction interaction, String parameterId, Direction direction)
      throws WebApplicationException {
    ApplicationContext definition = interaction.getDefinition();

    if ((null != definition) && !isEmpty(parameterId)) {
      for (AccessPoint ap : (List<AccessPoint>) definition.getAllAccessPoints()) {
        if ((direction == ap.getDirection()) && parameterId.equals(ap.getId())) {
          return ap;
        }
      }
    }

    return null;
  }
  public Map getOutDataValues(ActivityInstance ai) {
    trace.info("JSP Application");
    HttpSession webSession =
        (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);

    ApplicationContext applicationContext =
        ai.getActivity().getApplicationContext(PredefinedConstants.JSP_CONTEXT);

    Map outData = CollectionUtils.newMap();
    for (Iterator iterator = applicationContext.getAllOutDataMappings().iterator();
        iterator.hasNext() && webSession != null; ) {
      DataMapping mapping = (DataMapping) iterator.next();
      String mappingID = mapping.getId();
      outData.put(mappingID, webSession.getAttribute(mappingID));
    }

    return outData;
  }
  /* (non-Javadoc)
   * @see org.eclipse.stardust.ui.web.viewscommon.common.spi.IActivityInteractionController#unregisterInteraction(org.eclipse.stardust.engine.api.runtime.ActivityInstance)
   */
  public boolean unregisterInteraction(ActivityInstance ai) {
    HttpSession webSession =
        (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);

    ApplicationContext applicationContext =
        ai.getActivity().getApplicationContext(PredefinedConstants.JSP_CONTEXT);

    if (applicationContext == null || webSession == null) {
      return false;
    }

    for (Iterator iterator = applicationContext.getAllOutDataMappings().iterator();
        iterator.hasNext(); ) {
      DataMapping mapping = (DataMapping) iterator.next();
      webSession.removeAttribute(mapping.getId());
    }

    return true;
  }
  public void initializePanel(ActivityInstance ai, Map inData) {
    HttpSession session =
        (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);

    ApplicationContext applicationContext =
        ai.getActivity().getApplicationContext(PredefinedConstants.JSP_CONTEXT);

    for (Iterator i = applicationContext.getAllInDataMappings().iterator();
        i.hasNext() && session != null; ) {
      DataMapping mapping = (DataMapping) i.next();
      String mappingID = mapping.getId();
      Object value = inData.get(mappingID);

      if (trace.isDebugEnabled()) {
        trace.debug("Value " + value + " retrieved for mapping " + mappingID);
      }

      session.setAttribute(mappingID, value);
    }
  }
  public String providePanelUri(ActivityInstance ai) {
    ApplicationContext applicationContext =
        ai.getActivity().getApplicationContext(PredefinedConstants.JSP_CONTEXT);

    return (String) applicationContext.getAttribute(PredefinedConstants.HTML_PATH_ATT);
  }