ManageableServiceLocator.java
// license-header java merge-point
/* Autogenerated by AndroMDA crud/ManageableServiceLocator.vsl in andromda-ejb3-cartridge on 08/08/2014 12:21:07 - do not edit */
package org.andromda.demo.ejb3;
import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.andromda.demo.ejb3.registration.crud.ProfileManageableService;
import org.andromda.demo.ejb3.registration.crud.RegistrationManageableService;
/**
* Locates and provides all available application services.
*/
public class ManageableServiceLocator
{
/**
* The shared instance of this ServiceLocator.
*/
private static ManageableServiceLocator instance;
/**
* The Context to lookup the service beans.
*/
protected InitialContext context = null;
/**
* Cannot be instantiated constructor
*/
private ManageableServiceLocator()
{
// shouldn't be instantiated
}
/**
* Gets the shared instance of this Class.
* Create it if it doesn't already exists, otherwise return the current instance.
*
* @return the shared service locator instance.
*/
public static final ManageableServiceLocator instance()
{
if (instance == null)
{
instance = new ManageableServiceLocator();
}
return instance;
}
/**
* Gets the InitialContext.
*
* @param env the Context environment properties.
* @return the InitialContext.
* @throws NamingException failure to create InitialContext
*/
protected synchronized InitialContext getContext(Properties env)
throws NamingException
{
if (this.context == null)
{
this.context = new InitialContext(env);
}
return this.context;
}
/**
* Instantiate a new InitialContext using the properties table.
*
* @param env passed to the InitialContext constructor.
* @return the InitialContext.
* @throws NamingException failure to create InitialContext
*/
protected synchronized InitialContext newContext(Properties env)
throws NamingException
{
this.context = new InitialContext(env);
return this.context;
}
/**
* Shuts down the ManageableServiceLocator and releases any used resources.
*/
public synchronized void shutdown()
{
if (this.context != null)
{
try
{
this.context.close();
}
catch (NamingException ne)
{
// ignore
}
finally
{
this.context = null;
}
}
}
/**
* Gets an instance of {@link RegistrationManageableService}.
*
* @throws NamingException failure to lookup remote manageable service interface.
*/
public final RegistrationManageableService getRegistrationManageableService()
throws NamingException
{
return this.getRegistrationManageableServiceRemote(null);
}
/**
* Get the remote interface for {@link RegistrationManageableService}.
*
* @param env the Context environment properties. Null represents no properties.
* @throws NamingException failure to lookup remote manageable service interface.
*/
public final RegistrationManageableService getRegistrationManageableServiceRemote(Properties env)
throws NamingException
{
return (RegistrationManageableService)
getContext(env).lookup("demo-ejb3-3.5-SNAPSHOT/RegistrationManageableService/remote");
}
/**
* Get the local interface for {@link RegistrationManageableService}.
*
* @param env the Context environment properties. Null represents no properties.
* @throws NamingException failure to lookup remote manageable service interface.
*/
public final RegistrationManageableService getRegistrationManageableServiceLocal(Properties env)
throws NamingException
{
return (RegistrationManageableService)
getContext(env).lookup("demo-ejb3-3.5-SNAPSHOT/RegistrationManageableService/local");
}
/**
* Gets an instance of {@link ProfileManageableService}.
*
* @throws NamingException failure to lookup remote manageable service interface.
*/
public final ProfileManageableService getProfileManageableService()
throws NamingException
{
return this.getProfileManageableServiceRemote(null);
}
/**
* Get the remote interface for {@link ProfileManageableService}.
*
* @param env the Context environment properties. Null represents no properties.
* @throws NamingException failure to lookup remote manageable service interface.
*/
public final ProfileManageableService getProfileManageableServiceRemote(Properties env)
throws NamingException
{
return (ProfileManageableService)
getContext(env).lookup("demo-ejb3-3.5-SNAPSHOT/ProfileManageableService/remote");
}
/**
* Get the local interface for {@link ProfileManageableService}.
*
* @param env the Context environment properties. Null represents no properties.
* @throws NamingException failure to lookup remote manageable service interface.
*/
public final ProfileManageableService getProfileManageableServiceLocal(Properties env)
throws NamingException
{
return (ProfileManageableService)
getContext(env).lookup("demo-ejb3-3.5-SNAPSHOT/ProfileManageableService/local");
}
/**
* Gets an instance of the given service.
*
* @param serviceName lookup this service from the context.
* @throws NamingException failure to lookup remote service interface.
*/
public final Object getService(String serviceName)
throws NamingException
{
return getService(serviceName, null);
}
/**
* Gets an instance of the given service.
*
* @param serviceName lookup this service from the context.
* @param env the Context environment properties. Null represents no properties.
* @throws NamingException failure to lookup remote service interface.
*/
public final Object getService(String serviceName, Properties env)
throws NamingException
{
return getContext(env).lookup(serviceName);
}
}