source: EDIS/trunk/java/tracking-server-vista/src/main/java/gov/va/med/edp/vistalink/locator/InstitutionMappingConnectionFactoryLocator.java@ 1227

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

initial load of EDIS 1.0

File size: 3.0 KB
Line 
1package gov.va.med.edp.vistalink.locator;
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 gov.va.med.edp.vistalink.ConnectionFactoryLocator;
8import org.springframework.dao.DataAccessResourceFailureException;
9
10import javax.naming.Context;
11import javax.naming.InitialContext;
12import javax.naming.NamingException;
13import javax.resource.cci.ConnectionFactory;
14import java.text.MessageFormat;
15
16public 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}
Note: See TracBrowser for help on using the repository browser.