Project

General

Profile

Smart props - DONE » History » Version 14

Henning Blohm, 05.03.2017 22:27

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 14 Henning Blohm
h3. Smart props and findComponents
24
25
Note that findComponents in IComponentsManager is based on the raw properties, before processing. This is so that component resolution is independent of the local 
26
environment and so that the risk of recursion traps while looking for processors is lowered.
27
28 8 Henning Blohm
h3. The plain style
29
30
There is a defaulting style "plain". That is, declaring a property 
31
32
<pre>x=...</pre>
33
34
is equivalent to 
35
36
<pre>
37
x\:plain=...
38
</pre>
39
40
h3. The JEXL3 style
41
42
A built-in processor is based on the "Apache Commons JEXL library":http://commons.apache.org/proper/commons-jexl.
43
44
JEXL offers a simple and versatile expression language. See "here":http://commons.apache.org/proper/commons-jexl/reference/syntax.html for a syntax reference. 
45
46
The JEXL3 style offers some implicit variables so that you can easily access system properties, environment variables, and other components. 
47
48
Example expressions:
49
50
Set path based on user's home folder:
51
<pre>
52
importPath\:JEXL3=system['user.home']+"/import"
53
</pre>
54
55
Copy a database configuration:
56
<pre>
57
ds.prop.user\:JEXL3=components.getComponent("environment/mainDB").getProperty("ds.prop.password")
58
ds.prop.password\:JEXL3=components.getComponent("environment/mainDB").getProperty("ds.prop.user")
59
ds.prop.url\:JEXL3=components.getComponent("environment/mainDB").getProperty("ds.prop.url")
60
</pre>
61
62
Copy a database configuration:
63
<pre>
64
ds.prop.user\:JEXL3=components.getComponent("environment/mainDB").getProperty("ds.prop.password")
65
ds.prop.password\:JEXL3=components.getComponent("environment/mainDB").getProperty("ds.prop.user")
66
ds.prop.url\:JEXL3=components.getComponent("environment/mainDB").getProperty("ds.prop.url")
67
</pre>
68
69
String with expressions:
70
<pre>
71
message\:JEXL3=`Sorry. We do not serve users called "${system['user.name']}" at ${env.JAVA_HOME}`
72
</pre>
73
74
Conditional expressions:
75
<pre>
76 9 Henning Blohm
osChoice\:JEXL3=system["os.name"].startsWith("Linux")? "We are running on a Linux OS" : "We are running on something else"
77 8 Henning Blohm
</pre>
78
79
80 11 Henning Blohm
h2. Previous work:
81 1 Henning Blohm
82 13 Henning Blohm
{{child_pages}}