openInstaller : Dynamic calculation of default values

OpenInstaller have  many great features,one of them is ,deducing the default values during runtime.

Sometimes we need to calculate the default value of configuration property at runtime for configuration.There are two ways to define dynamic default values in openInstaller:


1.Define substitution expression as an <if:eval> element
2.Define arbitrary substitution logic as an <if:eval-engine> element

Substitution expression:

If a particular property has an <if:eval> expression, this expression is evaluated and the resulting value substituted as the property's default value (just as though the document author had hard-coded the default value in the <value> element).  An <if:eval> property can contain one of three different supported types of substitution values.

The three types are:

1.Simple Substitution
2.Target Substitution
3.Component Substitution


Simple Substitution:

Syntax    

    :[varname]

Example

    <value if:eval=":[username]">root</value>

During runtime the value in the if:eval property will be resolved against a known set of parameters defined by a default set of parameters supplied by the install author in the ui.prefs file.

If the Substitution Engine is not able to resolve the variable name against the default supplied values then it will fall back to default value provided.
 
- Component Substitution:

Syntax   

    :[component:varname]

Example

    <value if:eval=":[component:SomeComponent.group.username]">root</value>

During runtime the value in the if:eval property will be resolved against the known components and their associated groups/values.  The name is treated as fully-qualified, where the first part of the “.”-separated name represents a component name, then the intermediate parts of the name represent a hierarchy of group names, and the final part of the name represents the parameter name of the parameter whose value should be substituted here.

If the Substitution Engine is not able to resolve the value then it will fall back to default value provided.

- Target Substitution:

Syntax

    :[target:varname]
    :[target(host-redirect):varname]

Examples

<value if:eval=":[target:sys.ipAddress]">127.0.0.1</value>
<value if:eval=":[target(purplehaze.sfbay):sys.ipAddress]">10.4.116.100</value>

In the first example will substitute the value of the IP Address of the localhost whereas the second example will substitute the value of the IP Address of purplehaze.sfbay.

OpenInstaller defines a certain set of attributes associated with a host (target). References to a value associated to a particular host can be made with this style of syntax.

When the (host-redirect) syntax is used, the value returned will be the value of the attributed associated with the specified hostname (or IP address) defined by the (host-redirect). If the value cannot be looked up relative to that host, then the default value is used instead (along with a warning in the engine log).

When the (host-redirect) is not used, the value is assumed to be the local host where the code is executing.

There are 8 predefined variable for target substitution.

1.sys.hostName        Host name of host
2.sys.ipAddress        IP Address of host
3.sys.homeDir        Home Directory of current user\*
4.sys.tmpDir        Temporary directory used by the running VM\*
5.sys.osVersion        Release version of OS (e.g. `uname -r` output on Solaris)\*
6.sys.OSArch        OS Architecture (e.g. `uname -p` output).\*
7.sys.userName        Current user's login account name \*
8.sys.userDir        The current directory from which the engine was invoked \*

These values are only available for the local host. Using with a (host-redirect) has no effect.

Substitution Engine:

Instead of defining a substitution expression, an install author may want to execute arbitrary code ( a substitution engine) to compute the default value.  For example, if the default value changes based on environment (e.g. If a port number is in use, the default port number should be decremented before being shown to the user).

For this purpose, instead of (or in addition to, see below) defining an <if:eval> element, an <if:eval-engine> element can also be defined. 

Example:

    <value if:eval-engine="com.sun.ph.Substitution">default value</value>

In the above example, the specified class is loaded using the engine's classpath (which includes dynamic plugins.  The engine is expected to implement the following interface:

public interface com.sun.install.provider.conf.oor.dynamic.EvalEngine {
  /\*\*
   \* This method should be used to resolve and return the correct value for substitution.
   \* The two arguments to the method, aEvalvalue and aDefaultValue can be used as per
   \* the need. Never return a null string instead return an empty string since the
   \* return value will may be displayed using UI.
   \*
   \*@param aEvalValue        The resolved 'eval' tag value.
   \*@param aDefaultValue    The default value of the value tag.
   \*@return                The resolved value which shouldn't be null.
   \*@throws EnhancedException If an unexpected error occurs
   \*/
  public String resolve(String aEvalValue, String aDefaultValue) throws Enhanced
Exception;
}

Notice that the first argument to the resolve method is the result of evaluating any <if:eval> element, if specified.  This gives a parameter three potential ways to specify a default value:  a hard-coded default, a resolved substitution variable, or the return value of an arbitrary piece of executed code.

Other Substitutions:

In addition to configuration schema definitions, other areas of this project will recognize and evaluate substitution expressions:

Properties files – Any property file supplied by the install author or end user is scanned for potential :[] substitution tokens.  Any expressions found are substituted with the resulting values as computed by the above descriptions.  If no value can be computed, a warning is issued and an empty value is used.

XML Resource files – Any XML file loaded by the engine is scanned for potential :[] substitution tokens. As above, any expressions found are substituted with the resulting values as computed by the above descriptions.  If no value can be computed, a warning is issued and an empty value is used.

User input – Any user input (e.g. In a GUI entry screen, or through an answer file) is scanned for potential :[] substitution tokens.  As above, any expressions found are substituted with the resulting values as computed by the above descriptions.  If no value can be computed, a warning is issued and an empty value is used.

 Want to know more about the openInstaller , visit http://openinstaller.org/ .

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

sandeeps

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today