/**
 * 
 */
package it.mice.voila.runtime.springws.interceptors;

import java.io.IOException;

import javax.xml.transform.TransformerException;

import org.springframework.ws.context.MessageContext;
import org.springframework.ws.server.endpoint.MethodEndpoint;
import org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor;
import org.xml.sax.SAXException;

/**
 *
 */
public class EndpointFilteringPayloadValidatingInterceptor extends PayloadValidatingInterceptor {
	private String filterOnEndpointBeanName;

	public String getFilterOnEndpointBeanName() {
		return filterOnEndpointBeanName;
	}

	public void setFilterOnEndpointBeanName(String filterOnEndpointBeanName) {
		this.filterOnEndpointBeanName = filterOnEndpointBeanName;
	}

	@Override
	public boolean handleRequest(MessageContext messageContext, Object endpoint) throws IOException,
			SAXException, TransformerException {
		// TODO Auto-generated method stub
		if (endpoint instanceof MethodEndpoint) {
			MethodEndpoint methodEndpoint = (MethodEndpoint)endpoint;
			if (methodEndpoint.getBean().equals(getFilterOnEndpointBeanName())) {
				return super.handleRequest(messageContext, endpoint);
			}
		}
		return true;
	}

	@Override
	public boolean handleResponse(MessageContext messageContext, Object endpoint) throws IOException,
			SAXException {
		// TODO Auto-generated method stub
		return super.handleResponse(messageContext, endpoint);
	}
	
}
