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