1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.properties.admin.domain.model;
17
18 import static de.smartics.properties.admin.domain.service.ApplicationIdConfigurationLoader.ARCHIVE_TYPE;
19 import static de.smartics.properties.admin.domain.service.ApplicationIdConfigurationLoader.ARTIFACT_ID;
20 import static de.smartics.properties.admin.domain.service.ApplicationIdConfigurationLoader.CLASSIFIER;
21 import static de.smartics.properties.admin.domain.service.ApplicationIdConfigurationLoader.GROUP_ID;
22 import static de.smartics.properties.admin.domain.service.ApplicationIdConfigurationLoader.VERSION;
23 import static de.smartics.properties.api.core.security.SecurityConfigurationLoader.SECURITY_ALGORITHM;
24 import static de.smartics.properties.api.core.security.SecurityConfigurationLoader.SECURITY_KEY;
25 import static de.smartics.properties.api.core.security.SecurityConfigurationLoader.SECURITY_PROVIDER;
26 import static de.smartics.properties.api.core.security.SecurityConfigurationLoader.SECURITY_TRANSFORMATION;
27 import static de.smartics.properties.impl.config.ds.DataSourceConfiguration.CREATE_TABLE;
28 import static de.smartics.properties.impl.config.ds.DataSourceConfiguration.DROP_TABLE;
29 import static de.smartics.properties.impl.config.ds.DataSourceConfiguration.JNDI_NAME;
30
31 import java.io.Serializable;
32
33 import javax.naming.Context;
34 import javax.naming.InitialContext;
35 import javax.naming.NamingException;
36
37 import de.smartics.properties.api.core.app.JndiContext;
38 import de.smartics.properties.spi.config.cache.CacheConfigurationLoader;
39
40
41
42
43 public final class JndiConfiguration implements Serializable
44 {
45
46
47
48
49
50
51
52
53
54
55 private static final long serialVersionUID = 1L;
56
57
58
59
60
61
62
63 private static final JndiConfiguration INSTANCE = new JndiConfiguration();
64
65
66
67
68
69
70 private JndiContext lookup;
71
72
73
74
75
76
77
78 private String groupId;
79
80
81
82
83
84
85
86 private String artifactId;
87
88
89
90
91
92
93 private String version;
94
95
96
97
98
99
100 private String archiveType;
101
102
103
104
105
106
107 private String classifier;
108
109
110
111
112
113
114 private String cacheName;
115
116
117
118
119
120
121 private String dsName;
122
123
124
125
126
127
128 private Boolean dsCreateTable;
129
130
131
132
133
134
135 private Boolean dsDropTable;
136
137
138
139
140
141
142 private String securityKey;
143
144
145
146
147
148
149 private String securityAlgorithm;
150
151
152
153
154
155
156 private String securityProvider;
157
158
159
160
161
162
163 private String securityTransformation;
164
165
166
167
168
169
170
171
172 public JndiConfiguration()
173 {
174 }
175
176
177
178
179
180
181
182
183
184
185
186
187 public void initialize() throws IllegalStateException
188 {
189 try
190 {
191 final Context jndi = new InitialContext();
192 final JndiContext context = JndiContext.boot(jndi);
193
194 setGroupId(context.lookup(GROUP_ID));
195 setArtifactId(context.lookup(ARTIFACT_ID));
196 setVersion(context.lookup(VERSION));
197 setArchiveType(context.lookup(ARCHIVE_TYPE));
198 setClassifier(context.lookup(CLASSIFIER));
199
200 setDsName(context.lookup(JNDI_NAME));
201 setDsCreateTable(context.lookupBoolean(CREATE_TABLE));
202 setDsDropTable(context.lookupBoolean(DROP_TABLE));
203
204 setCacheName(context.lookup(CacheConfigurationLoader.JNDI_NAME));
205
206 setSecurityKey(context.lookup(SECURITY_KEY));
207 setSecurityAlgorithm(context.lookup(SECURITY_ALGORITHM));
208 setSecurityProvider(context.lookup(SECURITY_PROVIDER));
209 setSecurityTransformation(context.lookup(SECURITY_TRANSFORMATION));
210
211 this.lookup = context;
212 }
213 catch (final Exception e)
214 {
215 throw new IllegalStateException("Cannot initialize JNDI context.", e);
216 }
217 }
218
219
220
221
222
223
224
225 public boolean isInitialized()
226 {
227 return lookup != null;
228 }
229
230
231
232
233
234
235
236
237
238
239 public String getGroupId()
240 {
241 return groupId;
242 }
243
244
245
246
247
248
249
250
251 public void setGroupId(final String groupId)
252 {
253 this.groupId = groupId;
254 }
255
256
257
258
259
260
261
262
263 public String getArtifactId()
264 {
265 return artifactId;
266 }
267
268
269
270
271
272
273
274
275 public void setArtifactId(final String artifactId)
276 {
277 this.artifactId = artifactId;
278 }
279
280
281
282
283
284
285
286
287 public String getVersion()
288 {
289 return version;
290 }
291
292
293
294
295
296
297
298 public void setVersion(final String version)
299 {
300 this.version = version;
301 }
302
303
304
305
306
307
308
309
310 public String getArchiveType()
311 {
312 return archiveType;
313 }
314
315
316
317
318
319
320
321
322 public void setArchiveType(final String archiveType)
323 {
324 this.archiveType = archiveType;
325 }
326
327
328
329
330
331
332
333
334 public String getClassifier()
335 {
336 return classifier;
337 }
338
339
340
341
342
343
344
345
346 public void setClassifier(final String classifier)
347 {
348 this.classifier = classifier;
349 }
350
351
352
353
354
355
356 public String getCacheName()
357 {
358 return cacheName;
359 }
360
361
362
363
364
365
366 public void setCacheName(final String cacheName)
367 {
368 this.cacheName = cacheName;
369 }
370
371
372
373
374
375
376 public String getDsName()
377 {
378 return dsName;
379 }
380
381
382
383
384
385
386 public void setDsName(final String dsName)
387 {
388 this.dsName = dsName;
389 }
390
391
392
393
394
395
396 public Boolean getDsCreateTable()
397 {
398 return dsCreateTable;
399 }
400
401
402
403
404
405
406
407 public void setDsCreateTable(final Boolean dsCreateTable)
408 {
409 this.dsCreateTable = dsCreateTable;
410 }
411
412
413
414
415
416
417
418 public void setDsCreateTable(final String dsCreateTable)
419 {
420 if (dsCreateTable != null)
421 {
422 setDsCreateTable("on".equals(dsCreateTable));
423 }
424 else
425 {
426 setDsCreateTable((Boolean) null);
427 }
428 }
429
430
431
432
433
434
435 public Boolean getDsDropTable()
436 {
437 return dsDropTable;
438 }
439
440
441
442
443
444
445 public void setDsDropTable(final Boolean dsDropTable)
446 {
447 this.dsDropTable = dsDropTable;
448 }
449
450
451
452
453
454
455 public void setDsDropTable(final String dsDropTable)
456 {
457 if (dsDropTable != null)
458 {
459 setDsDropTable("on".equals(dsDropTable));
460 }
461 else
462 {
463 setDsDropTable((Boolean) null);
464 }
465 }
466
467
468
469
470
471
472 public String getSecurityKey()
473 {
474 return securityKey;
475 }
476
477
478
479
480
481
482 public void setSecurityKey(final String securityKey)
483 {
484 this.securityKey = securityKey;
485 }
486
487
488
489
490
491
492 public String getSecurityAlgorithm()
493 {
494 return securityAlgorithm;
495 }
496
497
498
499
500
501
502 public void setSecurityAlgorithm(final String securityAlgorithm)
503 {
504 this.securityAlgorithm = securityAlgorithm;
505 }
506
507
508
509
510
511
512 public String getSecurityProvider()
513 {
514 return securityProvider;
515 }
516
517
518
519
520
521
522 public void setSecurityProvider(final String securityProvider)
523 {
524 this.securityProvider = securityProvider;
525 }
526
527
528
529
530
531
532 public String getSecurityTransformation()
533 {
534 return securityTransformation;
535 }
536
537
538
539
540
541
542 public void setSecurityTransformation(final String securityTransformation)
543 {
544 this.securityTransformation = securityTransformation;
545 }
546
547
548
549
550
551
552
553
554 public void update() throws NamingException
555 {
556 lookup.set(GROUP_ID, getGroupId());
557 lookup.set(ARTIFACT_ID, getArtifactId());
558 lookup.set(VERSION, getVersion());
559 lookup.set(ARCHIVE_TYPE, getArchiveType());
560 lookup.set(CLASSIFIER, getClassifier());
561
562 lookup.set(JNDI_NAME, getDsName());
563 lookup.set(CREATE_TABLE, getDsCreateTable());
564 lookup.set(DROP_TABLE, getDsDropTable());
565
566 lookup.set(CacheConfigurationLoader.JNDI_NAME, getCacheName());
567
568 lookup.set(SECURITY_KEY, getSecurityKey());
569 lookup.set(SECURITY_ALGORITHM, getSecurityAlgorithm());
570 lookup.set(SECURITY_PROVIDER, getSecurityProvider());
571 lookup.set(SECURITY_TRANSFORMATION, getSecurityTransformation());
572 }
573
574
575
576
577
578
579 public static JndiConfiguration getJndiConfiguration()
580 {
581 return INSTANCE;
582 }
583
584
585
586 }