Search in sources :

Example 36 with Solution

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

the class ClientState method handleException.

public void handleException(String servoyMsg, final Exception e) {
    // Ignore the ExitScriptException completely.
    if (e instanceof ExitScriptException || e.getCause() instanceof ExitScriptException || (e instanceof JavaScriptException && ((JavaScriptException) e).getValue() instanceof ExitScriptException))
        return;
    // If the given message is null then let it be the localized message of the deepest cause (the real cause)
    String msg = servoyMsg;
    if (msg == null) {
        Throwable t = e;
        while (t.getCause() != null) {
            t = t.getCause();
        }
        msg = t.getLocalizedMessage();
    }
    Solution s = getSolution();
    if (// && (e instanceof ApplicationException || e instanceof DataException || e instanceof JavaScriptException))
    s != null) {
        Object thrown = getScriptException(e);
        if (!testClientRegistered(thrown)) {
            return;
        }
        ScriptMethod sm = null;
        int mid = s.getOnErrorMethodID();
        if (mid > 0) {
            sm = getFlattenedSolution().getScriptMethod(mid);
        }
        if (// check for error handler, or when a error ocurs in error handler
        sm == null || isHandlingError) {
            reportError(msg, e);
        } else {
            try {
                isHandlingError = true;
                Object retval = getScriptEngine().getScopesScope().executeGlobalFunction(sm.getScopeName(), sm.getName(), // $NON-NLS-1$
                Utils.arrayMerge((new Object[] { thrown }), Utils.parseJSExpressions(s.getFlattenedMethodArguments("onErrorMethodID"))), false, false);
                if (Utils.getAsBoolean(retval)) {
                    // error handler cannot handle this error
                    reportError(msg, e);
                }
            } catch (Exception e1) {
                reportError(msg, e);
            } finally {
                isHandlingError = false;
            }
        }
    } else // no solution
    {
        reportError(msg, e);
    }
}
Also used : NativeObject(org.mozilla.javascript.NativeObject) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) Solution(com.servoy.j2db.persistence.Solution) UnmarshalException(java.rmi.UnmarshalException) RhinoException(org.mozilla.javascript.RhinoException) RemoteException(java.rmi.RemoteException) ServoyException(com.servoy.j2db.util.ServoyException) JavaScriptException(org.mozilla.javascript.JavaScriptException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) JavaScriptException(org.mozilla.javascript.JavaScriptException)

Example 37 with Solution

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

the class MessagesResourceBundle method getMessages.

private Properties getMessages() {
    if (messages == null) {
        messages = new Properties();
        if (application != null) {
            Solution sol;
            try {
                sol = (Solution) application.getRepository().getActiveRootObject(solutionId);
                Messages.loadMessagesFromDatabaseInternal(null, application.getClientID(), application.getSettings(), application.getDataServer(), application.getRepository(), messages, locale, Messages.ALL_LOCALES, null, null, i18nColumnName, i18nColunmValue, application.getFoundSetManager());
                Messages.loadMessagesFromDatabaseInternal(sol != null ? sol.getI18nDataSource() : null, application.getClientID(), application.getSettings(), application.getDataServer(), application.getRepository(), messages, locale, Messages.ALL_LOCALES, null, null, i18nColumnName, i18nColunmValue, application.getFoundSetManager());
            } catch (Exception e) {
                Debug.error(e);
            }
        } else if (applicationServerLoader != null) {
            // we are on the server load from the server.
            applicationServerLoader.loadMessages(messages, locale, solutionId, i18nColumnName, i18nColunmValue, null);
        }
    }
    return messages;
}
Also used : Properties(java.util.Properties) Solution(com.servoy.j2db.persistence.Solution) MissingResourceException(java.util.MissingResourceException) IOException(java.io.IOException)

Example 38 with Solution

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

the class FlattenedSolution method setSolutionAndModules.

protected void setSolutionAndModules(String mainSolutionName, Solution[] mods) throws RemoteException {
    // name -> solution
    Map<String, Solution> modulesMap = new HashMap<String, Solution>();
    for (Solution module : mods) {
        if (module != null) {
            if (mainSolutionName.equals(module.getName())) {
                mainSolution = module;
            } else if (!modulesMap.containsKey(module.getName())) {
                modulesMap.put(module.getName(), module);
            }
        }
    }
    if (mainSolution != null) {
        if (mainSolution.getChangeHandler() != null) {
            mainSolution.getChangeHandler().addIPersistListener(this);
        }
        for (Solution module : modulesMap.values()) {
            combineServerProxies(mainSolution.getServerProxies(), module.getServerProxies());
        }
    }
    modules = getDependencyGraphOrderedModules(modulesMap.values(), mainSolution);
    flushAllCachedData();
    getAllStyles();
    for (Solution s : modules) {
        HashMap<String, Style> modStyles = s.getSerializableRuntimeProperty(Solution.PRE_LOADED_STYLES);
        if (modStyles != null) {
            synchronized (modStyles) {
                Map<String, Style> allStyles = getAllStyles();
                synchronized (// the two syncs should not cause deadlock because the module's lock is always acquired first (so another thread cannot come and do it backwards)
                allStyles) {
                    allStyles.putAll(modStyles);
                }
            }
        }
        if (s.getChangeHandler() != null) {
            s.getChangeHandler().addIPersistListener(this);
        }
    }
    // everything loaded, let the index be created.
    if (index != null) {
        index.destroy();
        index = null;
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Style(com.servoy.j2db.persistence.Style) Solution(com.servoy.j2db.persistence.Solution)

Example 39 with Solution

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

the class FlattenedSolution method close.

// commit all user data
public void close(IActiveSolutionHandler handler) {
    flushAllCachedData();
    if (loginFlattenedSolution != null) {
        loginFlattenedSolution.close(handler);
    }
    loginFlattenedSolution = null;
    if (mainSolution != null) {
        if (mainSolution.getChangeHandler() != null) {
            mainSolution.getChangeHandler().removeIPersistListener(this);
        }
        // try disksave in client
        if (handler != null)
            handler.saveActiveSolution(mainSolution);
        mainSolution = null;
    }
    if (modules != null) {
        for (Solution element : modules) {
            // try disksave in client
            if (handler != null)
                handler.saveActiveSolution(element);
            if (element.getChangeHandler() != null) {
                element.getChangeHandler().removeIPersistListener(this);
            }
        }
        modules = null;
    }
    mainSolutionMetaData = null;
    synchronized (liveForms) {
        changedForms.clear();
        liveForms.clear();
    }
    designFormName = null;
    copySolution = null;
    persistFactory = null;
    allObjectsSize = 256;
    parentFlattenedSolution = null;
    if (index != null) {
        index.destroy();
        index = null;
    }
}
Also used : Solution(com.servoy.j2db.persistence.Solution)

Example 40 with Solution

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

the class FlattenedSolution method loadStyleForForm.

/**
 * Load style for form, look for extend forms in flattenedSolution when possible
 * @param flattenedSolution may be null, fallback to f.getSolution() plus repo load
 * @param f
 */
public static Style loadStyleForForm(FlattenedSolution flattenedSolution, Form form) {
    try {
        String style_name = form.getStyleName();
        if (!(form instanceof FlattenedForm)) {
            Form extendedForm;
            int extended_form_id = form.getExtendsID();
            List<RootObjectReference> modulesMetaData = null;
            // We keep track of visited forms, to avoid infinite loop.
            Set<Integer> visited = new HashSet<Integer>();
            while (style_name == null && extended_form_id > 0) {
                visited.add(new Integer(extended_form_id));
                // if this is hit here with a normal (not flattened form) that has an extend.
                // and that form is a solution modal form. the f.getSolution() doesn't have to find it.
                // because f.getSolution() is the copy solution thats inside the FlattenedSolution.
                // that one doesn't have any other forms. But normally all forms should be flattened.
                extendedForm = flattenedSolution == null ? form.getSolution().getForm(extended_form_id) : flattenedSolution.getForm(extended_form_id);
                if (// check for module form
                flattenedSolution == null && extendedForm == null) {
                    if (modulesMetaData == null) {
                        modulesMetaData = form.getSolution().getRepository().getActiveSolutionModuleMetaDatas(form.getSolution().getID());
                    }
                    for (RootObjectReference moduleMetaData : modulesMetaData) {
                        Solution module = (Solution) form.getSolution().getRepository().getActiveRootObject(moduleMetaData.getMetaData().getRootObjectId());
                        extendedForm = module.getForm(extended_form_id);
                        if (extendedForm != null) {
                            break;
                        }
                    }
                }
                if (extendedForm == null) {
                    // in case referring to no longer existing form
                    break;
                }
                style_name = extendedForm.getStyleName();
                extended_form_id = extendedForm.getExtendsID();
                if (visited.contains(new Integer(extended_form_id))) {
                    // in case of cycle in form inheritance hierarchy
                    break;
                }
            }
        }
        if (style_name == null)
            return null;
        // preload the style at the server
        Style s = (Style) form.getSolution().getRepository().getActiveRootObject(style_name, IRepository.STYLES);
        return s;
    } catch (Exception e) {
        Debug.error(e);
    }
    return null;
}
Also used : FlattenedForm(com.servoy.j2db.persistence.FlattenedForm) Form(com.servoy.j2db.persistence.Form) FlattenedForm(com.servoy.j2db.persistence.FlattenedForm) RootObjectReference(com.servoy.j2db.persistence.RootObjectReference) Style(com.servoy.j2db.persistence.Style) Solution(com.servoy.j2db.persistence.Solution) RemoteException(java.rmi.RemoteException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) HashSet(java.util.HashSet)

Aggregations

Solution (com.servoy.j2db.persistence.Solution)59 FlattenedSolution (com.servoy.j2db.FlattenedSolution)17 Form (com.servoy.j2db.persistence.Form)16 ScriptMethod (com.servoy.j2db.persistence.ScriptMethod)14 RepositoryException (com.servoy.j2db.persistence.RepositoryException)12 ArrayList (java.util.ArrayList)9 RemoteException (java.rmi.RemoteException)8 HashMap (java.util.HashMap)8 FlattenedForm (com.servoy.j2db.persistence.FlattenedForm)7 IPersist (com.servoy.j2db.persistence.IPersist)6 TableNode (com.servoy.j2db.persistence.TableNode)6 ServoyException (com.servoy.j2db.util.ServoyException)6 JSONObject (org.json.JSONObject)6 IFormController (com.servoy.j2db.IFormController)5 Map (java.util.Map)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 JavaScriptException (org.mozilla.javascript.JavaScriptException)5 IRepository (com.servoy.j2db.persistence.IRepository)4 List (java.util.List)4 ApplicationException (com.servoy.j2db.ApplicationException)3