/*
 * Copyright 2000-2003 Oracle, Inc. This software was developed in conjunction with the National Cancer Institute, and so to the extent government employees are co-authors, any rights in such works shall be subject to Title 17 of the United States Code, section 105.
 *
 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the disclaimer of Article 3, below. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
 *
 * 2. The end-user documentation included with the redistribution, if any, must include the following acknowledgment:
 *
 * "This product includes software developed by Oracle, Inc. and the National Cancer Institute."
 *
 * If no such end-user documentation is to be included, this acknowledgment shall appear in the software itself, wherever such third-party acknowledgments normally appear.
 *
 * 3. The names "The National Cancer Institute", "NCI" and "Oracle" must not be used to endorse or promote products derived from this software.
 *
 * 4. This license does not authorize the incorporation of this software into any proprietary programs. This license does not authorize the recipient to use any trademarks owned by either NCI or Oracle, Inc.
 *
 * 5. THIS SOFTWARE IS PROVIDED "AS IS," AND ANY EXPRESSED OR IMPLIED WARRANTIES, (INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE) ARE DISCLAIMED. IN NO EVENT SHALL THE NATIONAL CANCER INSTITUTE, ORACLE, OR THEIR AFFILIATES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
 */
package gov.nih.nci.ncicb.cadsr.loader.util;

import gov.nih.nci.ncicb.cadsr.loader.RoundtripAction;
import gov.nih.nci.ncicb.cadsr.loader.UMLLoader;
import gov.nih.nci.ncicb.cadsr.loader.UMLLoaderGUI;
import gov.nih.nci.ncicb.cadsr.loader.UserSelections;
import gov.nih.nci.ncicb.cadsr.loader.event.UMLHandler;
import gov.nih.nci.ncicb.cadsr.loader.ext.CadsrPublicApiModule;
import gov.nih.nci.ncicb.cadsr.loader.parser.ElementWriter;
import gov.nih.nci.ncicb.cadsr.loader.ui.CadsrDialog;
import gov.nih.nci.ncicb.cadsr.loader.ui.DEReuseDialog;
import gov.nih.nci.ncicb.cadsr.loader.ui.WizardController;
import gov.nih.nci.ncicb.cadsr.loader.validator.Validator;
import gov.nih.nci.ncicb.cadsr.semconn.SemanticConnector;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class BeansAccessor {
  
  private static Logger logger = Logger.getLogger(BeansAccessor.class.getName());

//   private static XmlBeanFactory factory = null;
  private static BeanFactory factory = null;

  public static ElementWriter getWriter() {
    RunMode mode = (RunMode)UserSelections.getInstance().getProperty("MODE");
    if(mode.equals(RunMode.Reviewer)) {
      return (ElementWriter)getFactory().getBean("xmiWriter");
    } else if(mode.equals(RunMode.Curator)) {
      return (ElementWriter)getFactory().getBean("csvWriter");
    }
    else return null;
  }

  public static SemanticConnector getSemanticConnector() {
    return (SemanticConnector)getFactory().getBean("semanticConnector");
  }
  
  public static CadsrPublicApiModule getCadsrPublicApiModule() {
    return (CadsrPublicApiModule)getFactory().getBean("cadsrPublicApiModule");
  }

  public static UMLLoaderGUI getSiw() {
    return (UMLLoaderGUI)getFactory().getBean("siw");
  }

  public static WizardController getWizardController() {
    return (WizardController)getFactory().getBean("wizardController");
  }
  
  public static UMLLoader getUmlLoader() {
    return (UMLLoader)getFactory().getBean("umlLoader");
  }

  public static RoundtripAction getRoundtripAction() {
    return (RoundtripAction)getFactory().getBean("roundtripAction");
  }

  public static CadsrDialog getCadsrDEDialog() {
    return (CadsrDialog)getFactory().getBean("cadsrDEDialog");
  }

  public static CadsrDialog getCadsrVDDialog() {
    return (CadsrDialog)getFactory().getBean("cadsrVDDialog");
  }

  public static DEReuseDialog getDEReuseDialog() {
    return (DEReuseDialog)getFactory().getBean("deReuseDialog");
  }

  public static Validator getValidator() {
    return (Validator)getFactory().getBean("mainValidator");
  }

  public static UMLHandler getUMLHandler() {
    return (UMLHandler)getFactory().getBean("umlEventHandler");
  }

  private static BeanFactory getFactory() {
    try {
      if(factory != null) {
        return factory;
      }
      factory = new ClassPathXmlApplicationContext(new String[]{"beans.xml", "spring-datasources.xml"});
//       factory = new XmlBeanFactory(new InputStreamResource(Thread.currentThread().getContextClassLoader().getResourceAsStream("beans.xml")));
      return factory;
    } catch (Exception e){
      logger.error(e.getMessage());
    } // end of try-catch
    return null;
  }
 
  
 
}
@@ -4232,32 +4232,35 @@
 lLoader%22);%0A  %7D%0A%0A
+// 
   public static 
@@ -4294,24 +4294,27 @@
 pAction() %7B%0A
+// 
     return (
@@ -4366,24 +4366,27 @@
 ipAction%22);%0A
+// 
   %7D%0A%0A  publi
@@ -4725,32 +4725,35 @@
 eDialog%22);%0A  %7D%0A%0A
+// 
   public static 
@@ -4771,32 +4771,35 @@
 etValidator() %7B%0A
+// 
     return (Vali
@@ -4839,29 +4839,35 @@
 alidator%22);%0A
+// 
   %7D%0A%0A
+// 
   public sta
@@ -4891,32 +4891,35 @@
 tUMLHandler() %7B%0A
+// 
     return (UMLH
@@ -4962,24 +4962,27 @@
 tHandler%22);%0A
+// 
   %7D%0A%0A  priva

remove some methods -- no longer needed