Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The Java Condition can be used to check the value of a static field in a java class.

Example accessing a static field:

Code Block
languagexml
 <condition type="java" id="myStaticFieldIsTrue">
  <java>
    <class>my.package.MyClass</class>
    <field>myStaticField</field>
  </java>
  <returnvalue type="boolean">true</returnvalue>
</condition>


Example accessing a static method (as from izPack 5.2.0):

Code Block
languagexml
 <condition type="java" id="myStaticFieldIsTrue">
  <java>
    <class>my.package.MyClass</class>
    <method>processCondition</method>
  </java>
  <returnvalue type="boolean">true</returnvalue>
</condition>

Nested Elements

The Java condition must have a java ava element and a returnvalue element.

...

The java element contains two mandatory elements, class and field. <class> contains the fully qualified name of the class and either a <field> contains the name of the static field or a <method> containing the static method to inspect.

returnvalue

This element defines what is the expected value. Currently, only type="boolean" is " and "string" (as of izPack 5.2.0) are supported.

...

Complicated condition checks - example

In order to check for complicated conditions with java you can do the following. Assume that we use the same condition as above. 


Code Block
languagejava
package my.package
 
public class MyClass {
	public static boolean myStaticField = processCondition();
 
	public static boolean processCondition() {
		boolean conditionTrue = false;	
		//call other classes, conditionals, do processing, etc.
		return conditionTrue;
	}
} 

 

   


Note that for logging you will need to use log4j or similar. I use groovy in conjunction with an AntListener to log condition logs to temp. An easier way to accomplish this is to use process panels but if you absolutely must have a condition determined by java methods then this is the best way