Search in sources :

Example 1 with IServiceProvider

use of com.servoy.j2db.IServiceProvider in project servoy-client by Servoy.

the class SessionClient method executeMethod.

/*
	 * _______________________________________________________________________________
	 */
public synchronized Object executeMethod(String visibleFormName, String methodName, Object[] arguments) throws Exception {
    Object retval = null;
    IServiceProvider prev = testThreadLocals();
    try {
        String formName = visibleFormName;
        if (formName == null && ((FormManager) getFormManager()).getCurrentForm() != null) {
            formName = ((FormManager) getFormManager()).getCurrentForm().getName();
        }
        if (formName != null) {
            FormController fp = ((FormManager) getFormManager()).leaseFormPanel(formName);
            if (fp != null && fp.isFormVisible()) {
                return fp.executeFunction(methodName, arguments, true, null, false, null);
            } else {
                // $NON-NLS-1$
                throw new IllegalStateException("Cannot call method on non visible form " + formName);
            }
        } else {
            // $NON-NLS-1$
            throw new IllegalArgumentException("No current visible form specified");
        }
    } catch (IllegalStateException e1) {
        throw e1;
    } catch (IllegalArgumentException e2) {
        throw e2;
    } catch (Exception e) {
        Debug.error(e);
    } finally {
        unsetThreadLocals(prev);
    }
    return retval;
}
Also used : FormController(com.servoy.j2db.FormController) IFormController(com.servoy.j2db.IFormController) IServiceProvider(com.servoy.j2db.IServiceProvider) FormManager(com.servoy.j2db.FormManager) ApplicationException(com.servoy.j2db.ApplicationException) RemoteException(java.rmi.RemoteException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ServoyException(com.servoy.j2db.util.ServoyException) IOException(java.io.IOException) RepositoryException(com.servoy.j2db.persistence.RepositoryException)

Example 2 with IServiceProvider

use of com.servoy.j2db.IServiceProvider in project servoy-client by Servoy.

the class SessionClient method loadSolution.

@Override
protected void loadSolution(SolutionMetaData solutionMeta) throws RepositoryException {
    IServiceProvider prev = testThreadLocals();
    try {
        // make sure a new one in started if a new solution is loaded
        performanceData = null;
        loadSolutionsAndModules(solutionMeta);
        setAjaxUsage(solutionMeta.getName());
        enableAnchors(solutionMeta.getName());
        getScriptEngine();
    } finally {
        unsetThreadLocals(prev);
    }
// Note that getSolution() may return null at this point if the security.closeSolution() or security.logout() was called in onSolutionOpen
}
Also used : IServiceProvider(com.servoy.j2db.IServiceProvider)

Example 3 with IServiceProvider

use of com.servoy.j2db.IServiceProvider in project servoy-client by Servoy.

the class FormCssResource method getResourceStream.

/**
 * @see org.apache.wicket.Resource#getResourceStream()
 */
@Override
public IResourceStream getResourceStream() {
    String css = "";
    ValueMap params = getParameters();
    Long time = null;
    if (params.size() == 1) {
        Iterator iterator = params.entrySet().iterator();
        if (iterator.hasNext()) {
            Map.Entry entry = (Entry) iterator.next();
            String solutionName = (String) entry.getKey();
            Pair<String, Long> filterTime = filterTime((String) entry.getValue());
            String formInstanceName = filterTime.getLeft();
            time = filterTime.getRight();
            // $NON-NLS-1$
            String solutionAndForm = solutionName + "/" + formInstanceName;
            // $NON-NLS-1$
            String templateDir = "default";
            IServiceProvider sp = null;
            Solution solution = null;
            Form form = null;
            if (Session.exists()) {
                sp = WebClientSession.get().getWebClient();
                if (sp != null) {
                    IForm fc = ((WebClient) sp).getFormManager().getForm(formInstanceName);
                    if (fc instanceof FormController) {
                        FlattenedSolution clientSolution = sp.getFlattenedSolution();
                        form = clientSolution.getForm(((FormController) fc).getForm().getName());
                    }
                }
                templateDir = WebClientSession.get().getTemplateDirectoryName();
            }
            final String fullpath = "/servoy-webclient/templates/" + templateDir + "/" + solutionAndForm + ".css";
            try {
                URL url = context.getResource(fullpath);
                if (url != null) {
                    return new NullUrlResourceStream(url);
                }
            } catch (Exception e) {
                Debug.error(e);
            }
            try {
                IApplicationServerSingleton as = ApplicationServerRegistry.get();
                RootObjectMetaData sd = as.getLocalRepository().getRootObjectMetaData(solutionName, IRepository.SOLUTIONS);
                if (sd != null) {
                    solution = (Solution) as.getLocalRepository().getActiveRootObject(sd.getRootObjectId());
                    if (form == null) {
                        form = solution.getForm(formInstanceName);
                    }
                }
                if (form != null) {
                    Pair<String, String> formHTMLAndCSS = TemplateGenerator.getFormHTMLAndCSS(solution, form, sp, formInstanceName);
                    css = formHTMLAndCSS.getRight();
                }
            } catch (Exception e) {
                Debug.error(e);
            }
        }
    }
    // $NON-NLS-1$
    StringResourceStream stream = new StringResourceStream(css, "text/css");
    stream.setLastModified(time != null ? Time.valueOf(time.longValue()) : null);
    return stream;
}
Also used : Entry(java.util.Map.Entry) FormController(com.servoy.j2db.FormController) RootObjectMetaData(com.servoy.j2db.persistence.RootObjectMetaData) IApplicationServerSingleton(com.servoy.j2db.server.shared.IApplicationServerSingleton) IForm(com.servoy.j2db.IForm) Form(com.servoy.j2db.persistence.Form) ValueMap(org.apache.wicket.util.value.ValueMap) FlattenedSolution(com.servoy.j2db.FlattenedSolution) IForm(com.servoy.j2db.IForm) URL(java.net.URL) Entry(java.util.Map.Entry) IServiceProvider(com.servoy.j2db.IServiceProvider) Iterator(java.util.Iterator) StringResourceStream(org.apache.wicket.util.resource.StringResourceStream) Map(java.util.Map) ValueMap(org.apache.wicket.util.value.ValueMap) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Solution(com.servoy.j2db.persistence.Solution)

Example 4 with IServiceProvider

use of com.servoy.j2db.IServiceProvider in project servoy-client by Servoy.

the class ServoyDebugger method getFrame.

/**
 * @see org.eclipse.dltk.rhino.dbgp.DBGPDebugger#getFrame(org.mozilla.javascript.Context, org.mozilla.javascript.debug.DebuggableScript)
 */
@Override
public DebugFrame getFrame(Context cx, DebuggableScript fnOrScript) {
    final IServiceProvider client = J2DBGlobals.getServiceProvider();
    if (profilelisteners.size() > 0) {
        ProfileInfo info = profileInfo.get();
        return new ServoyDebugFrame(cx, fnOrScript, this, info != null ? info.peek() : null);
    }
    return new DBGPDebugFrame(cx, fnOrScript, this) {

        @Override
        public Object eval(String value) {
            if (client != null && J2DBGlobals.getServiceProvider() == null) {
                J2DBGlobals.setServiceProvider(client);
            }
            boolean reset = false;
            try {
                if (client instanceof NGClient && !CurrentWindow.exists()) {
                    // make sure that for an NGClient the current window is set.
                    CurrentWindow.set(new NGClientWebsocketSessionWindows(((NGClient) client).getWebsocketSession()));
                    reset = true;
                }
                return super.eval(value);
            } finally {
                if (reset)
                    CurrentWindow.set(null);
            }
        }
    };
}
Also used : IServiceProvider(com.servoy.j2db.IServiceProvider) NGClientWebsocketSessionWindows(com.servoy.j2db.server.ngclient.eventthread.NGClientWebsocketSessionWindows) NGClient(com.servoy.j2db.server.ngclient.NGClient) DBGPDebugFrame(org.eclipse.dltk.rhino.dbgp.DBGPDebugFrame)

Example 5 with IServiceProvider

use of com.servoy.j2db.IServiceProvider in project servoy-client by Servoy.

the class ScriptVariableScope method evalValue.

private Object evalValue(String name, String str, String sourceName, int lineNumber) {
    Object retValue = null;
    Context cx = Context.enter();
    boolean debug = cx.isGeneratingDebug();
    int level = cx.getOptimizationLevel();
    Debugger debugger = cx.getDebugger();
    Object debuggerContextData = cx.getDebuggerContextData();
    try {
        cx.setGeneratingDebug(lineNumber != -1);
        if (// flag should only be used in rich client //$NON-NLS-1$
        lineNumber != -1 || Utils.getAsBoolean(System.getProperty(ScriptEngine.SERVOY_DISABLE_SCRIPT_COMPILE_PROPERTY, "false"))) {
            cx.setOptimizationLevel(-1);
        } else {
            cx.setOptimizationLevel(9);
        }
        // cx.setDebugger(null, null);
        Object o = cx.evaluateString(this, str, sourceName, lineNumber == -1 ? 0 : lineNumber, null);
        if (o instanceof Wrapper && !(o instanceof NativeArray) && !(o instanceof NativeJavaClass)) {
            o = ((Wrapper) o).unwrap();
        }
        if (o == Scriptable.NOT_FOUND || o == Undefined.instance) {
            o = null;
        }
        retValue = o;
        Integer previousType = null;
        if (retValue instanceof Date) {
            // this is really an instance of Date so the type should be reset to that.
            previousType = nameType.put(name, new Integer(IColumnTypes.DATETIME));
        } else if (retValue instanceof XMLObject) {
            previousType = nameType.put(name, new Integer(Types.OTHER));
        } else if (retValue instanceof Number) {
            Integer prevType = nameType.get(name);
            if (prevType == null || !(prevType.intValue() == IColumnTypes.NUMBER || prevType.intValue() == IColumnTypes.INTEGER)) {
                previousType = nameType.put(name, new Integer(IColumnTypes.NUMBER));
            }
        } else if (!(retValue instanceof String) && !(retValue == null && nameType.get(name) != null)) {
            // this is not an instanceof a String and a Date so make it a
            previousType = nameType.put(name, new Integer(IColumnTypes.MEDIA));
        }
        if (previousType != null) {
            if (replacedNameType == null) {
                replacedNameType = new HashMap<String, Integer>(3);
                replacedNameType.put(name, previousType);
            } else if (!replacedNameType.containsKey(name)) {
                replacedNameType.put(name, previousType);
            }
        }
    } catch (Exception ex) {
        IServiceProvider serviceProvider = J2DBGlobals.getServiceProvider();
        if (serviceProvider != null) {
            serviceProvider.reportJSError("cant parse variable '" + name + '\'', ex);
        } else {
            // $NON-NLS-1$
            Debug.log("cant parse variable '" + name + '\'', ex);
        }
    } finally {
        try {
            cx.setGeneratingDebug(debug);
            cx.setOptimizationLevel(level);
            cx.setDebugger(debugger, debuggerContextData);
        } finally {
            Context.exit();
        }
    }
    return retValue;
}
Also used : Context(org.mozilla.javascript.Context) Debugger(org.mozilla.javascript.debug.Debugger) NativeArray(org.mozilla.javascript.NativeArray) Wrapper(org.mozilla.javascript.Wrapper) XMLObject(org.mozilla.javascript.xml.XMLObject) Date(java.util.Date) WrappedException(org.mozilla.javascript.WrappedException) IServiceProvider(com.servoy.j2db.IServiceProvider) XMLObject(org.mozilla.javascript.xml.XMLObject) NativeJavaClass(org.mozilla.javascript.NativeJavaClass)

Aggregations

IServiceProvider (com.servoy.j2db.IServiceProvider)14 Solution (com.servoy.j2db.persistence.Solution)3 FlattenedSolution (com.servoy.j2db.FlattenedSolution)2 FormController (com.servoy.j2db.FormController)2 IForm (com.servoy.j2db.IForm)2 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)2 Form (com.servoy.j2db.persistence.Form)2 FormScope (com.servoy.j2db.scripting.FormScope)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ApplicationException (com.servoy.j2db.ApplicationException)1 FormManager (com.servoy.j2db.FormManager)1 IFormController (com.servoy.j2db.IFormController)1 ClientInfo (com.servoy.j2db.dataprocessing.ClientInfo)1 IRepository (com.servoy.j2db.persistence.IRepository)1 RepositoryException (com.servoy.j2db.persistence.RepositoryException)1 RootObjectMetaData (com.servoy.j2db.persistence.RootObjectMetaData)1 WebForm (com.servoy.j2db.server.headlessclient.WebForm)1 NGClient (com.servoy.j2db.server.ngclient.NGClient)1 NGClientWebsocketSessionWindows (com.servoy.j2db.server.ngclient.eventthread.NGClientWebsocketSessionWindows)1 IApplicationServerSingleton (com.servoy.j2db.server.shared.IApplicationServerSingleton)1