Search in sources :

Example 1 with RootObjectReference

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

the class FlattenedSolution method setSolution.

public void setSolution(SolutionMetaData sol, boolean loadLoginSolution, boolean loadMainSolution, IActiveSolutionHandler activeSolutionHandler) throws RepositoryException, RemoteException {
    // $NON-NLS-1$
    if (sol == null)
        throw new IllegalArgumentException("use close method!");
    isLoadingSolution = true;
    try {
        copySolution = null;
        persistFactory = null;
        mainSolution = null;
        user_created_styles = null;
        all_styles = null;
        if (index != null) {
            index.destroy();
            index = null;
        }
        mainSolutionMetaData = sol;
        if (loadLoginSolution) {
            // get login solution
            Solution[] loginSolutionAndModules = activeSolutionHandler.loadLoginSolutionAndModules(mainSolutionMetaData);
            if (loginSolutionAndModules != null && loginSolutionAndModules.length > 0) {
                if (loginFlattenedSolution == null) {
                    loginFlattenedSolution = new ExtendsConfiguratingFlattenedSolution();
                }
                loginFlattenedSolution.setSolutionAndModules(loginSolutionAndModules[0].getName(), loginSolutionAndModules);
                loginFlattenedSolution.setParentSolution(this);
            }
        }
        // get regular solution if available
        if (// local or already access to repository
        loadMainSolution && activeSolutionHandler.haveRepositoryAccess()) {
            // Note: referencedModules includes main solution
            List<RootObjectReference> referencedModules = activeSolutionHandler.getRepository().getActiveSolutionModuleMetaDatas(mainSolutionMetaData.getRootObjectId());
            if (referencedModules != null && referencedModules.size() != 0) {
                List<RootObjectMetaData> solutionAndModuleMetaDatas = new ArrayList<RootObjectMetaData>();
                for (RootObjectReference moduleReference : referencedModules) {
                    RootObjectMetaData moduleMetaData = moduleReference.getMetaData();
                    if (moduleMetaData == null) {
                        // $NON-NLS-1$
                        throw new RepositoryException(Messages.getString("servoy.client.module.notfound", new Object[] { moduleReference.toString() }));
                    }
                    solutionAndModuleMetaDatas.add(moduleMetaData);
                }
                Solution[] mods = activeSolutionHandler.loadActiveSolutions(solutionAndModuleMetaDatas.toArray(new RootObjectMetaData[solutionAndModuleMetaDatas.size()]));
                setSolutionAndModules(mainSolutionMetaData.getName(), mods);
            }
        }
    } finally {
        isLoadingSolution = false;
    }
}
Also used : RootObjectMetaData(com.servoy.j2db.persistence.RootObjectMetaData) RootObjectReference(com.servoy.j2db.persistence.RootObjectReference) ArrayList(java.util.ArrayList) RepositoryException(com.servoy.j2db.persistence.RepositoryException) JSONObject(org.json.JSONObject) IRootObject(com.servoy.j2db.persistence.IRootObject) Solution(com.servoy.j2db.persistence.Solution)

Example 2 with RootObjectReference

use of com.servoy.j2db.persistence.RootObjectReference 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

RepositoryException (com.servoy.j2db.persistence.RepositoryException)2 RootObjectReference (com.servoy.j2db.persistence.RootObjectReference)2 Solution (com.servoy.j2db.persistence.Solution)2 FlattenedForm (com.servoy.j2db.persistence.FlattenedForm)1 Form (com.servoy.j2db.persistence.Form)1 IRootObject (com.servoy.j2db.persistence.IRootObject)1 RootObjectMetaData (com.servoy.j2db.persistence.RootObjectMetaData)1 Style (com.servoy.j2db.persistence.Style)1 RemoteException (java.rmi.RemoteException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 JSONObject (org.json.JSONObject)1