use of com.servoy.j2db.server.ngclient.scripting.WebServiceFunction in project servoy-client by Servoy.
the class NGClient method doCallCloseSolutionMethod.
private boolean doCallCloseSolutionMethod(boolean force) {
boolean canClose = super.callCloseSolutionMethod(force);
// cleanup here before script engine is destroyed
if (canClose || force) {
SpecProviderState specProviderState = WebServiceSpecProvider.getSpecProviderState();
if (specProviderState != null) {
WebObjectSpecification[] serviceSpecifications = specProviderState.getAllWebComponentSpecifications();
for (WebObjectSpecification serviceSpecification : serviceSpecifications) {
WebObjectFunctionDefinition apiFunction = serviceSpecification.getApiFunction("cleanup");
if (apiFunction != null && getScriptEngine() != null) {
final PluginScope scope = (PluginScope) getScriptEngine().getSolutionScope().get("plugins", getScriptEngine().getSolutionScope());
if (scope != null) {
final Scriptable service = (Scriptable) scope.get(serviceSpecification.getScriptingName(), null);
final Object api = service.get(apiFunction.getName(), null);
if (api instanceof Function) {
Runnable r = new Runnable() {
@Override
public void run() {
Context context = Context.enter();
try {
((Function) api).call(context, scope, service, ScriptRuntime.emptyArgs);
} catch (Exception ex) {
Debug.trace(ex);
} finally {
Context.exit();
}
}
};
if (api instanceof WebServiceFunction) {
invokeAndWait(r);
} else {
r.run();
}
}
}
}
}
}
}
return canClose;
}
Aggregations