LoadAllRequiredModulesExecutor.java
01 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
02  *
03  * Copyright 2000-2013,  Michael Meyling <mime@qedeq.org>.
04  *
05  * "Hilbert II" is free software; you can redistribute
06  * it and/or modify it under the terms of the GNU General Public
07  * License as published by the Free Software Foundation; either
08  * version 2 of the License, or (at your option) any later version.
09  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  */
15 
16 package org.qedeq.kernel.bo.service.dependency;
17 
18 import org.qedeq.base.io.Parameters;
19 import org.qedeq.kernel.bo.common.ModuleReferenceList;
20 import org.qedeq.kernel.bo.module.ControlVisitor;
21 import org.qedeq.kernel.bo.module.InternalServiceProcess;
22 import org.qedeq.kernel.bo.module.KernelQedeqBo;
23 import org.qedeq.kernel.bo.module.PluginExecutor;
24 import org.qedeq.kernel.se.common.Plugin;
25 
26 
27 /**
28  * Load all required QEDEQ modules.
29  *
30  @author  Michael Meyling
31  */
32 public final class LoadAllRequiredModulesExecutor extends ControlVisitor
33         implements PluginExecutor {
34 
35     /** This class. */
36     private static final Class CLASS = LoadAllRequiredModulesExecutor.class;
37 
38     /**
39      * Constructor.
40      *
41      @param   plugin      Plugin we work for.
42      @param   prop        Internal QedeqBo.
43      @param   parameter   Currently ignored.
44      */
45     public LoadAllRequiredModulesExecutor(final Plugin plugin, final KernelQedeqBo prop,
46             final Parameters parameter) {
47         super(plugin, prop);
48     }
49 
50     public Object executePlugin(final InternalServiceProcess process, final Object data) {
51         if (getQedeqBo().hasLoadedRequiredModules()) {
52             return Boolean.TRUE;
53         }
54         getServices().executePlugin(LoadDirectlyRequiredModulesPlugin.class.getName(),
55             getQedeqBo(), data, process);
56         if (!getQedeqBo().hasLoadedImports()) {
57             return Boolean.FALSE;
58         }
59         final ModuleReferenceList imports = getQedeqBo().getRequiredModules();
60         boolean result = true;
61         for (int i = 0; i < imports.size(); i++) {
62             if (!imports.getQedeqBo(i).hasLoadedImports()) {
63                 getServices().executePlugin(LoadAllRequiredModulesPlugin.class.getName(),
64                     (KernelQedeqBoimports.getQedeqBo(i), data, process);
65             }
66             if (!imports.getQedeqBo(i).hasLoadedImports()) {
67                 result = false;
68             }
69         }
70         return Boolean.valueOf(result);
71     }
72 
73 }