Author: aparfonov
Date: 2010-05-13 05:23:41 -0400 (Thu, 13 May 2010)
New Revision: 2376
Modified:
core/trunk/exo.core.component.script.groovy/src/main/java/org/exoplatform/services/script/groovy/GroovyScriptInstantiator.java
Log:
EXOJCR-721 :
Modified:
core/trunk/exo.core.component.script.groovy/src/main/java/org/exoplatform/services/script/groovy/GroovyScriptInstantiator.java
===================================================================
---
core/trunk/exo.core.component.script.groovy/src/main/java/org/exoplatform/services/script/groovy/GroovyScriptInstantiator.java 2010-05-12
17:17:03 UTC (rev 2375)
+++
core/trunk/exo.core.component.script.groovy/src/main/java/org/exoplatform/services/script/groovy/GroovyScriptInstantiator.java 2010-05-13
09:23:41 UTC (rev 2376)
@@ -19,6 +19,7 @@
package org.exoplatform.services.script.groovy;
import groovy.lang.GroovyClassLoader;
+import groovy.lang.GroovyCodeSource;
import org.codehaus.groovy.control.CompilationFailedException;
import org.exoplatform.container.ExoContainer;
@@ -188,6 +189,34 @@
}
/**
+ * Instantiate script from give {@link GroovyCodeSource} and use given
+ * class-loader. If <code>loader == null</code> then
+ * {@link groovy.lang.GroovyClassLoader} will be is use.
+ *
+ * @param codeSource code source
+ * @param loader
+ * @return
+ * @throws IOException
+ */
+ public Object instantiateScript(GroovyCodeSource codeSource, GroovyClassLoader
loader)
+ {
+ if (loader == null)
+ {
+ loader = new GroovyClassLoader();
+ }
+ Class<?> clazz = null;
+ clazz = loader.parseClass(codeSource);
+ try
+ {
+ return createObject(clazz);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Can't instantiate groovy script: " +
e.getMessage(), e);
+ }
+ }
+
+ /**
* Created object from given class, if class has parameters in constructor,
* then this parameters will be searched in container.
*
Show replies by date