

package gov.va.med.mediator.client.messagemediator;


import gov.va.med.cds.util.EndpointResolver;
import gov.va.med.mediator.client.jaxws.MessageMediatorServiceInterface;
import gov.va.med.mediator.exception.MediatorClientException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.net.URL;

import javax.xml.namespace.QName;


/**
 * 
 * Factory that creates MessageMediator delegate.
 * 
 */
public class MessageMediatorFactory
{
    // Use this version for Remote EJB
    private static Log logger = LogFactory.getLog( MessageMediatorFactory.class );

    private String serviceBindingId = null;

    private EndpointResolver endpointResolver = null;


    public synchronized MessageMediatorInterface create( )
    {
        try
        {
            URL endpoint = new URL( endpointResolver.resolve( serviceBindingId ) );

            MessageMediatorServiceInterface mediatorService = new MessageMediatorServiceInterface( endpoint, new QName(
                            "http://messagemediator.client.mediator.med.DNS   ", "MessageMediatorServiceInterface" ) );
            return mediatorService.getMessageMediatorInterfaceHttpPort();
        }
        catch ( Exception ex )
        {
            logger.error( "Error creating mediator webservice cient.", ex );
            throw new MediatorClientException( "Error creating mediator service objects.", ex );
        }
    }


    public void setServiceBindingId( String serviceBindingId )
    {
        this.serviceBindingId = serviceBindingId;
    }


    public void setEndpointResolver( EndpointResolver endpointResolver )
    {
        this.endpointResolver = endpointResolver;
    }

}
