Clover Coverage Report
Coverage timestamp: Sat Sep 18 2010 04:09:52 UTC
../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
49   154   16   16.33
22   99   0.33   3
3     5.33  
1    
 
  LoadRequiredModules       Line # 36 49 16 91.9% 0.9189189
 
  (41)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2010, Michael Meyling <mime@qedeq.org>.
4    *
5    * "Hilbert II" is free software; you can redistribute
6    * it and/or modify it under the terms of the GNU General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
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;
17   
18    import java.util.HashMap;
19    import java.util.Map;
20   
21    import org.qedeq.base.trace.Trace;
22    import org.qedeq.kernel.bo.module.KernelModuleReferenceList;
23    import org.qedeq.kernel.common.DefaultSourceFileExceptionList;
24    import org.qedeq.kernel.common.DependencyState;
25    import org.qedeq.kernel.common.ModuleDataException;
26    import org.qedeq.kernel.common.Plugin;
27    import org.qedeq.kernel.common.SourceFileException;
28    import org.qedeq.kernel.common.SourceFileExceptionList;
29   
30   
31    /**
32    * Load all required QEDEQ modules.
33    *
34    * @author Michael Meyling
35    */
 
36    public final class LoadRequiredModules {
37   
38    /** This class. */
39    private static final Class CLASS = LoadRequiredModules.class;
40   
41    /** All QedeqBos currently in state "loading required modules". */
42    private final Map loadingRequiredInProgress = new HashMap();
43   
44    /**
45    * Don't use this constructor.
46    */
 
47  63 toggle private LoadRequiredModules() {
48    // nothing to do
49    }
50   
51    /**
52    * Load all required QEDEQ modules for a given QEDEQ module.
53    *
54    * @param plugin We work for this plugin.
55    * @param prop QEDEQ module BO. This module must be loaded.
56    * @throws SourceFileExceptionList Failure(s).
57    * @throws IllegalArgumentException BO is not loaded
58    */
 
59  121 toggle public static void loadRequired(final Plugin plugin, final DefaultKernelQedeqBo prop)
60    throws SourceFileExceptionList {
61    // did we check this already?
62  121 if (prop.getDependencyState().areAllRequiredLoaded()) {
63  58 return; // everything is OK
64    }
65  63 (new LoadRequiredModules()).loadAllRequired(plugin, prop);
66    }
67   
68    /**
69    * Load all required QEDEQ modules for a given QEDEQ module.
70    *
71    * @param plugin We work for this plugin.
72    * @param prop QEDEQ module BO. This module must be loaded.
73    * @throws SourceFileExceptionList Failure(s).
74    * @throws IllegalArgumentException BO is not loaded
75    */
 
76  203 toggle private void loadAllRequired(final Plugin plugin, final DefaultKernelQedeqBo prop)
77    throws SourceFileExceptionList {
78  203 final String method = "loadRequired(DefaultQedeqBo)";
79  203 Trace.param(CLASS, this, method, "prop.getModuleAddress", prop.getModuleAddress());
80  203 synchronized (prop) {
81  203 if (prop.getDependencyState().areAllRequiredLoaded()) {
82  40 return; // everything is OK
83    }
84  163 if (!prop.isLoaded()) {
85  0 throw new IllegalArgumentException("Programming error BO must be loaded!");
86    }
87  163 if (loadingRequiredInProgress.containsKey(prop)) { // already checked?
88  0 throw new IllegalStateException("Programming error: must not be marked!");
89    }
90  163 prop.setDependencyProgressState(DependencyState.STATE_LOADING_REQUIRED_MODULES);
91  163 loadingRequiredInProgress.put(prop, prop);
92   
93    }
94  163 SourceFileExceptionList sfl = null;
95  163 final LoadDirectlyRequiredModules loader = new LoadDirectlyRequiredModules(plugin, prop);
96  163 KernelModuleReferenceList required = null;
97  163 try {
98  163 required = loader.load();
99  161 sfl = loader.getErrorList();
100    } catch (DefaultSourceFileExceptionList e) {
101  2 sfl = e;
102    }
103  163 if (sfl == null) {
104  316 for (int i = 0; i < required.size(); i++) {
105  155 Trace.trace(CLASS, this, method, "loading required modules of " + prop.getUrl());
106  155 DefaultKernelQedeqBo current = null;
107  155 current = (DefaultKernelQedeqBo) required.getKernelQedeqBo(i);
108  155 if (loadingRequiredInProgress.containsKey(current)) {
109  15 ModuleDataException me = new LoadRequiredModuleException(12,
110    "recursive import of modules is forbidden, label \""
111    + required.getLabel(i) + "\"",
112    required.getModuleContext(i));
113  15 final SourceFileException sf = prop.createSourceFileException(plugin, me);
114  15 if (sfl == null) {
115  13 sfl = new DefaultSourceFileExceptionList(sf);
116    } else {
117  2 sfl.add(sf);
118    }
119  15 continue;
120    }
121  140 try {
122  140 loadAllRequired(plugin, current);
123    } catch (SourceFileExceptionList e) {
124  35 ModuleDataException me = new LoadRequiredModuleException(13,
125    "import of module \"" + required.getLabel(i) + "\" failed: "
126    + e.get(0).getMessage(),
127    required.getModuleContext(i));
128  35 final SourceFileException sf = prop.createSourceFileException(plugin, me);
129  35 if (sfl == null) {
130  26 sfl = new DefaultSourceFileExceptionList(sf);
131    } else {
132  9 sfl.add(sf);
133    }
134  35 continue;
135    }
136    }
137    }
138   
139  163 synchronized (prop) {
140  163 loadingRequiredInProgress.remove(prop);
141  163 if (prop.getDependencyState().areAllRequiredLoaded()) {
142  0 return; // everything is OK, someone elses thread might have corrected errors!
143    }
144  163 if (sfl == null) {
145  122 prop.setLoadedRequiredModules(required);
146    } else {
147  41 prop.setDependencyFailureState(
148    DependencyState.STATE_LOADING_REQUIRED_MODULES_FAILED, sfl);
149  41 throw sfl;
150    }
151    }
152    }
153   
154    }