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