package edu.usc.glidein.api;

import java.net.URL;
import java.rmi.RemoteException;

import javax.xml.rpc.ServiceException;
import javax.xml.rpc.Stub;

import org.apache.axis.message.addressing.EndpointReferenceType;

import edu.usc.glidein.stubs.SitePortType;
import edu.usc.glidein.stubs.service.SiteServiceAddressingLocator;
import edu.usc.glidein.stubs.types.EmptyObject;
import edu.usc.glidein.stubs.types.Site;
import edu.usc.glidein.util.AddressingUtil;

public class SiteService extends BaseService
{	
	public SiteService(EndpointReferenceType epr)
	{
		super(epr);
	}
	
	public SiteService(URL serviceUrl, int id) throws GlideinException
	{
		super(SiteService.createEPR(serviceUrl,id));	
	}
		
	public static EndpointReferenceType createEPR(URL serviceUrl, int id)
	throws GlideinException
	{
		try {
			return AddressingUtil.getSiteEPR(serviceUrl,id);
		} catch (Exception e) {
			throw new GlideinException(e.getMessage(),e);
		}
	}
	
	public Site getSite() throws GlideinException
	{
		try {
			SitePortType instance = getPort();
			Site site = instance.getSite(new EmptyObject());
			return site;
		} catch (RemoteException re) {
			throw new GlideinException("Unable to get site: "+
					re.getMessage(),re);
		}
	}
	
	public void submit(EndpointReferenceType credentialEPR) throws GlideinException
	{
		try {
			SitePortType instance = getPort();
			instance.submit(credentialEPR);
		} catch (RemoteException re) {
			throw new GlideinException("Unable to submit site: "+
					re.getMessage(),re);
		}
	}
	
	public void remove(boolean force) throws GlideinException
	{
		try {
			SitePortType instance = getPort();
			instance.remove(force);
		} catch (RemoteException re) {
			throw new GlideinException("Unable to remove site: "+
					re.getMessage(),re);
		}
	}
	
	private SitePortType getPort() throws GlideinException
	{
		try {
			SiteServiceAddressingLocator locator = 
				new SiteServiceAddressingLocator();
			SitePortType instance = 
				locator.getSitePortTypePort(getEPR());
			if (getDescriptor() != null) {
				((Stub)instance)._setProperty(
						"clientDescriptor", getDescriptor());
			}
			return instance;
		} catch (ServiceException se) {
			throw new GlideinException("Unable to get SitePortType: "+
					se.getMessage(),se);
		}
	}
}

@@ -211,16 +211,60 @@
 eType;%0A%0A
+import edu.usc.glidein.stubs.RemoveRequest;%0A
 import e
@@ -1593,16 +1593,53 @@
 an force
+, EndpointReferenceType credentialEPR
 ) throws
@@ -1697,32 +1697,100 @@
 ce = getPort();%0A
+%09%09%09RemoveRequest request = new RemoveRequest(credentialEPR, force);%0A
 %09%09%09instance.remo
@@ -1792,21 +1792,23 @@
 .remove(
-force
+request
 );%0A%09%09%7D c

Add delegated credential to remove operation