/**
 * Copyright (c) 2008-2012 EBM WebSourcing, 2012-2013 Linagora
 * 
 * This program/library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 2.1 of the License, or (at your
 * option) any later version.
 * 
 * This program/library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
 * for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program/library; If not, see <http://www.gnu.org/licenses/>
 * for the GNU Lesser General Public License version 2.1.
 */
package org.ow2.petals.se.xslt;

import java.util.concurrent.ConcurrentHashMap;

import org.ow2.petals.component.framework.bc.AbstractBindingComponent;
import org.ow2.petals.component.framework.su.AbstractServiceUnitManager;
import org.ow2.petals.se.xslt.model.XsltConfigurationHandler;

/**
 * The component class of the XSLT service engine.
 * @author Roland Naudin - EBM WebSourcing
 * @author Vincent Zurczak - EBM WebSourcing
 */
public class XsltSe extends AbstractBindingComponent {

	/**
	 * This map is used to get the XSLT configuration associated with an end-point name.
	 */
	private final ConcurrentHashMap<String,XsltConfigurationHandler> endpointNameToXsltConfigurationHandler =
		new ConcurrentHashMap<String,XsltConfigurationHandler> ();


	/*
	 * (non-Javadoc)
	 * @see org.ow2.petals.component.framework.bc.AbstractBindingComponent
	 * #createServiceUnitManager()
	 */
	@Override
	protected AbstractServiceUnitManager createServiceUnitManager() {
		return new XsltSuManager(this);
	}


	/**
	 * @param endpointName the end-point name
	 * @param xsltConfigurationHandler the XSLT configuration handler
	 * @return the previous XSLT configuration handler that was registered for this end-point name
	 * @see java.util.concurrent.ConcurrentHashMap#put(java.lang.Object, java.lang.Object)
	 */
	public XsltConfigurationHandler registerXsltConfigurationHandler(
			String endpointName,
			XsltConfigurationHandler xsltConfigurationHandler ) {

		return this.endpointNameToXsltConfigurationHandler.put( endpointName, xsltConfigurationHandler );
	}


	/**
	 * @param endpointName the end-point name
	 * @return the XSLT configuration handler that was registered for this end-point name
	 * @see java.util.concurrent.ConcurrentHashMap#remove(java.lang.Object)
	 */
	public XsltConfigurationHandler removeXsltConfigurationHandler( String endpointName ) {
		return this.endpointNameToXsltConfigurationHandler.remove( endpointName );
	}


	/**
	 * @param endpointName the end-point name
	 * @return the XSLT configuration handler associated with this end-point name
	 * @see java.util.Map#get(java.lang.Object)
	 */
	public XsltConfigurationHandler getXsltConfigurationHandler( String endpointName ) {
		return this.endpointNameToXsltConfigurationHandler.get( endpointName );
	}
}
