Nova Ordis Generic Variable and Expression System: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(15 intermediate revisions by the same user not shown)
Line 5: Line 5:
=Overview=
=Overview=


The implementation of a generic variable system. Variables are scoped, typed and named placeholders for values. Variable instances can only be created by declaring them in a scope, with Scope.declare(). Once declared in a scope, the variable is available to all enclosed scopes.The same variable may be declared in more than one scope, and may have different values in different scopes.
The implementation of a generic variable system. Variables are scoped, typed and named placeholders for values.  


Values are assigned to a variable with set() and retrieved with get(). The value of a variable may be null.
Variable instances can only be created by declaring them in a scope, with Scope.declare(). Once declared in a scope, the variable is available to all enclosed scopes, but not to the enclosing scopes. The same variable - a variable with the same name - may be declared in more than one scope, and may have different values in different scopes. In this context, a variable is said to be ''declared'' if it was declared either in the current scope or in any of its enclosing scopes. A variable is said to be ''declared in scope'' only if it was declared in the scope in question.
 
A variable cannot be declared twice in the same scope, the attempt will throw a DuplicateDeclarationException.
 
Values are assigned to a variable with set() and retrieved with get().  
 
The value of a variable may be null, unless the scope does not allow null variable. An example of such of scope is OSProcessScope, that can be used to access OS-level environment variables and plug the into the application's variable system. There can't be null environment variables.


=Variable Names=
=Variable Names=


A variable name must start with a letter and consists in letters, digits, '_' and '-', and must not belong to the set of reserved names.
A variable name must start with a letter and consists in letters, digits, '_', '-' and '.', and must not belong to the set of reserved names.


=Example=
=Example=
Line 22: Line 28:


</syntaxhighlight>
</syntaxhighlight>
=Scopes and Visibility=
Once a variable is declared in a scope, it becomes visible to all enclosed scopes (scopes that have this scope as parent) but it is not visible to this scope's enclosing scopes. The value of the variable is given by the value in the closest scope.
<syntaxhighlight lang='java'>
Scope upper = new ScopeImpl();
Scope intermediate = new ScopeImpl();
Scope lower = new ScopeImpl();
upper.enclose(intermediate);
intermediate.enclose(lower);
intermediate.declare("color", String.class, "blue");
assertNull(upper.getVariable("color"));
assertEquals("blue", intermediate.getVariable("color").get());
assertEquals("blue", lower.getVariable("color").get());
</syntaxhighlight>
Only EncloseableScopes can be enclosed.
=Environment Variable Access=
{{Internal|Nova Ordis Utilities Environment Variable Support|Environment Variable Support}}
=Variable and Expression Evaluation=

Latest revision as of 19:03, 18 September 2017

Internal

Overview

The implementation of a generic variable system. Variables are scoped, typed and named placeholders for values.

Variable instances can only be created by declaring them in a scope, with Scope.declare(). Once declared in a scope, the variable is available to all enclosed scopes, but not to the enclosing scopes. The same variable - a variable with the same name - may be declared in more than one scope, and may have different values in different scopes. In this context, a variable is said to be declared if it was declared either in the current scope or in any of its enclosing scopes. A variable is said to be declared in scope only if it was declared in the scope in question.

A variable cannot be declared twice in the same scope, the attempt will throw a DuplicateDeclarationException.

Values are assigned to a variable with set() and retrieved with get().

The value of a variable may be null, unless the scope does not allow null variable. An example of such of scope is OSProcessScope, that can be used to access OS-level environment variables and plug the into the application's variable system. There can't be null environment variables.

Variable Names

A variable name must start with a letter and consists in letters, digits, '_', '-' and '.', and must not belong to the set of reserved names.

Example

Scope s = new ScopeImpl();

Variable<String> v = s.declare("color", String.class, "blue");

Scopes and Visibility

Once a variable is declared in a scope, it becomes visible to all enclosed scopes (scopes that have this scope as parent) but it is not visible to this scope's enclosing scopes. The value of the variable is given by the value in the closest scope.

Scope upper = new ScopeImpl();
Scope intermediate = new ScopeImpl();
Scope lower = new ScopeImpl();

upper.enclose(intermediate);
intermediate.enclose(lower);

intermediate.declare("color", String.class, "blue");

assertNull(upper.getVariable("color"));
assertEquals("blue", intermediate.getVariable("color").get());
assertEquals("blue", lower.getVariable("color").get());

Only EncloseableScopes can be enclosed.

Environment Variable Access

Environment Variable Support

Variable and Expression Evaluation