source: EDIS/trunk/java/tracking-server-vista/src/main/java/gov/va/med/edp/vistalink/locator/BeanFactoryConnectionFactoryLocator.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: 2.3 KB
Line 
1package gov.va.med.edp.vistalink.locator;
2
3import org.springframework.beans.BeansException;
4import org.springframework.beans.factory.BeanFactory;
5import org.springframework.beans.factory.BeanFactoryAware;
6import org.springframework.dao.DataAccessResourceFailureException;
7import org.springframework.util.StringUtils;
8
9import javax.resource.cci.ConnectionFactory;
10import java.text.MessageFormat;
11
12import gov.va.med.edp.vistalink.ConnectionFactoryLocator;
13
14public class BeanFactoryConnectionFactoryLocator implements ConnectionFactoryLocator, BeanFactoryAware {
15
16 private static final String NO_CONNECTION_FACTORY = "Unable to obtain connection factory for station ''{0}''";
17
18 private BeanFactory beanFactory;
19 private String prefix;
20 private String suffix;
21
22 public ConnectionFactory getConnectionFactory(String stationNumber) throws DataAccessResourceFailureException {
23 try {
24 ConnectionFactory connectionFactory = (ConnectionFactory) beanFactory.getBean(getBeanName(stationNumber), ConnectionFactory.class);
25 return connectionFactory;
26 } catch (BeansException e) {
27
28 throw new DataAccessResourceFailureException(MessageFormat.format(NO_CONNECTION_FACTORY, new Object[] {stationNumber}), e);
29// throw new DataAccessResourceFailureException(MessageFormat.format(NO_CONNECTION_FACTORY, stationNumber), e); // TODO: use this one for java 5
30 }
31 }
32
33 private String getBeanName(String stationNumber) {
34// StringBuilder builder = new StringBuilder(); // TODO: switch to StringBuilder in java 5
35 StringBuffer builder = new StringBuffer();
36 if (StringUtils.hasText(getPrefix())) {
37 builder.append(getPrefix());
38 }
39 builder.append(stationNumber);
40 if (StringUtils.hasText(getSuffix())) {
41 builder.append(getSuffix());
42 }
43 return builder.toString();
44 }
45
46 public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
47 this.beanFactory = beanFactory;
48 }
49
50 public String getPrefix() {
51 return prefix;
52 }
53
54 public void setPrefix(String prefix) {
55 this.prefix = prefix;
56 }
57
58 public String getSuffix() {
59 return suffix;
60 }
61
62 public void setSuffix(String suffix) {
63 this.suffix = suffix;
64 }
65}
Note: See TracBrowser for help on using the repository browser.