source: EDIS/tags/ed/tracking-server-core/src/main/java/gov/va/med/edp/rpc/InstitutionMappingConnectionFactoryLocator.java@ 1240

Last change on this file since 1240 was 1240, checked in by George Lilly, 13 years ago

new version from the VA

File size: 2.3 KB
Line 
1package gov.va.med.edp.rpc;
2
3import gov.va.med.vistalink.adapter.cci.VistaLinkConnectionFactory;
4import gov.va.med.vistalink.institution.InstitutionMapNotInitializedException;
5import gov.va.med.vistalink.institution.InstitutionMappingDelegate;
6import gov.va.med.vistalink.institution.InstitutionMappingNotFoundException;
7import org.springframework.dao.DataAccessResourceFailureException;
8
9import javax.naming.Context;
10import javax.naming.InitialContext;
11import javax.naming.NamingException;
12import javax.resource.cci.ConnectionFactory;
13import java.text.MessageFormat;
14
15public 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}
Note: See TracBrowser for help on using the repository browser.