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;
}
}
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;
}
Aggregations