/*
 * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

/*
 * @(#)SunRIURL.java	1.4 02/01/12
 */


package com.sun.cts.implementation.sun;

import java.net.*;
import com.sun.cts.util.*;
import com.sun.cts.porting.*;

/**
  * This is a J2EE Reference specific implementation of the CTSURLInterface
  * which is to be used for J2EE-CTS testing.  CTS tests use this interface to
  * obtain the URL String to use to access a given web component.  If a given
  * J2EE Server implmentation requires that URLs be created in a different
  * manner, then this implementation can be replaced. 
  *
  * @author Kyle Grucci
  */
public class SunRIURL implements CTSURLInterface
{
	private URL url = null;
	
	/**
	  * This method is called by CTS tests to get the URL to use to access a
	  * given web component.
	  *
	  * @param       protocol - the name of the protocol.
	  * @param 		 host - the name of the host.
	  * @param 		 port - the port number.
	  * @param 		 file - the host file.
	  * @return      a valid URL object.
	  */
	public URL getURL(String protocol, String host, int port,
					 String file) throws MalformedURLException
	{
		try
		{
			url = new URL(protocol, host, port, file);      
		}
		catch(MalformedURLException e)
		{
			TestUtil.logErr("Failed during URL creation", e);
			throw e;
		}
		return url;
	}
	
	/**
	  * This method is called by CTS tests to get the URL to use to access a
	  * given web component.
	  *
	  * @param       protocol - the name of the protocol.
	  * @param 		 host - the name of the host.
	  * @param 		 port - the port number.
	  * @param 		 file - the host file.
	  * @return      a valid URL as a String.
	  */
	public String getURLString(String protocol, String host, int port,
					 String file)
	{
		if (file.startsWith("/"))
		    return protocol + "://" + host + ":" + port + file;
		else
		    return protocol + "://" + host + ":" + port + "/" + file;
	}
	
	/**
	  * This method is called by CTS tests to get the request string to use
	  * to access a given web component.
	  *
	  * @param 	 request - the request file.
	  * @return      a valid String object.
	  */
	public String getRequest(String request)
	{
	        return request;
	}  
}




