Project

General

Profile

Improvement #1697

Implement Smart Props

Added by Henning Blohm about 10 years ago. Updated almost 7 years ago.

Status:
Resolved
Priority:
Normal
Assignee:
Category:
z2-core
Target version:
Start date:
23.03.2014
Due date:
% Done:

100%

Estimated time:
origin:

Description

As component properties pre-processor as laid out in smart props.

Specifically:

  1. Component properties may be qualified with a processing style using a colon-separated name appendix
  2. An API for component property processors is provided and an extension point is used to find style implementers
  3. A JEXL3 implementation is provided
#1

Updated by Henning Blohm over 7 years ago

  • Target version changed from 3.0 to 2.5

As described in Smart props:

Smart Props (#1697)

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.

Latest Design

In order to maximize compatibility and flexibility the following design has been chosen:

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,

someProp\:JEXL3="This is a JEXL3 string" 

marks the property "someProp" as being of style <em>JEXL3</em>.

<b>Note #1:</b> Colons need to be escaped using a backslash to be part of the name.

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.

<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.

Smart props and findComponents

Note that findComponents in IComponentsManager is based on the raw properties, before processing. This is so that component resolution is independent of the local
environment and so that the risk of recursion traps while looking for processors is lowered.

The plain style

There is a defaulting style "plain". That is, declaring a property

x=...

is equivalent to

x\:plain=...

The JEXL3 style

A built-in processor is based on the Apache Commons JEXL library.

JEXL offers a simple and versatile expression language. See here for a syntax reference.

The JEXL3 style offers some implicit variables so that you can easily access system properties, environment variables, and other components.

Example expressions:

Set path based on user's home folder:

importPath\:JEXL3=system['user.home']+"/import" 

Copy a database configuration:

ds.prop.user\:JEXL3=components.getComponent("environment/mainDB").getProperty("ds.prop.password")
ds.prop.password\:JEXL3=components.getComponent("environment/mainDB").getProperty("ds.prop.user")
ds.prop.url\:JEXL3=components.getComponent("environment/mainDB").getProperty("ds.prop.url")

Copy a database configuration:

ds.prop.user\:JEXL3=components.getComponent("environment/mainDB").getProperty("ds.prop.password")
ds.prop.password\:JEXL3=components.getComponent("environment/mainDB").getProperty("ds.prop.user")
ds.prop.url\:JEXL3=components.getComponent("environment/mainDB").getProperty("ds.prop.url")

String with expressions:

message\:JEXL3=`Sorry. We do not serve users called "${system['user.name']}" at ${env.JAVA_HOME}`

Conditional expressions:

osChoice\:JEXL3=system["os.name"].startsWith("Linux")? "We are running on a Linux OS" : "We are running on something else" 

Previous work:

#2

Updated by Henning Blohm over 7 years ago

  • Status changed from New to In Progress
#3

Updated by Henning Blohm about 7 years ago

  • Description updated (diff)
#4

Updated by Henning Blohm about 7 years ago

  • Status changed from In Progress to To Be Documented
#5

Updated by Henning Blohm about 7 years ago

  • Status changed from To Be Documented to Resolved

documented and done

#6

Updated by Henning Blohm almost 7 years ago

  • Status changed from Resolved to In Progress

Reopened to add "this" implicit var.

#7

Updated by Henning Blohm almost 7 years ago

  • Status changed from In Progress to Resolved
  • % Done changed from 0 to 100
#8

Updated by Henning Blohm almost 7 years ago

  • Status changed from Resolved to In Progress
  • % Done changed from 100 to 0

reopened for self-recursion resolve

#9

Updated by Henning Blohm almost 7 years ago

  • Status changed from In Progress to Resolved
  • % Done changed from 0 to 100

Applied in changeset internal:internal-office|r2576.

Also available in: Atom PDF