Project

General

Profile

Smart props - DONE » History » Version 12

Henning Blohm, 05.03.2017 22:17

1 10 Henning Blohm
h1. Smart Props (#1697)
2 1 Henning Blohm
3 7 Henning Blohm
The goal of this concept is to provide facilities to simplify sharing of component configuration, making use of system and environment variables while still being able to query resolved component configuration efficiently and with minimal resource usage.
4 1 Henning Blohm
5 7 Henning Blohm
h2. Latest Design
6
7
In order to maximize compatibility and flexibility the following design has been chosen:
8
9
Component properties can be marked with a processing style. To do so, the property name is qualified with an appended, colon separated style descriptor. For example,
10
11
<pre>
12
someProp\:JEXL3="This is a JEXL3 string"
13
</pre>
14
15 8 Henning Blohm
marks the property "someProp" as being of style <em>JEXL3</em>. 
16 1 Henning Blohm
17 8 Henning Blohm
<b>Note #1:</b> Colons need to be escaped using a backslash to be part of the name.
18
19
Running into an expression like this, z2 will hand it off to an IComponentDescriptorProcessor for evaluation. In this particular case it would be the included JEXL3 processor.
20
21
<b>Note #2:</b> There is still a uniqueness requirement. The same property name ("someProp" in this case) may not be used with more than one style qualifier.
22
23
h3. The plain style
24
25
There is a defaulting style "plain". That is, declaring a property 
26
27
<pre>x=...</pre>
28
29
is equivalent to 
30
31
<pre>
32
x\:plain=...
33
</pre>
34
35
h3. The JEXL3 style
36
37
A built-in processor is based on the "Apache Commons JEXL library":http://commons.apache.org/proper/commons-jexl.
38
39
JEXL offers a simple and versatile expression language. See "here":http://commons.apache.org/proper/commons-jexl/reference/syntax.html for a syntax reference. 
40
41
The JEXL3 style offers some implicit variables so that you can easily access system properties, environment variables, and other components. 
42
43
Example expressions:
44
45
Set path based on user's home folder:
46
<pre>
47
importPath\:JEXL3=system['user.home']+"/import"
48
</pre>
49
50
Copy a database configuration:
51
<pre>
52
ds.prop.user\:JEXL3=components.getComponent("environment/mainDB").getProperty("ds.prop.password")
53
ds.prop.password\:JEXL3=components.getComponent("environment/mainDB").getProperty("ds.prop.user")
54
ds.prop.url\:JEXL3=components.getComponent("environment/mainDB").getProperty("ds.prop.url")
55
</pre>
56
57
Copy a database configuration:
58
<pre>
59
ds.prop.user\:JEXL3=components.getComponent("environment/mainDB").getProperty("ds.prop.password")
60
ds.prop.password\:JEXL3=components.getComponent("environment/mainDB").getProperty("ds.prop.user")
61
ds.prop.url\:JEXL3=components.getComponent("environment/mainDB").getProperty("ds.prop.url")
62
</pre>
63
64
String with expressions:
65
<pre>
66
message\:JEXL3=`Sorry. We do not serve users called "${system['user.name']}" at ${env.JAVA_HOME}`
67
</pre>
68
69
Conditional expressions:
70
<pre>
71 9 Henning Blohm
osChoice\:JEXL3=system["os.name"].startsWith("Linux")? "We are running on a Linux OS" : "We are running on something else"
72 8 Henning Blohm
</pre>
73
74
75 11 Henning Blohm
h2. Previous work:
76 1 Henning Blohm
77 12 Henning Blohm
{{children}}