package edu.usc.glidein.service.impl;

import java.rmi.RemoteException;

import org.apache.log4j.Logger;
import org.globus.wsrf.ResourceContext;
import org.globus.wsrf.ResourceKey;

import edu.usc.glidein.stubs.types.EmptyObject;
import edu.usc.glidein.stubs.types.Site;

public class SiteService 
{
	private Logger logger = Logger.getLogger(SiteService.class);
	
	private SiteResourceHome getResourceHome() throws RemoteException
	{
		try {
			return (SiteResourceHome)ResourceContext.getResourceContext().getResourceHome();
		} catch (Exception e) {
			String message = "Unable to find site resource home";
			logger.error(message,e);
			throw new RemoteException(message, e);
		}	
	}
	
	private SiteResource getResource() throws RemoteException
	{
		try {
			return (SiteResource) ResourceContext.getResourceContext().getResource();
		} catch (Exception e) {
			String message = "Unable to find site resource";
			logger.error(message,e);
			throw new RemoteException(message, e);
		}	
	}
	
	private ResourceKey getResourceKey() throws RemoteException
	{
		try {
			return (ResourceKey) ResourceContext.getResourceContext().getResourceKey();
		} catch (Exception e) {
			String message = "Unable to find site resource key";
			logger.error(message,e);
			throw new RemoteException(message, e);
		}	
	}
	
	public Site getSite(EmptyObject empty) throws RemoteException
	{
		return getResource().getSite();
	}
	
	public EmptyObject submit(EmptyObject empty) throws RemoteException
	{
		SiteResource resource = getResource();
		resource.submit();
		return new EmptyObject();
	}
	
	public EmptyObject remove(EmptyObject empty) throws RemoteException
	{
		// Delete the resource from the databse
		getResource().delete();
		
		// Remove the resource from the resource home
		getResourceHome().remove(getResourceKey());
		
		return new EmptyObject();
	}
}
@@ -1648,127 +1648,8 @@
 %0A%09%7B%0A
-%09%09// Delete the resource from the databse%0A%09%09getResource().delete();%0A%09%09%0A%09%09// Remove the resource from the resource home%0A
 %09%09ge
@@ -1694,11 +1694,8 @@
 ));%0A
-%09%09%0A
 %09%09re

Fix remove operation