package edu.usc.glidein.service.core;

import java.io.File;

import org.globus.cog.abstraction.interfaces.ExecutionService;
import org.globus.cog.abstraction.interfaces.TaskHandler;

import edu.usc.glidein.service.types.ExecutionServiceDescription;
import edu.usc.glidein.service.types.SiteDescription;

public class SiteFactory 
{
	private static SiteFactory singleton;
	
	private SiteFactory() { }
	
	public synchronized static SiteFactory getInstance()
	{
		if(singleton == null){
			singleton = new SiteFactory();
		}
		return singleton;
	}
	
	public Site createSite(int id, SiteDescription description) 
	throws Exception
	{
		Site site = new Site(id,description.getName());
		
		// Install path
		String installPath = description.getInstallPath();
		if(installPath == null || "".equals(installPath)) 
			throw new Exception("Invalid install path: "+installPath);
		site.setInstallPath(description.getInstallPath());
		
		// Local path
		String localPath = description.getLocalPath();
		if(localPath == null || "".equals(localPath)) 
			localPath = description.getInstallPath();
		site.setLocalPath(localPath);
		
		// TODO Save configuration to a file
		String config = description.getConfiguration();
		File configuration = null;
		site.setConfiguration(configuration);
		
		// TODO Get proxy credential
		
		// TODO Security context
		
		// Glidein execution service
		// TODO Service contact
		ExecutionServiceDescription glideinServiceDescription = 
			description.getGlideinService();
		ExecutionService glideinService = null; // TODO glideinService
		site.setGlideinService(glideinService);
		
		// TODO Staging execution service
		// TODO Service contact
		ExecutionServiceDescription stagingServiceDescription =
			description.getStagingService();
		ExecutionService stagingService = null;
		if(stagingServiceDescription == null){
			stagingService = glideinService;
		}
		else {
			stagingService = null; // TODO stagingService
		}
		site.setStagingService(stagingService);
		
		return site;
	}
}

@@ -58,196 +58,8 @@
 e;%0A%0A
-import org.globus.cog.abstraction.interfaces.ExecutionService;%0Aimport org.globus.cog.abstraction.interfaces.TaskHandler;%0A%0Aimport edu.usc.glidein.service.types.ExecutionServiceDescription;%0A
 impo
@@ -1123,686 +1123,8 @@
 %0A%09%09%0A
-%09%09// TODO Security context%0A%09%09%0A%09%09// Glidein execution service%0A%09%09// TODO Service contact%0A%09%09ExecutionServiceDescription glideinServiceDescription = %0A%09%09%09description.getGlideinService();%0A%09%09ExecutionService glideinService = null; // TODO glideinService%0A%09%09site.setGlideinService(glideinService);%0A%09%09%0A%09%09// TODO Staging execution service%0A%09%09// TODO Service contact%0A%09%09ExecutionServiceDescription stagingServiceDescription =%0A%09%09%09description.getStagingService();%0A%09%09ExecutionService stagingService = null;%0A%09%09if(stagingServiceDescription == null)%7B%0A%09%09%09stagingService = glideinService;%0A%09%09%7D%0A%09%09else %7B%0A%09%09%09stagingService = null; // TODO stagingService%0A%09%09%7D%0A%09%09site.setStagingService(stagingService);%0A%09%09%0A
 %09%09re

Remove some CoG stuff