Search in sources :

Example 1 with WebServiceFunction

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;
}
Also used : BrowserConverterContext(org.sablo.specification.property.BrowserConverterContext) Context(org.mozilla.javascript.Context) WebObjectSpecification(org.sablo.specification.WebObjectSpecification) WebServiceScriptable(com.servoy.j2db.server.ngclient.scripting.WebServiceScriptable) Scriptable(org.mozilla.javascript.Scriptable) WebObjectFunctionDefinition(org.sablo.specification.WebObjectFunctionDefinition) ServoyException(com.servoy.j2db.util.ServoyException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ApplicationException(com.servoy.j2db.ApplicationException) RemoteException(java.rmi.RemoteException) MalformedURLException(java.net.MalformedURLException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) Function(org.mozilla.javascript.Function) WebServiceFunction(com.servoy.j2db.server.ngclient.scripting.WebServiceFunction) BrowserFunction(com.servoy.j2db.server.ngclient.property.BrowserFunction) SpecProviderState(org.sablo.specification.SpecProviderState) WebServiceFunction(com.servoy.j2db.server.ngclient.scripting.WebServiceFunction) PluginScope(com.servoy.j2db.scripting.PluginScope) BaseWebObject(org.sablo.BaseWebObject) JSONObject(org.json.JSONObject)

Aggregations

ApplicationException (com.servoy.j2db.ApplicationException)1 RepositoryException (com.servoy.j2db.persistence.RepositoryException)1 PluginScope (com.servoy.j2db.scripting.PluginScope)1 BrowserFunction (com.servoy.j2db.server.ngclient.property.BrowserFunction)1 WebServiceFunction (com.servoy.j2db.server.ngclient.scripting.WebServiceFunction)1 WebServiceScriptable (com.servoy.j2db.server.ngclient.scripting.WebServiceScriptable)1 ServoyException (com.servoy.j2db.util.ServoyException)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 RemoteException (java.rmi.RemoteException)1 ExecutionException (java.util.concurrent.ExecutionException)1 JSONObject (org.json.JSONObject)1 Context (org.mozilla.javascript.Context)1 Function (org.mozilla.javascript.Function)1 Scriptable (org.mozilla.javascript.Scriptable)1 BaseWebObject (org.sablo.BaseWebObject)1 SpecProviderState (org.sablo.specification.SpecProviderState)1 WebObjectFunctionDefinition (org.sablo.specification.WebObjectFunctionDefinition)1 WebObjectSpecification (org.sablo.specification.WebObjectSpecification)1 BrowserConverterContext (org.sablo.specification.property.BrowserConverterContext)1