src/main/java/js/container/ManagedClass.java
private void initializeStaticFields() throws ConfigException {
		if (config == null) {
			return;
		}
		for (Config config : config.findChildren("static-field")) {
			String fieldName = config.getAttribute("name");
			if (fieldName == null) {
				throw new ConfigException("Missing <name> attribute from static field initialization |%s|.", config.getParent());
			}
			if (!config.hasAttribute("value")) {
				throw new ConfigException("Missing <value> attribute from static field initialization |%s|.", config.getParent());
			}

			Field field = Classes.getOptionalField(implementationClass, fieldName);
			if (field == null) {
				throw new ConfigException("Missing managed class static field |%s#%s|.", implementationClass, fieldName);
			}
			int modifiers = field.getModifiers();
			if (!Modifier.isStatic(modifiers)) {
				throw new ConfigException("Attempt to execute static initialization on instance field |%s#%s|.", implementationClass, fieldName);
			}

			Object value = config.getAttribute("value", field.getType());
			log.debug("Intialize static field |%s#%s| |%s|", implementationClass, fieldName, value);
			Classes.setFieldValue(null, field, config.getAttribute("value", field.getType()));
		}
	}
private void initializeStaticFields() throws ConfigException {
		if (config == null) {
			return;
		}
		for (Config config : config.findChildren("static-field")) {
			String fieldName = config.getAttribute("name");
			if (fieldName == null) {
				throw new ConfigException("Missing <name> attribute from static field initialization |%s|.", config.getParent());
			}
			if (!config.hasAttribute("value")) {
				throw new ConfigException("Missing <value> attribute from static field initialization |%s|.", config.getParent());
			}

			Field field = Classes.getOptionalField(implementationClass, fieldName);
			if (field == null) {
				throw new ConfigException("Missing managed class static field |%s#%s|.", implementationClass, fieldName);
			}
			int modifiers = field.getModifiers();
			if (!Modifier.isStatic(modifiers)) {
				throw new ConfigException("Attempt to execute static initialization on instance field |%s#%s|.", implementationClass, fieldName);
			}

			Object value = config.getAttribute("value", field.getType());
			log.debug("Intialize static field |%s#%s| |%s|", implementationClass, fieldName, value);
			Classes.setFieldValue(null, field, config.getAttribute("value", field.getType()));
		}
	}
private void initializeStaticFields ( ) throws ConfigException { if ( config == null ) { return ; } for ( Config config : config . findChildren ( "static-field" ) ) { String fieldName = config . getAttribute ( "name" ) ; if ( fieldName == null ) { throw new ConfigException ( "Missing <name> attribute from static field initialization |%s|." , config . getParent ( ) ) ; } if ( ! config . hasAttribute ( "value" ) ) { throw new ConfigException ( "Missing <value> attribute from static field initialization |%s|." , config . getParent ( ) ) ; } Field field = Classes . getOptionalField ( implementationClass , fieldName ) ; if ( field == null ) { throw new ConfigException ( "Missing managed class static field |%s#%s|." , implementationClass , fieldName ) ; } int modifiers = field . getModifiers ( ) ; if ( ! Modifier . isStatic ( modifiers ) ) { throw new ConfigException ( "Attempt to execute static initialization on instance field |%s#%s|." , implementationClass , fieldName ) ; } Object value = config . getAttribute ( "value" , field . getType ( ) ) ; log . debug ( "Intialize static field |%s#%s| |%s|" , implementationClass , fieldName , value ) ; Classes . setFieldValue ( null , field , config . getAttribute ( "value" , field . getType ( ) ) ) ; } }
Initialize implementation class static, not final, fields. Static initializer reads name / value pairs from
<code>static-field</code> configuration element, see sample below. String value is converted to instance field type using
{@link Converter#asObject(String, Class)} utility. This means that configured value should be convertible to field type,
otherwise {@link ConverterException} is thrown.
<p>
In sample there is a <code>person</code> managed instance that has a configuration section. Configuration declares three
static fields that will be initialized with defined values when managed class is created.

<pre>
&lt;managed-classes&gt;
&lt;person class="js.app.Person" /&gt;
&lt;/managed-classes&gt;
...
&lt;person&gt;
&lt;static-field name='name' value='John Doe' /&gt;
&lt;static-field name='age' value='54' /&gt;
&lt;static-field name='married' value='false' /&gt;
&lt;/person&gt;
...
class Person {
private static String name;
private static int age;
private static boolean married;
}
</pre>

@throws ConfigException if static field descriptor is invalid, field is missing or is instance field.
Initialize implementation class static not final fields . Static initializer reads name / value pairs from <code > static - field< / code > configuration element see sample below . String value is converted to instance field type using { @link Converter#asObject ( String Class ) } utility . This means that configured value should be convertible to field type otherwise { @link ConverterException } is thrown . <p > In sample there is a <code > person< / code > managed instance that has a configuration section . Configuration declares three static fields that will be initialized with defined values when managed class is created .