ServiceLocator.java
// license-header java merge-point
//
// Attention: Generated code! Do not modify by hand!
// Generated by SpringServiceLocator.vsl in andromda-spring-cartridge on 08/18/2014 15:29:44-0400. Do not modify by hand!.
//
package org.andromda.samples.carrental;
import org.andromda.samples.carrental.admins.AdminService;
import org.andromda.samples.carrental.contracts.ContractService;
import org.andromda.samples.carrental.customers.CustomerService;
import org.andromda.samples.carrental.inventory.InventoryService;
import org.springframework.beans.factory.access.BeanFactoryLocator;
import org.springframework.beans.factory.access.BeanFactoryReference;
import org.springframework.context.ApplicationContext;
import org.springframework.context.access.ContextSingletonBeanFactoryLocator;
import org.springframework.context.support.AbstractApplicationContext;
/**
* Locates and provides all available application services.
*/
public class ServiceLocator
{
private ServiceLocator()
{
// shouldn't be instantiated
}
/**
* The prefix used for all bean ids.
*/
public static final String BEAN_PREFIX = "";
/**
* The shared instance of this ServiceLocator.
*/
private static final ServiceLocator instance = new ServiceLocator();
/**
* Gets the shared instance of this Class
*
* @return the shared service locator instance.
*/
public static final ServiceLocator instance()
{
return instance;
}
/**
* The bean factory reference instance.
*/
private BeanFactoryReference beanFactoryReference;
/**
* The bean factory reference location.
*/
private String beanFactoryReferenceLocation;
/**
* The bean factory reference id.
*/
private String beanRefFactoryReferenceId;
/**
* Initializes the Spring application context from
* the given <code>beanFactoryReferenceLocation</code>. If <code>null</code>
* is specified for the <code>beanFactoryReferenceLocation</code>
* then the default application context will be used.
*
* @param beanFactoryReferenceLocationIn the location of the beanRefFactory reference.
* @param beanRefFactoryReferenceIdIn the id of the beanRefFactory reference.
*/
public synchronized void init(final String beanFactoryReferenceLocationIn, final String beanRefFactoryReferenceIdIn)
{
this.beanFactoryReferenceLocation = beanFactoryReferenceLocationIn;
this.beanRefFactoryReferenceId = beanRefFactoryReferenceIdIn;
this.beanFactoryReference = null;
}
/**
* Initializes the Spring application context from
* the given <code>beanFactoryReferenceLocation</code>. If <code>null</code>
* is specified for the <code>beanFactoryReferenceLocation</code>
* then the default application context will be used.
*
* @param beanFactoryReferenceLocationIn the location of the beanRefFactory reference.
*/
public synchronized void init(final String beanFactoryReferenceLocationIn)
{
this.beanFactoryReferenceLocation = beanFactoryReferenceLocationIn;
this.beanFactoryReference = null;
}
/**
* The default bean reference factory location.
*/
private final String DEFAULT_BEAN_REFERENCE_LOCATION = "beanRefFactory.xml";
/**
* The default bean reference factory ID, referencing beanRefFactory.
*/
private final String DEFAULT_BEAN_REFERENCE_ID = "beanRefFactory";
/**
* Gets the Spring ApplicationContext.
* @return beanFactoryReference.getFactory()
*/
public synchronized ApplicationContext getContext()
{
if (this.beanFactoryReference == null)
{
if (this.beanFactoryReferenceLocation == null)
{
this.beanFactoryReferenceLocation = this.DEFAULT_BEAN_REFERENCE_LOCATION;
}
if (this.beanRefFactoryReferenceId == null)
{
this.beanRefFactoryReferenceId = this.DEFAULT_BEAN_REFERENCE_ID;
}
BeanFactoryLocator beanFactoryLocator =
ContextSingletonBeanFactoryLocator.getInstance(
this.beanFactoryReferenceLocation);
this.beanFactoryReference = beanFactoryLocator.useBeanFactory(this.beanRefFactoryReferenceId);
}
return (ApplicationContext)this.beanFactoryReference.getFactory();
}
/**
* Shuts down the ServiceLocator and releases any used resources.
*/
public synchronized void shutdown()
{
((AbstractApplicationContext)this.getContext()).close();
if (this.beanFactoryReference != null)
{
this.beanFactoryReference.release();
this.beanFactoryReference = null;
}
}
/**
* Gets an instance of {@link AdminService}.
* @return AdminService from getContext().getBean("adminService")
*/
public final AdminService getAdminService()
{
return (AdminService)
getContext().getBean("adminService");
}
/**
* Gets an instance of {@link ContractService}.
* @return ContractService from getContext().getBean("contractService")
*/
public final ContractService getContractService()
{
return (ContractService)
getContext().getBean("contractService");
}
/**
* Gets an instance of {@link CustomerService}.
* @return CustomerService from getContext().getBean("customerService")
*/
public final CustomerService getCustomerService()
{
return (CustomerService)
getContext().getBean("customerService");
}
/**
* Gets an instance of {@link InventoryService}.
* @return InventoryService from getContext().getBean("inventoryService")
*/
public final InventoryService getInventoryService()
{
return (InventoryService)
getContext().getBean("inventoryService");
}
/**
* Gets an instance of the given service.
* @param serviceName
* @return getContext().getBean(BEAN_PREFIX + serviceName)
*/
public final Object getService(String serviceName)
{
return getContext().getBean(BEAN_PREFIX + serviceName);
}
}