Skip to content
Permalink
Browse files

Improved: Disallow extension of the script helper bindings (OFBIZ-10825)

‘ScriptHelper’ is a mechanism used to add some useful bindings to
scripts.  This feature has been introduced in revision 1299924 by
Adrian Crum as part of an general effort of supporting the Generic
Scripting Engine specified by JSR-223.

Previously this mechanism was extensible, however it appears to be
undesirable (nor used in practice) to extend the bindings available to
services since the internal service implementations are highly coupled
to those bindings.  As a consequence the usage of the Abstract Factory
pattern which was used for that purpose is now removed.

The side effect of this change is that we have now simpler code.


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1854668 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mthl committed Mar 2, 2019
1 parent 4fbb189 commit 617b7629156ea7d56c78f17035ecd581d84885b8

This file was deleted.

@@ -27,10 +27,8 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.Set;

import javax.script.Bindings;
@@ -47,6 +45,8 @@

import org.apache.ofbiz.base.location.FlexibleLocation;
import org.apache.ofbiz.base.util.cache.UtilCache;
import org.apache.ofbiz.base.util.ScriptHelper;
import org.apache.ofbiz.common.scripting.ScriptHelperImpl;
import org.codehaus.groovy.runtime.InvokerHelper;

/**
@@ -70,7 +70,6 @@
public static final String SCRIPT_HELPER_KEY = "ofbiz";
private static final UtilCache<String, CompiledScript> parsedScripts = UtilCache.createUtilCache("script.ParsedScripts", 0, 0, false);
private static final Object[] EMPTY_ARGS = {};
private static ScriptHelperFactory helperFactory = null;
/** A set of script names - derived from the JSR-223 scripting engines. */
public static final Set<String> SCRIPT_NAMES;

@@ -104,15 +103,6 @@
}
}
SCRIPT_NAMES = Collections.unmodifiableSet(writableScriptNames);
Iterator<ScriptHelperFactory> iter = ServiceLoader.load(ScriptHelperFactory.class).iterator();
if (iter.hasNext()) {
helperFactory = iter.next();
if (Debug.verboseOn()) {
Debug.logVerbose("ScriptHelper factory set to " + helperFactory.getClass().getName(), module);
}
} else {
Debug.logWarning("ScriptHelper factory not found", module);
}
}

/**
@@ -206,7 +196,7 @@ public static ScriptContext createScriptContext(Map<String, Object> context) {
localContext.put(WIDGET_CONTEXT_KEY, context);
localContext.put("context", context);
ScriptContext scriptContext = new SimpleScriptContext();
ScriptHelper helper = createScriptHelper(scriptContext);
ScriptHelper helper = new ScriptHelperImpl(scriptContext);
if (helper != null) {
localContext.put(SCRIPT_HELPER_KEY, helper);
}
@@ -233,21 +223,11 @@ public static ScriptContext createScriptContext(Map<String, Object> context, Set
ScriptContext scriptContext = new SimpleScriptContext();
Bindings bindings = new ProtectedBindings(localContext, Collections.unmodifiableSet(protectedKeys));
scriptContext.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
ScriptHelper helper = createScriptHelper(scriptContext);
if (helper != null) {
localContext.put(SCRIPT_HELPER_KEY, helper);
}
localContext.put(SCRIPT_HELPER_KEY, new ScriptHelperImpl(scriptContext));
return scriptContext;
}

public static ScriptHelper createScriptHelper(ScriptContext context) {
if (helperFactory != null) {
return helperFactory.getInstance(context);
}
return null;
}

/**
/**
* Executes a script <code>String</code> and returns the result.
*
* @param language

This file was deleted.

This file was deleted.

0 comments on commit 617b762

Please sign in to comment.
You can’t perform that action at this time.