[1240] | 1 | package gov.va.med.edp.vistalink.locator;
|
---|
| 2 |
|
---|
| 3 | import gov.va.med.vistalink.adapter.cci.VistaLinkConnectionFactory;
|
---|
| 4 | import gov.va.med.vistalink.institution.InstitutionMapNotInitializedException;
|
---|
| 5 | import gov.va.med.vistalink.institution.InstitutionMappingDelegate;
|
---|
| 6 | import gov.va.med.vistalink.institution.InstitutionMappingNotFoundException;
|
---|
| 7 | import gov.va.med.edp.vistalink.ConnectionFactoryLocator;
|
---|
| 8 | import org.springframework.dao.DataAccessResourceFailureException;
|
---|
| 9 |
|
---|
| 10 | import javax.naming.Context;
|
---|
| 11 | import javax.naming.InitialContext;
|
---|
| 12 | import javax.naming.NamingException;
|
---|
| 13 | import javax.resource.cci.ConnectionFactory;
|
---|
| 14 | import java.text.MessageFormat;
|
---|
| 15 |
|
---|
| 16 | public class InstitutionMappingConnectionFactoryLocator implements ConnectionFactoryLocator {
|
---|
| 17 | private static final String NO_CONNECTION_FACTORY = "Unable to obtain connection factory for station ''{0}''";
|
---|
| 18 | private static final String NO_CONNECTION_FACTORY_JNDI = "Unable to obtain connection factory for station ''{0}'' at JNDI name ''{1}''";
|
---|
| 19 |
|
---|
| 20 | public ConnectionFactory getConnectionFactory(String stationNumber) throws DataAccessResourceFailureException {
|
---|
| 21 | try {
|
---|
| 22 | String jndiConnectorName = InstitutionMappingDelegate.getJndiConnectorNameForInstitution(
|
---|
| 23 | stationNumber);
|
---|
| 24 | try {
|
---|
| 25 | Context ic = new InitialContext();
|
---|
| 26 | VistaLinkConnectionFactory vistaLinkConnectionFactory = (VistaLinkConnectionFactory) ic.lookup(jndiConnectorName);
|
---|
| 27 | if (vistaLinkConnectionFactory == null)
|
---|
| 28 | throw new DataAccessResourceFailureException(MessageFormat.format(NO_CONNECTION_FACTORY_JNDI, new Object[] {stationNumber, jndiConnectorName}));
|
---|
| 29 | // throw new DataAccessResourceFailureException(MessageFormat.format(NO_CONNECTION_FACTORY_JNDI, stationNumber, jndiConnectorName)); // TODO: switch to this one in java 5
|
---|
| 30 | return vistaLinkConnectionFactory;
|
---|
| 31 | } catch (NamingException e) {
|
---|
| 32 | throw new DataAccessResourceFailureException(MessageFormat.format(NO_CONNECTION_FACTORY_JNDI, new Object[] {stationNumber, jndiConnectorName}), e);
|
---|
| 33 | // throw new DataAccessResourceFailureException(MessageFormat.format(NO_CONNECTION_FACTORY_JNDI, stationNumber, jndiConnectorName), e); // TODO: switch to this one in java 5
|
---|
| 34 | }
|
---|
| 35 | } catch (InstitutionMappingNotFoundException e) {
|
---|
| 36 | throw new DataAccessResourceFailureException(MessageFormat.format(NO_CONNECTION_FACTORY, new Object[] {stationNumber}), e);
|
---|
| 37 | // throw new DataAccessResourceFailureException(MessageFormat.format(NO_CONNECTION_FACTORY, stationNumber), e); // TODO: switch to this one in java 5
|
---|
| 38 | } catch (InstitutionMapNotInitializedException e) {
|
---|
| 39 | throw new DataAccessResourceFailureException(MessageFormat.format(NO_CONNECTION_FACTORY, new Object[] {stationNumber}), e);
|
---|
| 40 | // throw new DataAccessResourceFailureException(MessageFormat.format(NO_CONNECTION_FACTORY, stationNumber), e); // TODO: switch to this one in java 5
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | }
|
---|
| 44 | }
|
---|