1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.properties.impl.config.ds;
17
18 import java.io.Serializable;
19
20 import de.smartics.properties.api.config.ds.DataSourceConfiguration;
21 import de.smartics.properties.api.core.domain.PropertiesContext;
22 import de.smartics.properties.spi.config.config.ConfigurationJndiLookupLoader;
23 import de.smartics.properties.spi.config.config.PropertiesConfiguration;
24
25
26
27
28
29 public class DataSourceConfigurationLoader implements Serializable
30 {
31
32
33
34
35
36
37
38
39
40
41 private static final long serialVersionUID = 1L;
42
43
44
45
46 public static final String CLASSPATH_LOCATION =
47 PropertiesContext.META_INF_HOME + "/datasource.properties";
48
49
50
51
52
53
54
55
56
57
58 public DataSourceConfigurationLoader()
59 {
60 }
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77 public DataSourceConfiguration load()
78 {
79 try
80 {
81 try
82 {
83 final DataSourceConfigurationPropertiesLoader propertiesLoader =
84 new DataSourceConfigurationPropertiesLoader();
85 final DataSourceConfiguration config = propertiesLoader.load();
86 return config;
87 }
88 catch (final IllegalStateException e)
89 {
90 return loadConfigFromJndi();
91 }
92 }
93 catch (final IllegalStateException e)
94 {
95 throw new IllegalStateException(
96 String.format("Cannot configure the access to a data source: %s",
97 e.getMessage(), e));
98 }
99 }
100
101 private DataSourceConfiguration loadConfigFromJndi()
102 {
103 try
104 {
105 final DataSourceConfigurationJndiLoader jndiLoader =
106 new DataSourceConfigurationJndiLoader();
107 final DataSourceConfiguration config = jndiLoader.load();
108 return config;
109 }
110 catch (final IllegalStateException e)
111 {
112 final ConfigurationJndiLookupLoader loader =
113 new ConfigurationJndiLookupLoader();
114 final PropertiesConfiguration allConfig = loader.load();
115 final DataSourceConfiguration config =
116 allConfig.getDataSourceConfiguration();
117 return config;
118 }
119 }
120
121
122
123 }