/*
 * Copyright (c) 2003 by Hyperwave AG. All rights reserved.
 */

  /**
   * This class is the Value Object implementation for search results.
   *
   * @see SearchResultVO
   */

// <JSClass>
  /**
   * Public constructor, creates an instance of the search results value object.
   */
  SearchResultsVO = function(theArgs)
  {
    if (theArgs == "__proto__")
      return;

    this.data_         = []; // data: [] of SearchResultVO
    this.searchParams_ = null; // SearchParamsVO
    this.itemCount_    = null;
    this.exactCount_   = null;
  }

  // Inheritance call for JavaScript.
  class$ = doInherit(SearchResultsVO);


  /**
   * Serialize search results.
   *
   * @return String: the serialization String of the search results.
   */
  class$.serialize = function()
  {
    var ws = new WebSerializer();

    // add all string properties in key value map
    // add the array of data and pupils, which are arrays of ObjectVO objects
    // if the arrays are null are considered unchanged and are not serialized.
    if (this.data_ != null) 
    {
      ws.addValueArray("d", this.data_);
    }
    
    ws.addValue("s",  this.searchParams_);
    ws.addValue("ic", this.itemCount_);
    ws.addValue("ec", this.exactCount_);

    // return serialized value
    return ws.getString();
  }


  /**
   * Deserializes search results.
   *
   * @param aSerializedObject: String: the serialization String of the search results.
   * @return ObjectVO: the created value object.
   */
  class$.static_.deserialize = function(aSerializedObject)
  {
    // build a new instance of the value object
    var value_object = new SearchResultsVO();

    // load serialized course
    var ws = new WebSerializer(aSerializedObject);

    // deserialize data
    value_object.data_ = ws.getValueArray("d", SearchResultVO);
    value_object.searchParams_ = ws.getValue("s", SearchParamsVO);
    value_object.itemCount_ = ws.getValue("ic", "number");
    value_object.exactCount_ = ws.getValue("ec", "boolean");
    
    // return the newly created value object
    return value_object;
  }



  /**
   * Creates a SearchResultsVO object from an java script object. All dirty flags are cleared.
   *
   * @param anObject: Object: java script object with properties:
   * @param anObject.data: Array of <Object> | void: the data array. default: empty array
   *
   * @see <code>SearchResultVO.serializeToObject</code> for <Object> definition
   *
   * @return SearchResultsVO object
   */
  class$.static_.createFromObject = function(anObject) {

    var searchResultsVO = new SearchResultsVO();

    // set data
    if (typeof anObject.data != "undefined") {  // set data
      for(var i = 0; i < anObject.d.length; i++) {
        searchResultsVO.data_[i] = SearchResultVO.static_.createFromObject( anObject.data[i] );
      }
    }
    if (typeof anObject.params!="undefined") 
      searchResultsVO.searchParams_ = SearchParamsVO.static_.createFromObject( anObject.s );

    if (typeof theObject.ic  != "undefined") vo.itemCount_ = theObject.ic;
    if (typeof theObject.ec  != "undefined") vo.exactCount_ = theObject.ec;

    return searchResultsVO;
  }

  /**
   * Creates a java script object holding all course wizard data.
   *
   * @return Object with the following properties:
   *           Object.data: Array of <UserObject> the data array.
   * @see <code>ObjectVO.serializeToObject</code> for <UserObject> definition
   */
  class$.serializeToObject = function() {
    var ret_object=new Object();

    // set data
    WebSerializer.static_.setPropertyArray(ret_object, "d", this.data_);
    WebSerializer.static_.setProperty(ret_object, "s", this.searchParams_);
    WebSerializer.static_.setProperty(ret_object, "ic", this.itemCount_);
    WebSerializer.static_.setProperty(ret_object, "ec", this.exactCount_);

    return ret_object;
  }


  /**
   * Sets the search results
   *
   * @param data: Array of SearchResultVO: the search results
   */
  class$.setData = function(data)
  {
    this.data_ = data;
  }

  /**
   * Gets the search results.
   *
   * @return Array of SeacrhResultVO: the course data.
   */
  class$.getData = function()
  {
    return this.data_;
  }

  /**
   * Sets the search params (iteratorId, currentPage, ...)
   *
   * @param params: SearchParamsVO: the search params
   */
  class$.setSearchParams = function(theSearchParams)
  {
    this.searchParams_ = theSearchParams;
  }

  /**
   * Gets the search params.
   *
   * @return SearchParamsVO
   */
  class$.getSearchParams = function()
  {
    return this.searchParams_;
  }

  /**
   * Sets the itemCount
   *
   * @param theItemCount: number
   */
  class$.setItemCount = function(theItemCount)
  {
    this.itemCount_ = theItemCount;
  }

  /**
   * Gets the itemCount.
   *
   * @return itemCount
   */
  class$.getItemCount = function()
  {
    return this.itemCount_;
  }

  /**
   * Sets the exactCount
   *
   * @param isExactCount: boolean
   */
  class$.setExactCount = function(isExactCount)
  {
    this.exactCount_ = isExactCount;
  }

  /**
   * Gets the exactCount.
   *
   * @return exactCount
   */
  class$.getExactCount = function()
  {
    return this.exactCount_;
  }


// </JSClass>
