function ALOEServiceConnector (owner){
	this.owner=owner;
	this.searchURL = MACEConstants.componentsURL+"search/php/ServiceConnectorAloe.php";
	console.log("new ALOEServiceConnector");
	this.queryCache={};
}

ALOEServiceConnector.extend(ServiceConnector);

// construct parameters object for AJAX call in getResults
ALOEServiceConnector.prototype.setParams = function(query, currentPage, itemsPerPage){
	console.log("ALOEServiceConnector: set Params");
	this.currentPage=currentPage;
	this.itemsPerPage=itemsPerPage;
	this.params={tag:this.queryToSearchString(query), currentPage:this.currentPage, itemsPerPage:this.itemsPerPage};	
}

// load the results with the current params
ALOEServiceConnector.prototype.getResults = function(){
	// ALOE has no paging, so if we did the same query already, we return the cached response
	// for faster page navigation...
	if(this.queryCache[this.params.tag]){
		this.onResult(this.queryCache[this.params.tag]);
		return;
	}
	
	var _this = this;
	var callback=function (results, text) {
		console.log("ALOEServiceConnector.callback", results, text);
		if(!results.success){
			console.log("ALOEServiceConnector.onError");
			_this.onError(results);
		} else {
			console.log("ALOEServiceConnector.onSuccess");
			_this.onResult(results);
		}
	};
	// load results
	console.log("ALOEServiceConnector.getResults", _this, this.params, callback);
	$.getJSON(this.searchURL, this.params, callback, this.onError);
}

// takes a Query object and returns the respective ALOE query string 
ALOEServiceConnector.prototype.queryToSearchString = function (query){
	return query.constraints.searchTerm.join(" ");
}

// takes a server response and returns an object with (at least) resultList and numResults attributes
ALOEServiceConnector.prototype.parseResults = function (results){
	// store whole result in cache
	/*
	if(Utils.isUndefined(this.queryCache[this.params.tag])){
		this.queryCache[this.params.tag]=results;
	}
	*/
	// slice out the current page
	var resultList=results.resultList;
	$(resultList).each(function(){this.catalog = LOM.guessCatalog(this.catalog)});
	return {resultList:resultList, numResults:results.numResults};
}


