<commit_before>package gov.nih.nci.system.applicationservice;

import org.apache.log4j.Logger;



/**
 * This class acts as a Factory for the creating an appropriate instance of the 
 * {@link ApplicationService} Interface and return it to the client.
 * 
 * @author <NAME> Ltd.
 */
public class ApplicationServiceProvider
{

	private static Logger log= Logger.getLogger(ApplicationServiceProvider.class.getName());
	private static ApplicationService applicationService;

	/**
	 * Default constructor. Does nothing
	 */	
	public ApplicationServiceProvider()
	{
	}

	/**
	 * This methods returns appropriate instance of the {@link ApplicationService}
	 * depending upon from where the client is trying to access it. If the client is
	 * a remote instance then it instantiate approriate remote implementation of the
	 * {@link ApplicationService} interface and chache it. It the methods detects that
	 * the client is local then it instantiates a local implementation of the (@link 
	 * ApplicationService) interface and chache it. If it is unable to instantiate
	 * either the appropriate implementation then it returns a <code>NULL</code>
	 * @return The appropriate instance of 
	 */
	public synchronized static ApplicationService getApplicationService()
	{
		if (applicationService == null)
		{
			applicationService = getLocalInstance();
			if (applicationService == null)
				applicationService = getRemoteInstance();
		}
		return applicationService;
	}
	
	public synchronized static ApplicationService getLocalInstance()
	{
		if (applicationService == null)
		{
			try 
			{
				Class applicationServiceImplClass = Class.forName("gov.nih.nci.system.applicationservice.impl.ApplicationServiceImpl");
				try 
				{
					applicationService = (ApplicationService)applicationServiceImplClass.newInstance();
				} 
				catch (InstantiationException e1) 
				{
					log.error("Instantiation Error in Initailizing the Local Implementation of Application Service");
				} 
				catch (IllegalAccessException e1)
				{
					log.error("Security Error in Initailizing the Local Implementation of Application Service");
				}
			} 
			catch (ClassNotFoundException e)
			{
				log.error("Fatal Error in Initailizing Either Client or Server Implementation of Application Service");
			}
		}
		return applicationService;
	}
	
	public synchronized static ApplicationService getRemoteInstance()
	{
		if (applicationService == null)
		{
			try 
			{
				Class applicationServiceClientImplClass = Class.forName("gov.nih.nci.system.comm.client.ApplicationServiceClientImpl");
				try 
				{
					applicationService = (ApplicationService)applicationServiceClientImplClass.newInstance();
					applicationService = applicationService.getBeanInstance();
				}
				catch (InstantiationException e1) 
				{
					log.error("Instantiation Error in Initailizing the Remote Implementation of Application Service");
				}
				catch (IllegalAccessException e1) 
				{
					log.error("Security Error in Initailizing the Remote Implementation of Application Service");
				}				
			}
			catch (ClassNotFoundException e1)
			{
				log.error("Fatal Error in Initailizing Either Client or Server Implementation of Application Service");
			}
		}
		return applicationService;
	}

	public synchronized static ApplicationService getRemoteInstance(String URL)
	{
		if (applicationService == null)<commit_msg>Allowing to obtain new remote service from URL when user asks for it<commit_after>package gov.nih.nci.system.applicationservice;

import org.apache.log4j.Logger;



/**
 * This class acts as a Factory for the creating an appropriate instance of the 
 * {@link ApplicationService} Interface and return it to the client.
 * 
 * @author <NAME> Ltd.
 */
public class ApplicationServiceProvider
{

	private static Logger log= Logger.getLogger(ApplicationServiceProvider.class.getName());
	private static ApplicationService applicationService;

	/**
	 * Default constructor. Does nothing
	 */	
	public ApplicationServiceProvider()
	{
	}

	/**
	 * This methods returns appropriate instance of the {@link ApplicationService}
	 * depending upon from where the client is trying to access it. If the client is
	 * a remote instance then it instantiate approriate remote implementation of the
	 * {@link ApplicationService} interface and chache it. It the methods detects that
	 * the client is local then it instantiates a local implementation of the (@link 
	 * ApplicationService) interface and chache it. If it is unable to instantiate
	 * either the appropriate implementation then it returns a <code>NULL</code>
	 * @return The appropriate instance of 
	 */
	public synchronized static ApplicationService getApplicationService()
	{
		if (applicationService == null)
		{
			applicationService = getLocalInstance();
			if (applicationService == null)
				applicationService = getRemoteInstance();
		}
		return applicationService;
	}
	
	public synchronized static ApplicationService getLocalInstance()
	{
		if (applicationService == null)
		{
			try 
			{
				Class applicationServiceImplClass = Class.forName("gov.nih.nci.system.applicationservice.impl.ApplicationServiceImpl");
				try 
				{
					applicationService = (ApplicationService)applicationServiceImplClass.newInstance();
				} 
				catch (InstantiationException e1) 
				{
					log.error("Instantiation Error in Initailizing the Local Implementation of Application Service");
				} 
				catch (IllegalAccessException e1)
				{
					log.error("Security Error in Initailizing the Local Implementation of Application Service");
				}
			} 
			catch (ClassNotFoundException e)
			{
				log.error("Fatal Error in Initailizing Either Client or Server Implementation of Application Service");
			}
		}
		return applicationService;
	}
	
	public synchronized static ApplicationService getRemoteInstance()
	{
		if (applicationService == null)
		{
			try 
			{
				Class applicationServiceClientImplClass = Class.forName("gov.nih.nci.system.comm.client.ApplicationServiceClientImpl");
				try 
				{
					applicationService = (ApplicationService)applicationServiceClientImplClass.newInstance();
					applicationService = applicationService.getBeanInstance();
				}
				catch (InstantiationException e1) 
				{
					log.error("Instantiation Error in Initailizing the Remote Implementation of Application Service");
				}
				catch (IllegalAccessException e1) 
				{
					log.error("Security Error in Initailizing the Remote Implementation of Application Service");
				}				
			}
			catch (ClassNotFoundException e1)
			{
				log.error("Fatal Error in Initailizing Either Client or Server Implementation of Application Service");
			}
		}
		return applicationService;
	}

	public synchronized static ApplicationService getRemoteInstance(String URL)
	{
		//if (applicationService == null) Commented this line because user specifically is asking for a new instance. But this will still not work in multi threaded environment
{'fraction_non_alphanumeric': 0.07165513264129181, 'fraction_numerical': 0.0017301038062283738, 'mean_word_length': 4.1157817109144545, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '5529498', 'n_tokens_mistral': 2040, 'n_tokens_neox': 1683, 'n_words': 585}