back to API     back to index     prev     next  

Variables for Descriptors

Principle

The objective of this feature is to allow the use of variables inside XML descriptors. Variables can be defined: directly in the descriptor, using independent files, or inside the deploying application's code (with an API).

The variable tags are usefull inside a descriptor because they can factorize frequent parameters. For example, a variable like ${PROACTIVE_HOME} can be defined, set and used in an XML Descriptor.

Variable Types

Variables can be defined in more than one place. When the value is set on multiple places, then the definition specified in the priority column will take precedence.

Variables Example

Descriptor Variables

All variable declarations must be written in a variable section at the beginning of the descriptor file in the following way:

	<variables>
	 <property name="USER_HOME" value="/usr/home/team"/> <!-- constant is default-->
	 <property name="PROACTIVE_HOME" value="ProActive/dist/ProActive" type="constant"/>

	 <property name="OPTIONAL_NODES" value="2" type="overrridableInXML"/>
	 <property name="USE_P2P" value="yes" type="overrridableInProgram"/>
	 <property name="NEEDED_NODES" value="" type="setInProgram" />
		  
	 <!-- example using jvm properties -->
	 <property name="JAVA_HOME" value="java.home" type="javaProperty"/>

	 <!-- loading external files with variables definitions -->
	 <propertiesFile location="context.properties"/>
	 <property file="context.xml"/>
	</variables>

	<!-- example usage -->
	...
	<classpath>
	 <absolutePath value="${USER_HOME}/${PROACTIVE_HOME}/ProActive.jar"/>
	 <absolutePath value="${JAVA_HOME}/lib/asm.jar"/>
	</classpath>
	...

Program Variables


External Variable Definitions Files

XML Files

Is built using XML property tags.

File : context.xml


	<!-- Definition of the specific context -->
	<property name="USER_HOME" value="/usr/home/team" />
	<property name="PROACTIVE_HOME" value="ProActive/dist/ProActive" />
	<property name="MIN_NODES" value="45" />
	

Properties Files

This approach uses Sun microsystems properties file format. The format is plain text with one definition per line in the format variable = value, as shown in the following example:

File : context.properties


	# Definition of the specific context
	USER_HOME = /usr/home/team
	PROACTIVE_HOME = ProActive/dist/ProActive
	MIN_NODES : 45
	

Note that colon (:) can be used instead of equal (=).

Program Variable API

The API for adding a single variable value is show below. The name corresponds to the variable name, and the value to the variable content. The type is the String corresponding to one of the supported variable types.

static public XMLProperties.setVariableValue( String name, String value, String type);

The API for adding a multiple variables is shown below. The variable name/value pair is specified as the key/content of the HashMap. The type is the String corresponding to one of the supported variable types.

static public XMLProperties.setVariableValue( HashMap map, String type);


Copyright © April 2005 INRIA All Rights Reserved.