GuiController.java :  » Media » projectopenfarm » openfarm » model » controller » Java Open Source

Java Open Source » Media » projectopenfarm 
projectopenfarm » openfarm » model » controller » GuiController.java
/**
 * @Author Filipe Martins
 * 13 Dec 2010
 * OF-LauncherGui
 */
package openfarm.model.controller;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import openfarm.model.process.admin.ProcessCoordinator;
import openfarm.model.settings.InterpreterProperties;
import openfarm.model.settings.ManagerProperties;



public class GuiController
{
  private static GuiController instance;  
  private ManagerProperties managerProperties;
  private InterpreterProperties interpreterProperties;
  
  private ProcessCoordinator interpreterProcess;
  private ProcessCoordinator managerProcess;
  
  private Map<String,String> envMap;  
  
  private GuiController()
  {
    envMap = new HashMap<String, String>();  
    managerProperties = new ManagerProperties();  
    interpreterProperties = new InterpreterProperties();    
  }
  
  
  public static GuiController getMainController()
  {
    if(instance == null)
      instance = new GuiController();
    
    return instance;
  }
  
  
  public void loadProperties()
  {  
    //if there is no config file
    envMap.putAll(getSystemDefaultEnv());
    managerProperties.setSettingsLoaded(false);
    interpreterProperties.setSettingsLoaded(false);    
    //else load the config file    
  }
  
  public static Map<String,String> getSystemDefaultEnv()
  {
    return System.getenv();
  }
  
  public Map<String, String> getDefaultManagerEnv()
  {  
    if(managerProperties.getBinDir() != null)
    {      
      String catalinaHome = new File(managerProperties.getBinDir().getAbsolutePath()).getParent();
      envMap.put(ManagerProperties.ENV_CATALINA_HOME, catalinaHome);      
    }    
  
    return envMap;
  }
  
  
  

  //sets and gets
  public ManagerProperties getManagerProperties()
  {
    return managerProperties;
  }

  public void setManagerProperties(ManagerProperties managerProperties)
  {
    this.managerProperties = managerProperties;
  }

  public InterpreterProperties getInterpreterProperties()
  {
    return interpreterProperties;
  }

  public void setInterpreterProperties(InterpreterProperties interpreterProperties)
  {
    this.interpreterProperties = interpreterProperties;
  }


  public ProcessCoordinator getInterpreterProcess()
  {
    return interpreterProcess;
  }


  public void setInterpreterProcess(ProcessCoordinator interpreterProcess)
  {
    this.interpreterProcess = interpreterProcess;
    
    if(interpreterProcess!=null)
      interpreterProcess.setEnvs(null);
  }


  public ProcessCoordinator getManagerProcess()
  {
    return managerProcess;
  }


  public void setManagerProcess(ProcessCoordinator managerProcess)
  {
    this.managerProcess = managerProcess;
    
    if(managerProcess != null)
    {
      this.managerProcess.setEnvs(getDefaultManagerEnv());
    }
  }

  
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.