function AdfUserActivityInfo() {
  this.Init();
}
AdfUserActivityInfo.PREVIOUS = "pr0";
AdfUserActivityInfo.PRIMARY = "prm";
AdfUserActivityInfo.SECONDARY = "sec";
AdfUserActivityInfo._PREVIOUS_PREFIX = "pr";
AdfObject.createSubclass(AdfUserActivityInfo);
AdfUserActivityInfo.getInstance = function(type) {
  AdfAssert.assertString(type);
  var userActivities = AdfUserActivityInfo._instanceMap;
  if (!userActivities) {
    userActivities = {};
    AdfUserActivityInfo._instanceMap = userActivities;
  }
  var userActivity = null;
  if (type) {
    userActivity = userActivities[type];
    if (!userActivity) {
      userActivity = new AdfUserActivityInfo;
      userActivities[type] = userActivity;
    }
  }
  return userActivity;
};
AdfUserActivityInfo.restoreFromSessionStorage = function() {
  var primaryKey = AdfUserActivityInfo.PRIMARY;
  var previousKey = AdfUserActivityInfo.PREVIOUS;
  var primaryDataInStorage = AdfUserActivityInfo._getSessionStorageProperty(primaryKey);
  if (primaryDataInStorage) {
    AdfUserActivityInfo._getAsObject(String(primaryDataInStorage), previousKey);
    var prevUserActInfo = AdfUserActivityInfo.getInstance(previousKey);
    var startTime = prevUserActInfo.getClientStartTime();
    if (!startTime) {
      prevUserActInfo.setClientStartTime(prevUserActInfo._getCurrentTime());
    }
    AdfUserActivityInfo._removeSessionStorageProperty(primaryKey);
  } else {
    var prevInst = AdfUserActivityInfo.getInstance(previousKey);
    if (!prevInst.getClientStartTime()) {
      prevInst.setClientStartTime(prevInst._getCurrentTime());
    }
  }
  var previousDataInStorage = AdfUserActivityInfo._getSessionStorageProperty(previousKey);
  if (previousDataInStorage) {
    AdfUserActivityInfo._getAsObject(String(previousDataInStorage), AdfUserActivityInfo._getPreviousKeyInSequence(1));
    AdfUserActivityInfo._removeSessionStorageProperty(previousKey);
  }
  var secondaryKey = AdfUserActivityInfo.SECONDARY;
  var secondaryInStorage = AdfUserActivityInfo._getSessionStorageProperty(secondaryKey);
  if (secondaryInStorage) {
    AdfUserActivityInfo._getAsObject(String(secondaryInStorage), secondaryKey);
    AdfUserActivityInfo._removeSessionStorageProperty(secondaryKey);
  }
};
AdfUserActivityInfo.removeFromSessionStorageByType = function(type) {
  AdfAssert.assertNonEmptyString(type);
  AdfUserActivityInfo._removeSessionStorageProperty(type);
};
AdfUserActivityInfo.saveToSessionStorage = function() {
  if (AdfUserActivityInfo._instanceMap == null) {
    return;
  }
  AdfUserActivityInfo.restoreFromSessionStorage();
  var prevActInfo = AdfUserActivityInfo.getInstance(AdfUserActivityInfo.PREVIOUS);
  var currentTime = prevActInfo._getCurrentTime();
  prevActInfo.setClientEndTime(currentTime);
  AdfUserActivityInfo.saveToSessionStorageByType(AdfUserActivityInfo.PREVIOUS);
  var primActInfo = AdfUserActivityInfo.getInstance(AdfUserActivityInfo.PRIMARY);
  primActInfo.setClientStartTime(currentTime);
  AdfUserActivityInfo.saveToSessionStorageByType(AdfUserActivityInfo.PRIMARY);
  AdfUserActivityInfo.cleanInstanceMap();
};
AdfUserActivityInfo.saveToSessionStorageByType = function(type) {
  var userActInfo = AdfUserActivityInfo.getInstance(type);
  if (userActInfo) {
    userActInfoValue = AdfUserActivityInfo._getAsString(userActInfo);
    AdfUserActivityInfo._setSessionStorageProperty(type, userActInfoValue);
  }
};
AdfUserActivityInfo.prototype.Init = function() {
  AdfUserActivityInfo.superclass.Init.call(this);
  this["cid"] = null;
  this["cst"] = null;
  this["cet"] = null;
  this["eif"] = null;
  this["ppr"] = null;
  this["rrt"] = null;
};
AdfUserActivityInfo.getMarshaledObject = function() {
  var agent = AdfAgent.AGENT;
  var doc = agent.createXmlDocument();
  var parentNode = doc.createElement("TEMP");
  if (agent.getPlatform() == AdfAgent.IE_PLATFORM) {
    doc.documentElement = parentNode;
  } else {
    doc.appendChild(parentNode);
  }
  var node = AdfMarshalingService.getDefault().marshal(parentNode, AdfUserActivityInfo._instanceMap, null);
  AdfUserActivityInfo.removeFromSessionStorageByType(AdfUserActivityInfo.PRIMARY);
  AdfUserActivityInfo.removeFromSessionStorageByType(AdfUserActivityInfo.PREVIOUS);
  AdfUserActivityInfo.removeFromSessionStorageByType(AdfUserActivityInfo.SECONDARY);
  var seq = 1;
  var prevInSeq = AdfUserActivityInfo._getPreviousKeyInSequence(seq);
  while (AdfUserActivityInfo._getSessionStorageProperty(prevInSeq)) {
    AdfUserActivityInfo.removeFromSessionStorageByType(prevInSeq);
    prevInSeq = AdfUserActivityInfo._getPreviousKeyInSequence(seq++);
  }
  AdfUserActivityInfo.saveToSessionStorageByType(AdfUserActivityInfo.PRIMARY);
  AdfUserActivityInfo.cleanInstanceMap();
  return agent.getNodeXml(node);
};
AdfUserActivityInfo.setRequestSentTime = function(type) {
  var userActInfo = null;
  if (!type) {
    type = AdfUserActivityInfo.PRIMARY;
  }
  userActInfo = AdfUserActivityInfo.getInstance(type);
  userActInfo.rst = userActInfo._getCurrentTime();
};
AdfUserActivityInfo.setResponseReceivedTime = function(type) {
  var userActInfo = null;
  if (!type) {
    type = AdfUserActivityInfo.PREVIOUS;
  }
  userActInfo = AdfUserActivityInfo.getInstance(type);
  userActInfo.rrt = userActInfo.rrt || userActInfo._getCurrentTime();
};
AdfUserActivityInfo.prototype.getContextId = function() {
  return this["cid"];
};
AdfUserActivityInfo.prototype.getParentContextId = function() {
  return this["pid"];
};
AdfUserActivityInfo.prototype.getClientStartTime = function() {
  return this["cst"];
};
AdfUserActivityInfo.prototype.getClientEndTime = function() {
  return this["cet"];
};
AdfUserActivityInfo.prototype.getResponseTime = function() {
  return this.rrt;
};
AdfUserActivityInfo.prototype.getEventInfo = function() {
  return this["eif"];
};
AdfUserActivityInfo.prototype.getPprTargets = function() {
  return this["ppr"];
};
AdfUserActivityInfo.prototype.setContextId = function(contextId) {
  this["cid"] = contextId;
};
AdfUserActivityInfo.prototype.setParentContextId = function(parentContextId) {
  this["pid"] = parentContextId;
};
AdfUserActivityInfo.prototype.setClientStartTime = function(clientStartTime) {
  this["cst"] = clientStartTime;
};
AdfUserActivityInfo.prototype.setClientEndTime = function(clientEndTime) {
  this["cet"] = clientEndTime;
};
AdfUserActivityInfo.prototype.setEventInfo = function(eventType, clientId, componentType, compDisplayName) {
  if (!this["eif"]) {
    this["eif"] = {};
  }
  if (eventType) {
    this["eif"]["ety"] = eventType;
  }
  if (clientId) {
    this["eif"]["cld"] = clientId;
  }
  if (componentType) {
    this["eif"]["cty"] = componentType;
  }
  if (compDisplayName) {
    this["eif"]["cdn"] = compDisplayName;
  }
  var eventComponent = AdfPage.PAGE.findComponent(clientId);
  if (eventComponent != null) {
    var current = eventComponent;
    var regionViewId = null;
    var regionViewName = null;
    var parent = current;
    while (parent != null) {
      if (parent.getComponentType() == "oracle.adf.RichRegion") {
        regionViewId = parent.getProperty("viewId");
        regionViewName = parent.getProperty("viewName");
        break;
      }
      parent = parent.getParent();
    }
    if (regionViewId) {
      this["eif"]["rvd"] = regionViewId;
      if (regionViewName) {
        this["eif"]["rvn"] = regionViewName;
      }
    }
  }
};
AdfUserActivityInfo.prototype.setPprTargets = function(pprTargets) {
  if (pprTargets) {
    this["ppr"] = pprTargets;
  }
};
AdfUserActivityInfo.prototype.setResponseTime = function(responseEndTime) {
  this.rrt = responseEndTime;
};
AdfUserActivityInfo.prototype.cleanup = function() {
  this["cid"] = null;
  this["cst"] = null;
  this["cet"] = null;
  this["eif"] = null;
  this["pid"] = null;
  this["ppr"] = null;
};
AdfUserActivityInfo.cleanInstanceMap = function() {
  var userActivities = AdfUserActivityInfo._instanceMap;
  if (userActivities) {
    for (var type in userActivities) {
      var userActivity = userActivities[type];
      if (userActivity.cleanup) {
        userActivity.cleanup();
      }
    }
    AdfUserActivityInfo._instanceMap = null;
  }
};
AdfUserActivityInfo._getAsObject = function(userActInfoStr, type) {
  var userActInfo = AdfUserActivityInfo.getInstance(type);
  userActInfoStr = userActInfoStr.replace(/'/g, '"');
  var objInfo = JSON.parse(userActInfoStr);
  if (objInfo != null) {
    var clientStartTime = userActInfo.getClientStartTime();
    if (clientStartTime == null) {
      var storedStartTime = objInfo["cst"];
      if (storedStartTime != null) {
        userActInfo.setClientStartTime(storedStartTime);
      }
    }
    var contextId = userActInfo.getContextId();
    if (contextId == null) {
      var storedContextId = objInfo["cid"];
      if (storedContextId != null) {
        userActInfo.setContextId(storedContextId);
      }
    }
    var parentContextId = userActInfo.getParentContextId();
    if (parentContextId == null) {
      var storedParentContextId = objInfo["pid"];
      if (storedParentContextId != null && storedParentContextId != "undefined") {
        userActInfo.setParentContextId(storedParentContextId);
      }
    }
    userActInfo.setClientEndTime(objInfo["cet"]);
    var responseEndTime = userActInfo.getResponseTime();
    if (responseEndTime == null) {
      var storedResponseEndTime = objInfo.rrt;
      if (storedResponseEndTime && storedResponseEndTime !== "null") {
        userActInfo.setResponseTime(storedResponseEndTime);
      }
    }
  }
};
AdfUserActivityInfo._getAsString = function(userActInfo) {
  var userActInfoStr = "{'cid':'" + userActInfo.getContextId() + "','pid':'" + userActInfo.getParentContextId() + "','cst':'" + userActInfo.getClientStartTime() + "','cet':'" + userActInfo.getClientEndTime() + "','rrt':'" + userActInfo.getResponseTime() + "'}";
  return userActInfoStr;
};
AdfUserActivityInfo.prototype._getCurrentTime = function() {
  return (new Date).getTime().toString();
};
AdfUserActivityInfo._getPreviousKeyInSequence = function(sequenceNum) {
  if (sequenceNum) {
    AdfAssert.assertNumber(sequenceNum);
    if (sequenceNum > 0) {
      return AdfUserActivityInfo._PREVIOUS_PREFIX + sequenceNum.toString();
    }
  }
  return AdfUserActivityInfo.PREVIOUS;
};
AdfUserActivityInfo._getSessionStorageProperty = function(propKey) {
  var agent = AdfAgent.AGENT;
  var propValue = null;
  try {
    propValue = agent.getSessionStorageProperty(propKey);
  } catch (e) {
    AdfLogger.LOGGER.fine("User activity information may be inaccurate as a failure occurred when attempting to retrieve property from sessionStorage - " + propKey);
  }
  return propValue;
};
AdfUserActivityInfo._removeSessionStorageProperty = function(propKey) {
  var agent = AdfAgent.AGENT;
  var result = true;
  try {
    agent.removeSessionStorageProperty(propKey);
  } catch (e) {
    AdfLogger.LOGGER.fine("User activity information may be inaccurate as a failure occurred when attempting to remove property from sessionStorage - " + propKey);
    result = false;
  }
  return result;
};
AdfUserActivityInfo._setSessionStorageProperty = function(propKey, propValue) {
  var agent = AdfAgent.AGENT;
  var result = true;
  try {
    agent.setSessionStorageProperty(propKey, propValue);
  } catch (e) {
    AdfLogger.LOGGER.fine("User activity information may be inaccurate as a failure occurred when attempting to save property-value to sessionStorage " + propKey + ", " + propValue);
    result = false;
  }
  return result;
};
