package eu.dnetlib.data.utility.featureextraction;

import java.util.List;

import javax.jws.WebService;
import javax.xml.ws.wsaddressing.W3CEndpointReference;

import eu.dnetlib.common.ws.DriverServiceImpl;
import eu.dnetlib.data.utility.featureextraction.dataprovider.FeatureExtractionDataProvider;
import eu.dnetlib.enabling.resultset.rmi.ResultSetService;
import eu.dnetlib.resultset.impl.builder.IResultSetBuilder;

/**
 * The Class FeatureExtractionServiceImpl.
 */
@WebService(serviceName="FeatureExtractionService",
		endpointInterface="eu.dnetlib.data.utility.featureextraction.IFeatureExtractionService",
		targetNamespace="http://schemas.xmlsoap.org/soap/envelope/")
public class FeatureExtractionServiceImpl extends DriverServiceImpl implements IFeatureExtractionService{

	
	private FeatureExtractionDataProvider dataProvider;
	
	private ResultSetService resultsetService;
	
	/** Result Set service location. */
	private String resultSetLocation;
	
	private IResultSetBuilder resultSetBuilder;
	
	/**
	 * Inits the.
	 */
	public void init() {
		this.resultsetService = resultSetBuilder.build(resultSetLocation);
	}
	
	/* (non-Javadoc)
	 * @see eu.dnetlib.data.utility.featureextraction.IFeatureExtractionService#extract(eu.dnetlib.data.utility.featureextraction.Feature, javax.xml.ws.wsaddressing.W3CEndpointReference)
	 */
	@Override
	public W3CEndpointReference extract(Feature feature,
			W3CEndpointReference rsEpr)  throws FeatureExtractionException {
		
		if (feature == null)
			throw new FeatureExtractionException("Wrong parameter! " +
				"feature can not be null!");
		if ( !this.dataProvider.getFeatureMap().containsKey(feature.getName())){
			throw new FeatureExtractionException("unsupported feature: " + feature.getName());
		}
		
		if (rsEpr == null)
			throw new FeatureExtractionException("Wrong parameter! " +
				"rsEpr can not be null!");
		
		return this.dataProvider.createResultSet(feature, rsEpr, resultsetService);
	}

	/* (non-Javadoc)
	 * @see eu.dnetlib.data.utility.featureextraction.IFeatureExtractionService#getFeatures()
	 */
	@Override
	public List<Feature> getFeatures() {
		return dataProvider.getFeatures();
	}

	/* (non-Javadoc)
	 * @see eu.dnetlib.data.utility.featureextraction.IFeatureExtractionService#getStatusInformation(java.lang.String)
	 */
	@Override
	public String getStatusInformation(String id)
			throws FeatureExtractionException {
		return dataProvider.getStatusInformation(id);
	}
	
	/**
	 * @param dataProvider the dataProvider to set
	 */
	public void setDataProvider(FeatureExtractionDataProvider dataProvider) {
		this.dataProvider = dataProvider;
	}

	/**
	 * @return the dataProvider
	 */
	public FeatureExtractionDataProvider getDataProvider() {
		return dataProvider;
	}	
	
	/**
	 * Returns ResultSet builder module.
	 * @return ResultSet builder module
	 */
	public IResultSetBuilder getResultSetBuilder() {
		return resultSetBuilder;
	}

	/**
	 * Sets ResultSet builder module.
	 * @param resultSetBuilder
	 */
	public void setResultSetBuilder(IResultSetBuilder resultSetBuilder) {
		this.resultSetBuilder = resultSetBuilder;
	}
	
	/**
	 * Returns target Result Set service location.
	 * 
	 * @return target Result Set service location
	 */
	public String getResultSetLocation() {
		return resultSetLocation;
	}

	/**
	 * Sets target Result Set service location.
	 * 
	 * @param resultSetLocation
	 */
	public void setResultSetLocation(String resultSetLocation) {
		this.resultSetLocation = resultSetLocation;
	}

}
