<commit_before>/*
 * Created on Dec 30, 2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package gov.nih.nci.security.system;

import java.util.*;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;
import java.io.*;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;


/**
 * @author kumarvi
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 * This class will be used by UserProvisioningManagerImpl to get
 * appropriate sessionFactory handle
 */
public class ApplicationSessionFactory {

	private static Hashtable appSessionFactories;
	  
	/**
	 * This method will read a system wide configuration file
	 * called ApplicationSecurityConfig.xml and initilaize the
	 * session factories as per the application context names
	 */
	static{
		appSessionFactories = new Hashtable();
		/**
		 * Read all the applicationContext entries in
		 * the file and iterate through them.
		 *   for(int i=0;i<numberOfEntries;i++){
		 *   build session factory here
		 *   appSessionFactories.put(applicationContextName,sf);
		 * }
		 */
		
		Document configDocument = getConfigDocument();
		Element applicationsElement = configDocument.getRootElement();
		List applications = applicationsElement.getChildren("application");
		 Iterator appIterator  = applications.iterator();
		 while(appIterator.hasNext()){
		 	Element application = (Element)appIterator.next();
		 	Element context = application.getChild("context");
		 	String context_name = context.getAttributeValue("context-name");
		 	Element authorization = application.getChild("authorization");
		 	Element hibernate_config_file = authorization.getChild("hibernate-config-file");
		 	String file_name = hibernate_config_file.getAttributeValue("name");
		 	SessionFactory sf = initSessionFactory(file_name);
		 	appSessionFactories.put(context_name,sf);
		 	
		 }
	}
	public static SessionFactory getSessionFactory(String applicationContextName){
		/**
		 *  return (SessionFactory)appSessionFactories.get(applicationContextName);
		 */
		return null;
	}
	
	private static Document getConfigDocument(){
		try {
            SAXBuilder builder = new SAXBuilder();
            Document configDoc = builder.build(new File("ApplicationSecurityConfig.xml"));
            return configDoc;
        } catch(JDOMException e) {
            e.printStackTrace();
        } catch(NullPointerException e) {
            e.printStackTrace();
        } catch(Exception e) {
            e.printStackTrace();
        }
        return null;
	}
	
	private static SessionFactory initSessionFactory(String fileName){
		SessionFactory sf = null;<commit_msg>*** empty log message ***<commit_after>/*
 * Created on Dec 30, 2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package gov.nih.nci.security.system;

import java.util.*;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;
import java.io.*;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;


/**
 * @author kumarvi
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 * This class will be used by UserProvisioningManagerImpl to get
 * appropriate sessionFactory handle
 */
public class ApplicationSessionFactory {

	private static Hashtable appSessionFactories;
	  
	/**
	 * This method will read a system wide configuration file
	 * called ApplicationSecurityConfig.xml and initilaize the
	 * session factories as per the application context names
	 */
	static{
		appSessionFactories = new Hashtable();
		/**
		 * Read all the applicationContext entries in
		 * the file and iterate through them.
		 *   for(int i=0;i<numberOfEntries;i++){
		 *   build session factory here
		 *   appSessionFactories.put(applicationContextName,sf);
		 * }
		 */
		
		Document configDocument = getConfigDocument();
		Element applicationsElement = configDocument.getRootElement();
		List applications = applicationsElement.getChildren("application");
		 Iterator appIterator  = applications.iterator();
		 while(appIterator.hasNext()){
		 	Element application = (Element)appIterator.next();
		 	Element context = application.getChild("context");
		 	String context_name = context.getAttributeValue("context-name");
		 	Element authorization = application.getChild("authorization");
		 	Element hibernate_config_file = authorization.getChild("hibernate-config-file");
		 	String file_name = hibernate_config_file.getAttributeValue("name");
		 	SessionFactory sf = initSessionFactory(file_name);
		 	appSessionFactories.put(context_name,sf);
		 	
		 }
	}
	public static SessionFactory getSessionFactory(String applicationContextName){
		/**
		 *  return (SessionFactory)appSessionFactories.get(applicationContextName);
		 */
		return null;
	}
	
	private static Document getConfigDocument(){
		Document configDoc = null;
		try {
            SAXBuilder builder = new SAXBuilder();
            configDoc = builder.build(new File("ApplicationSecurityConfig.xml"));
            return configDoc;
        } catch(JDOMException e) {
            e.printStackTrace();
        } catch(NullPointerException e) {
            e.printStackTrace();
        } catch(Exception e) {
            e.printStackTrace();
        }
        return configDoc;
	}
	
	private static SessionFactory initSessionFactory(String fileName){
		SessionFactory sf = null;
{'fraction_non_alphanumeric': 0.0926411466526831, 'fraction_numerical': 0.0024471246285614405, 'mean_word_length': 3.8084033613445376, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5396051', 'n_tokens_mistral': 1628, 'n_tokens_neox': 1445, 'n_words': 415}