/**
  * This function is used to perform following checking (validation)
  * for capability negotiation.
  *  (1) Check client request's 'DataServiceVersion' header value is 
  *      less than or equal to the minimum version required to intercept
  *      the response
  *  (2) Check client request's 'MaxDataServiceVersion' header value is
  *      less than or equal to the version of protocol required to generate
  *      the response
  *  (3) Check the configured maximum protocol version is less than or equal 
  *      to the version of protocol required to generate the response
  *  In addition to these checking, this function is also responsible for
  *  initializing the properties respresenting 'DataServiceVersion' and
  *  'MaxDataServiceVersion'.
  *  
  * @param RequestDescription $requestDescription The request description object
  * @param DataService        $dataService        The Service to check
  * 
  * @return void
  * 
  * @throws ODataException If any of the above 3 check fails.
  */
 public static function checkVersion(RequestDescription $requestDescription, DataService $dataService)
 {
     if (is_null($requestDescription->_requestDataServiceVersion)) {
         $version = $dataService->getHost()->getRequestVersion();
         //'DataServiceVersion' header not present in the request, so use
         //default value as the maximum version number that the server can
         //interpret.
         if (is_null($version)) {
             $knownVersions = $requestDescription::getKnownDataServiceVersions();
             $version = $knownVersions[count($knownVersions) - 1];
         } else {
             $version = $requestDescription::_validateAndGetVersion($version, ODataConstants::ODATAVERSIONHEADER);
         }
         $requestDescription->_requestDataServiceVersion = $version;
     }
     if (is_null($requestDescription->_requestMaxDataServiceVersion)) {
         $version = $dataService->getHost()->getRequestMaxVersion();
         //'MaxDataServiceVersion' header not present in the request, so use
         //default value as the maximum version number that the server can
         //interpret.
         if (is_null($version)) {
             $knownVersions = $requestDescription::getKnownDataServiceVersions();
             $version = $knownVersions[count($knownVersions) - 1];
         } else {
             $version = $requestDescription::_validateAndGetVersion($version, ODataConstants::ODATAMAXVERSIONHEADER);
         }
         $requestDescription->_requestMaxDataServiceVersion = $version;
     }
     if ($requestDescription->_requestDataServiceVersion->compare($requestDescription->_minimumRequiredClientVersion) < 0) {
         ODataException::createBadRequestError(Messages::requestDescriptionDataServiceVersionTooLow($requestDescription->_requestDataServiceVersion->toString(), $requestDescription->_minimumRequiredClientVersion->toString()));
     }
     if ($requestDescription->_requestMaxDataServiceVersion->compare($requestDescription->_responseDataServiceVersion) < 0) {
         ODataException::createBadRequestError(Messages::requestDescriptionDataServiceVersionTooLow($requestDescription->_requestMaxDataServiceVersion->toString(), $requestDescription->_responseDataServiceVersion->toString()));
     }
     $configuration = $dataService->getServiceConfiguration();
     $maxConfiguredProtocolVersion = $configuration->getMaxDataServiceVersionObject();
     if ($maxConfiguredProtocolVersion->compare($requestDescription->_responseDataServiceVersion) < 0) {
         ODataException::createBadRequestError(Messages::requestDescriptionResponseVersionIsBiggerThanProtocolVersion($requestDescription->_responseDataServiceVersion->toString(), $maxConfiguredProtocolVersion->toString()));
     }
 }