Commits

Marcin Grzejszczak committed d3256cc

[Mappings] Refactoring - moved creation of the GroovyScriptEngine to the constructor

  • Participants
  • Parent commits adc5b35

Comments (0)

Files changed (1)

Groovy/Mappings/src/main/java/com/blogspot/toomuchcoding/factory/TransformerFactoryImpl.java

 import org.slf4j.LoggerFactory;
 
 import java.io.File;
+import java.io.IOException;
 import java.net.URL;
 
 /**
     private static Logger LOGGER = LoggerFactory.getLogger(TransformerFactoryImpl.class);
 
     private ScriptFactory scriptFactory;
+    private GroovyScriptEngine groovyScriptEngine;
 
     public TransformerFactoryImpl(ScriptFactory scriptFactory) {
         this.scriptFactory = scriptFactory;
+        try {
+            groovyScriptEngine = new GroovyScriptEngine(GROOVY_SCRIPTS_CLASSPATH);
+        } catch (IOException e) {
+            LOGGER.error("Exception occurred while trying to create the Groovy script engine", e);
+        }
     }
 
     @Override
     public Transformer<String, String> createTransformer() {
         Transformer<String, String> transformerFromScript = null;
         try {
-            GroovyScriptEngine groovyScriptEngine = new GroovyScriptEngine(GROOVY_SCRIPTS_CLASSPATH);
             File scriptFile = scriptFactory.createScript();
             URL scriptAsAClasspathResource = Resources.getResource(GROOVY_SCRIPTS_CLASSPATH + scriptFile.getName());
             Class classFromScript = groovyScriptEngine.loadScriptByName(scriptAsAClasspathResource.getFile());