1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.jetspeed.components.jndi; |
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
import java.util.Map; |
34 |
|
|
35 |
|
import org.apache.commons.pool.impl.GenericObjectPool; |
36 |
|
import org.apache.jetspeed.components.SpringComponentManager; |
37 |
|
import org.apache.jetspeed.components.datasource.BoundDBCPDatasourceComponent; |
38 |
|
import org.apache.jetspeed.components.jndi.JNDIComponent; |
39 |
|
import org.apache.jetspeed.components.jndi.TyrexJNDIComponent; |
40 |
|
|
41 |
|
public class SpringJNDIStarter |
42 |
|
{ |
43 |
|
|
44 |
|
public static final String JNDI_DS_NAME = "jetspeed"; |
45 |
0 |
public static final String DATASOURCE_DRIVER = "org.apache.jetspeed.database.driver".intern(); |
46 |
0 |
public static final String DATASOURCE_URL = "org.apache.jetspeed.database.url".intern(); |
47 |
0 |
public static final String DATASOURCE_USERNAME = "org.apache.jetspeed.database.user".intern(); |
48 |
0 |
public static final String DATASOURCE_PASSWORD = "org.apache.jetspeed.database.password".intern(); |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
private final Map context; |
54 |
|
|
55 |
|
protected BoundDBCPDatasourceComponent datasourceComponent; |
56 |
|
protected JNDIComponent jndi; |
57 |
0 |
String appRoot = null; |
58 |
0 |
String[] bootConfig = null; |
59 |
0 |
String[] appConfig = null; |
60 |
0 |
SpringComponentManager scm = null; |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
public SpringJNDIStarter(Map context,String appRoot, String[] bootConfig, String[] appConfig) |
72 |
0 |
{ |
73 |
0 |
this.context = context; |
74 |
0 |
this.appRoot = appRoot; |
75 |
0 |
this.bootConfig = bootConfig; |
76 |
0 |
this.appConfig = appConfig; |
77 |
0 |
} |
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
public void setUp() throws Exception |
89 |
|
{ |
90 |
0 |
setupJNDI(); |
91 |
0 |
scm = new SpringComponentManager(bootConfig, appConfig, appRoot ); |
92 |
0 |
} |
93 |
|
|
94 |
|
public void tearDown() throws Exception |
95 |
|
{ |
96 |
|
try |
97 |
|
{ |
98 |
0 |
datasourceComponent.stop(); |
99 |
|
} |
100 |
0 |
catch (Exception e) |
101 |
|
{ |
102 |
0 |
System.out.println("datasourceComponent stop failed with " + e.getLocalizedMessage()); |
103 |
0 |
e.printStackTrace(); |
104 |
0 |
} |
105 |
|
try |
106 |
|
{ |
107 |
0 |
scm.stop(); |
108 |
|
} |
109 |
0 |
catch (Exception e) |
110 |
|
{ |
111 |
0 |
System.out.println("SpringComponentManager stop failed with " + e.getLocalizedMessage()); |
112 |
0 |
e.printStackTrace(); |
113 |
0 |
} |
114 |
|
|
115 |
|
try |
116 |
|
{ |
117 |
0 |
jndi.unbindFromCurrentThread(); |
118 |
|
} |
119 |
0 |
catch (Exception e) |
120 |
|
{ |
121 |
0 |
System.out.println("JNDI unbindFromCurrentThread failed with " + e.getLocalizedMessage()); |
122 |
0 |
e.printStackTrace(); |
123 |
0 |
} |
124 |
0 |
} |
125 |
|
|
126 |
|
String getProperty(String name) |
127 |
|
{ |
128 |
0 |
String s = null; |
129 |
|
try |
130 |
|
{ |
131 |
0 |
if (context != null) |
132 |
0 |
s = (String) context.get(name); |
133 |
|
} |
134 |
0 |
catch (Exception e) |
135 |
|
{ |
136 |
0 |
e.printStackTrace(); |
137 |
0 |
} |
138 |
0 |
if (s == null) |
139 |
0 |
s = System.getProperty(name); |
140 |
0 |
return s; |
141 |
|
} |
142 |
|
|
143 |
|
|
144 |
|
public void setupJNDI() throws Exception |
145 |
|
{ |
146 |
0 |
jndi = new TyrexJNDIComponent(); |
147 |
0 |
String url = getProperty("org.apache.jetspeed.database.url"); |
148 |
0 |
String driver = getProperty("org.apache.jetspeed.database.driver"); |
149 |
0 |
String user = getProperty("org.apache.jetspeed.database.user"); |
150 |
0 |
String password = getProperty("org.apache.jetspeed.database.password"); |
151 |
0 |
datasourceComponent = new BoundDBCPDatasourceComponent(user, password, driver, url, 20, 5000, |
152 |
|
GenericObjectPool.WHEN_EXHAUSTED_GROW, true, JNDI_DS_NAME, jndi); |
153 |
0 |
datasourceComponent.start(); |
154 |
0 |
} |
155 |
|
|
156 |
|
public SpringComponentManager getComponentManager() |
157 |
|
{ |
158 |
0 |
return scm; |
159 |
|
} |
160 |
|
|
161 |
|
public Map getContext() |
162 |
|
{ |
163 |
0 |
return context; |
164 |
|
} |
165 |
|
|
166 |
|
|
167 |
|
} |