1 package org.simantics.scl.compiler.top;
\r
3 import java.lang.reflect.Field;
\r
5 import org.simantics.scl.compiler.internal.codegen.writer.ExternalConstant;
\r
7 public class StandardModuleInitializer implements ModuleInitializer {
\r
8 private final String moduleClassName;
\r
9 private final ExternalConstant[] externalConstants;
\r
11 private StandardModuleInitializer(String moduleClassName,
\r
12 ExternalConstant[] externalConstants) {
\r
13 this.moduleClassName = moduleClassName;
\r
14 this.externalConstants = externalConstants;
\r
18 public void initializeModule(ClassLoader classLoader) throws Exception {
\r
19 Class<?> clazz = classLoader.loadClass(moduleClassName.replace('/', '.'));
\r
20 for(ExternalConstant ec : externalConstants) {
\r
21 Field field = clazz.getField(ec.fieldName);
\r
22 field.set(null, ec.value);
\r
26 public static ModuleInitializer create(String moduleClassName, ExternalConstant[] externalConstants) {
\r
27 if(externalConstants.length == 0)
\r
30 return new StandardModuleInitializer(moduleClassName, externalConstants);
\r