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.Glidein;
import edu.usc.glidein.stubs.types.GlideinStatus;

public class GlideinService
{
	private Logger logger = Logger.getLogger(GlideinService.class);
	
	private GlideinResourceHome getResourceHome() throws RemoteException
	{
		try {
			Object resourceHome = ResourceContext.getResourceContext().getResourceHome();
			GlideinResourceHome glideinResourceHome = (GlideinResourceHome) resourceHome;
			return glideinResourceHome;
		} catch (Exception e) {
			String message = "Unable to find glidein resource home";
			logger.error(message,e);
			throw new RemoteException(message, e);
		}
	}
	
	private GlideinResource getResource() throws RemoteException
	{
		try {
			Object resource = ResourceContext.getResourceContext().getResource();
			GlideinResource glideinResource = (GlideinResource) resource;
			return glideinResource;
		} catch (Exception e) {
			String message = "Unable to find glidein resource";
			logger.error(message,e);
			throw new RemoteException(message, e);
		}
	}
	
	private ResourceKey getResourceKey() throws RemoteException 
	{
		try {
			return ResourceContext.getResourceContext().getResourceKey();
		} catch (Exception e) {
			String message = "Unable to find glidein resource key";
			logger.error(message,e);
			throw new RemoteException(message, e);
		}
	}
	
	public GlideinStatus getStatus(EmptyObject empty) throws RemoteException {
		return getResource().getStatus();
	}
	
	public Glidein getGlidein(EmptyObject empty) throws RemoteException {
		return getResource().getGlidein();
	}
	
	public EmptyObject start(EmptyObject empty) throws RemoteException {
		// TODO submit glidein job
		return new EmptyObject();
	}
	
	public EmptyObject cancel(EmptyObject empty) throws RemoteException {
		// TODO cancel glidein job
		return new EmptyObject();
	}
	
	public EmptyObject delete(EmptyObject empty) throws RemoteException {
		getResource().delete();
		getResourceHome().remove(getResourceKey());
		return new EmptyObject();
	}
}

@@ -270,58 +270,8 @@
 ein;
-%0Aimport edu.usc.glidein.stubs.types.GlideinStatus;
 %0A%0Apu
@@ -1508,125 +1508,8 @@
 %7D%0A%09%0A
-%09public GlideinStatus getStatus(EmptyObject empty) throws RemoteException %7B%0A%09%09return getResource().getStatus();%0A%09%7D%0A%09%0A
 %09pub

Remove getStatus