/**
 * Copyright 2008-2009 DRIVER PROJECT (Bielefeld University)
 * Original author: Marek Imialek <marek.imialek at uni-bielefeld.de>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package eu.dnetlib.contract.mocks;

import java.io.StringReader;
import java.util.List;

import javax.xml.transform.stream.StreamSource;
import javax.xml.ws.wsaddressing.W3CEndpointReference;

import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpDocumentNotFoundException;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;

/**
 * @author <a href="mailto:marek.imialek at uni-bielefeld.de">Marek Imialek</a>
 *
 */
public class mockISLookUpService implements ISLookUpService {

	public mockISStorage isStorage;
	
	/* (non-Javadoc)
	 * @see eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService#flushCachedResultSets()
	 */
	@Override
	public Boolean flushCachedResultSets() {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService#getCollection(java.lang.String, java.lang.String)
	 */
	@Override
	public String getCollection(String profId, String format)
			throws ISLookUpException {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService#getResourceProfile(java.lang.String)
	 */
	@Override
	public String getResourceProfile(String profId) throws ISLookUpException,
			ISLookUpDocumentNotFoundException {
		
		if (this.isStorage.get(profId) == null)
			throw new ISLookUpDocumentNotFoundException(
						"Resource not found in the storage");

		return isStorage.get(profId);
	}

	/* (non-Javadoc)
	 * @see eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService#getResourceProfileByQuery(java.lang.String)
	 */
	@Override
	public String getResourceProfileByQuery(String XQuery)
			throws ISLookUpException, ISLookUpDocumentNotFoundException {
		return null;
	}

	/* (non-Javadoc)
	 * @see eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService#getResourceQoSParams(java.lang.String)
	 */
	@Override
	public String getResourceQoSParams(String id) throws ISLookUpException {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService#getResourceTypeSchema(java.lang.String)
	 */
	@Override
	public String getResourceTypeSchema(String resourceType)
			throws ISLookUpException {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService#listCollections(java.lang.String, java.lang.String, java.lang.String)
	 */
	@Override
	public W3CEndpointReference listCollections(String format, String idfather,
			String owner) throws ISLookUpException {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService#listCommunities()
	 */
	@Override
	public W3CEndpointReference listCommunities() throws ISLookUpException {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService#listDHNIDs()
	 */
	@Override
	public List<String> listDHNIDs() throws ISLookUpException {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService#listMDStores(java.lang.String)
	 */
	@Override
	public W3CEndpointReference listMDStores(String metadataformat)
			throws ISLookUpException {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService#listResourceProfiles(java.lang.String, java.lang.String, java.lang.String)
	 */
	@Override
	public W3CEndpointReference listResourceProfiles(String resourceKind,
			String format, String resourceType) throws ISLookUpException {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService#listResourceTypes()
	 */
	@Override
	public List<String> listResourceTypes() throws ISLookUpException {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService#listServiceIDs(java.lang.String)
	 */
	@Override
	public List<String> listServiceIDs(String serviceType)
			throws ISLookUpException {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService#listServiceTypes()
	 */
	@Override
	public List<String> listServiceTypes() throws ISLookUpException {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService#quickSearchProfile(java.lang.String)
	 */
	@Override
	public List<String> quickSearchProfile(String xquery)
			throws ISLookUpException {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService#retrieveCollection(java.lang.String)
	 */
	@Override
	public String retrieveCollection(String profId) throws ISLookUpException {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService#searchProfile(java.lang.String)
	 */
	@Override
	public W3CEndpointReference searchProfile(String xquery) {
			
	
		String rsEPR = "<EndpointReference xmlns=\"http://www.w3.org/2005/08/addressing\">" +
				"<Address>http://146.48.85.160:8280/is/services/resultSet</Address>" +
				"<ReferenceParameters><ResourceIdentifier:" +
				"ResourceIdentifier xmlns:wsa=\"http://www.w3.org/2005/08/addressing\" " +
				"xmlns:ResourceIdentifier=\"" +
				"http://www.driver.org\">1" +
				"</ResourceIdentifier:ResourceIdentifier></ReferenceParameters>" +
				"<Metadata><wsaw:ServiceName EndpointName=\"theResultSet\" " +
				"xmlns=\"\" xmlns:ns2=\"http://www.w3.org/2006/02/addressing/wsdl\" " +
				"xmlns:wsa=\"http://www.w3.org/2005/08/addressing\" " +
				"xmlns:wsaw=\"http://www.w3.org/2006/05/addressing/wsdl\" " +
				"xmlns:ns5=\"http://www.w3.org/2005/08/addressing\">" +
				"ns2:theResultSet</wsaw:ServiceName><wsdl:definitions " +
				"xmlns:wsa=\"http://www.w3.org/2005/08/addressing\" " +
				"xmlns:wsaw=\"http://www.w3.org/2006/05/addressing/wsdl\" " +
				"xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\">" +
				"<wsdl:import location=\"http://146.48.85.160:8280/is/services/resultSet?WSDL\"" +
				" namespace=\"http://www.w3.org/2006/02/addressing/wsdl\" " +
				"xmlns=\"\" xmlns:ns5=\"http://www.w3.org/2005/08/addressing\"/>" +
				"</wsdl:definitions></Metadata></EndpointReference>";
		
		W3CEndpointReference epr = (W3CEndpointReference) W3CEndpointReference
				.readFrom(new StreamSource(new StringReader(rsEPR)));
		return epr;
	}

	/* (non-Javadoc)
	 * @see eu.dnetlib.common.rmi.BaseService#identify()
	 */
	@Override
	public String identify() {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see eu.dnetlib.common.rmi.BaseService#notify(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
	 */
	@Override
	public void notify(String subscriptionId, String topic, String isId,
			String message) {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see eu.dnetlib.common.rmi.BaseService#start()
	 */
	@Override
	public void start() {
		// TODO Auto-generated method stub

	}

	/**
	 * @param mockISStorage the mockISStorage to set
	 */
	public void setIsStorage(mockISStorage isStorage) {
		this.isStorage = isStorage;
	}

	/**
	 * @return the mockISStorage
	 */
	public mockISStorage getIsStorage() {
		return isStorage;
	}
}
