Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
../../../../../../img/srcFileCovDistChart7.png 74% of files have more coverage
60   196   18   10
8   140   0.3   6
6     3  
1    
 
  QedeqBoFactoryAssert       Line # 55 60 18 70.3% 0.7027027
 
  (8)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2013, 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.control;
17   
18    import java.lang.reflect.InvocationTargetException;
19   
20    import org.qedeq.base.io.Parameters;
21    import org.qedeq.base.io.SourceArea;
22    import org.qedeq.base.test.DynamicGetter;
23    import org.qedeq.base.trace.Trace;
24    import org.qedeq.base.utility.YodaUtility;
25    import org.qedeq.kernel.bo.module.InternalKernelServices;
26    import org.qedeq.kernel.bo.module.InternalServiceCall;
27    import org.qedeq.kernel.bo.module.InternalServiceProcess;
28    import org.qedeq.kernel.bo.module.KernelQedeqBo;
29    import org.qedeq.kernel.bo.module.QedeqFileDao;
30    import org.qedeq.kernel.bo.service.control.DefaultInternalKernelServices;
31    import org.qedeq.kernel.bo.service.control.DefaultKernelQedeqBo;
32    import org.qedeq.kernel.bo.service.control.ModuleLabelsCreator;
33    import org.qedeq.kernel.bo.service.control.QedeqVoBuilder;
34    import org.qedeq.kernel.bo.service.control.ServiceProcessManager;
35    import org.qedeq.kernel.bo.service.latex.QedeqBoDuplicateLanguageChecker;
36    import org.qedeq.kernel.bo.test.DummyPlugin;
37    import org.qedeq.kernel.bo.test.KernelFacade;
38    import org.qedeq.kernel.se.base.module.Qedeq;
39    import org.qedeq.kernel.se.common.ModuleAddress;
40    import org.qedeq.kernel.se.common.ModuleDataException;
41    import org.qedeq.kernel.se.common.SourceFileExceptionList;
42    import org.qedeq.kernel.se.dto.module.QedeqVo;
43    import org.qedeq.kernel.se.state.LoadingState;
44    import org.qedeq.kernel.se.visitor.InterruptException;
45    import org.qedeq.kernel.xml.dao.XmlQedeqFileDao;
46    import org.qedeq.kernel.xml.mapper.Context2SimpleXPath;
47    import org.qedeq.kernel.xml.tracker.SimpleXPath;
48    import org.qedeq.kernel.xml.tracker.XPathLocationParser;
49   
50    /**
51    * For testing QEDEQ BO generation.
52    *
53    * @author Michael Meyling
54    */
 
55    public class QedeqBoFactoryAssert extends QedeqVoBuilder {
56   
57    /** This class. */
58    private static final Class CLASS = QedeqBoFactoryAssert.class;
59   
60    /**
61    * Constructor.
62    *
63    * @param address QEDEQ module address.
64    */
 
65  17 toggle public QedeqBoFactoryAssert(final ModuleAddress address) {
66  17 super(address);
67    }
68   
 
69  68 toggle public static DefaultInternalKernelServices getInternalServices() {
70  68 try {
71  68 return (DefaultInternalKernelServices) YodaUtility.getFieldValue(
72    KernelFacade.getKernelContext(), "services");
73    } catch (NoSuchFieldException e) {
74  0 throw new RuntimeException(e);
75    }
76    }
77   
 
78  17 toggle public static InternalServiceCall createServiceCall(final String name, final KernelQedeqBo prop)
79    throws InterruptException {
80  17 InternalServiceProcess process = getInternalServices().createServiceProcess(name);
81  17 InternalServiceCall call = getInternalServices().createServiceCall(DummyPlugin.getInstance(), prop,
82    Parameters.EMPTY, Parameters.EMPTY, process, null);
83  17 return call;
84    }
85   
 
86  17 toggle public static void endServiceCall(final InternalServiceCall call) {
87  17 if (call == null) {
88  0 return;
89    }
90  17 try {
91  17 ((ServiceProcessManager) YodaUtility.getFieldValue(getInternalServices(), "processManager"))
92    .endServiceCall(call);
93    } catch (NoSuchFieldException e) {
94  0 e.printStackTrace();
95  0 throw new RuntimeException(e);
96    }
97    }
98   
99    /**
100    * Create {@link QedeqBo} out of an {@link Qedeq} instance.
101    * During that procedure some basic checking is done. E.g. the uniqueness of entries
102    * is tested.
103    * The resulting business object has no references to the original
104    * {@link Qedeq} instance.
105    * <p>
106    * During the creation process the caller must assert that no modifications are made
107    * to the {@link Qedeq} instance including its referenced objects.
108    *
109    * @param prop Module informations.
110    * @param original Basic qedeq module object.
111    */
 
112  17 toggle public static void createQedeq(final DefaultKernelQedeqBo prop,
113    final Qedeq original) throws SourceFileExceptionList, InterruptException {
114  17 final QedeqBoFactoryAssert creator = new QedeqBoFactoryAssert(prop.getModuleAddress());
115  17 final QedeqVo vo;
116  17 try {
117  17 vo = creator.create(original);
118    } catch (ModuleDataException e) {
119  0 final SourceFileExceptionList xl
120    = prop.createSourceFileExceptionList(DummyPlugin.getInstance(), e, original);
121  0 prop.setLoadingFailureState(LoadingState.STATE_LOADING_INTO_MEMORY_FAILED, xl);
122  0 throw xl;
123    }
124  17 final QedeqFileDao loader = new XmlQedeqFileDao();
125  17 loader.setServices(getInternalServices());
126  17 prop.setQedeqFileDao(loader);
127  17 prop.setQedeqVo(vo);
128  17 final ModuleLabelsCreator mc = new ModuleLabelsCreator(DummyPlugin.getInstance(),
129    prop);
130  17 InternalServiceCall call = null;
131  17 try {
132  17 call = createServiceCall("createQedeq", prop);
133  17 mc.createLabels(call.getInternalServiceProcess());
134    } finally {
135  17 endServiceCall(call);
136    }
137  16 prop.setLoaded(vo, mc.getLabels(), mc.getConverter(), mc.getTextConverter());
138  16 KernelFacade.getKernelContext().loadRequiredModules(prop.getModuleAddress());
139  16 KernelFacade.getKernelContext().checkWellFormedness(prop.getModuleAddress());
140  16 if (!prop.isWellFormed()) {
141  0 throw prop.getErrors();
142    }
143  16 QedeqBoDuplicateLanguageChecker.check(call);
144    }
145   
146    /**
147    * Set location information where we are within the module.
148    *
149    * @param locationWithinModule Location within module.
150    */
 
151  58530 toggle protected void setLocationWithinModule(final String locationWithinModule) {
152  58530 Trace.param(CLASS, "setLocationWithinModule(String)",
153    "locationWithinModule > ", locationWithinModule);
154  58530 getCurrentContext().setLocationWithinModule(locationWithinModule);
155   
156  58530 try {
157  58530 DynamicGetter.get(getQedeqOriginal(), getCurrentContext().getLocationWithinModule());
158    } catch (RuntimeException e) {
159  0 System.err.println(getCurrentContext().getLocationWithinModule());
160  0 throw e;
161    } catch (IllegalAccessException e) {
162  0 throw new RuntimeException(e);
163    } catch (InvocationTargetException e) {
164  0 throw new RuntimeException(e);
165    }
166   
167  58530 SimpleXPath xpath;
168  58530 try {
169  58530 xpath = Context2SimpleXPath.getXPath(getCurrentContext(), getQedeqOriginal());
170    } catch (ModuleDataException e) {
171  0 throw new RuntimeException(e);
172    }
173  58530 Trace.param(CLASS, "setLocationWithinModule(String)",
174    "xpath < ", xpath);
175  58530 InternalKernelServices services;
176  58530 try {
177  58530 services = (InternalKernelServices) YodaUtility
178    .getFieldValue(KernelFacade.getKernelContext(), "services");
179    } catch (NoSuchFieldException e) {
180  0 throw new RuntimeException(e);
181    }
182  58530 final SourceArea find = XPathLocationParser.findSourceArea(
183    services.getLocalFilePath(
184    getCurrentContext().getModuleLocation()), xpath);
185  58530 if (find.getStartPosition() == null) {
186  0 System.out.println(getCurrentContext());
187  0 throw new RuntimeException("start not found: " + find + "\ncontext: "
188    + getCurrentContext().getLocationWithinModule());
189    }
190  58530 if (find.getEndPosition() == null) {
191  0 System.out.println(getCurrentContext());
192  0 throw new RuntimeException("end not found: " + find + "\ncontext: "
193    + getCurrentContext().getLocationWithinModule());
194    }
195    }
196    }