Clover Coverage Report
Coverage timestamp: Sa Aug 2 2008 13:56:27 CEST
../../../../../img/srcFileCovDistChart7.png 62% of files have more coverage
44   163   14   14,67
6   104   0,32   3
3     4,67  
1    
 
  QedeqBoFactoryAssert       Line # 53 44 14 64,2% 0.6415094
 
  (8)
 
1    /* $Id: QedeqBoFactoryAssert.java,v 1.1 2008/07/26 07:59:15 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.control;
19   
20    import java.io.IOException;
21    import java.lang.reflect.InvocationTargetException;
22   
23    import javax.xml.parsers.ParserConfigurationException;
24   
25    import org.qedeq.base.io.IoUtility;
26    import org.qedeq.base.test.DynamicGetter;
27    import org.qedeq.base.trace.Trace;
28    import org.qedeq.kernel.base.module.Qedeq;
29    import org.qedeq.kernel.bo.module.InternalKernelServices;
30    import org.qedeq.kernel.bo.module.QedeqFileDao;
31    import org.qedeq.kernel.bo.service.DefaultKernelQedeqBo;
32    import org.qedeq.kernel.bo.service.ModuleLabelsCreator;
33    import org.qedeq.kernel.bo.service.QedeqVoBuilder;
34    import org.qedeq.kernel.bo.service.latex.QedeqBoDuplicateLanguageChecker;
35    import org.qedeq.kernel.bo.test.KernelFacade;
36    import org.qedeq.kernel.common.LoadingState;
37    import org.qedeq.kernel.common.ModuleAddress;
38    import org.qedeq.kernel.common.ModuleDataException;
39    import org.qedeq.kernel.common.SourceFileExceptionList;
40    import org.qedeq.kernel.dto.module.QedeqVo;
41    import org.qedeq.kernel.xml.dao.XmlQedeqFileDao;
42    import org.qedeq.kernel.xml.mapper.Context2SimpleXPath;
43    import org.qedeq.kernel.xml.tracker.SimpleXPath;
44    import org.qedeq.kernel.xml.tracker.XPathLocationParser;
45    import org.xml.sax.SAXException;
46   
47    /**
48    * For testing QEDEQ BO generation.
49    *
50    * @version $Revision: 1.1 $
51    * @author Michael Meyling
52    */
 
53    public class QedeqBoFactoryAssert extends QedeqVoBuilder {
54   
55    /** This class. */
56    private static final Class CLASS = QedeqBoFactoryAssert.class;
57   
58    /**
59    * Constructor.
60    *
61    * @param address QEDEQ module address.
62    */
 
63  11 toggle public QedeqBoFactoryAssert(final ModuleAddress address) {
64  11 super(address);
65    }
66   
67    /**
68    * Create {@link QedeqBo} out of an {@link Qedeq} instance.
69    * During that procedure some basic checking is done. E.g. the uniqueness of entries
70    * is tested.
71    * The resulting business object has no references to the original
72    * {@link Qedeq} instance.
73    * <p>
74    * During the creation process the caller must assert that no modifications are made
75    * to the {@link Qedeq} instance including its referenced objects.
76    *
77    * @param prop Module informations.
78    * @param original Basic qedeq module object.
79    * @throws ModuleDataException Semantic or syntactic error occurred.
80    */
 
81  11 toggle public static void createQedeq(final DefaultKernelQedeqBo prop,
82    final Qedeq original) throws SourceFileExceptionList {
83  11 final QedeqBoFactoryAssert creator = new QedeqBoFactoryAssert(prop.getModuleAddress());
84  11 final QedeqVo vo;
85  11 try {
86  11 vo = creator.create(original);
87    } catch (ModuleDataException e) {
88  0 final SourceFileExceptionList xl
89    = prop.createSourceFileExceptionList(e, original);
90  0 prop.setLoadingFailureState(LoadingState.STATE_LOADING_INTO_MEMORY_FAILED, xl);
91  0 throw xl;
92    }
93  11 final InternalKernelServices services = (InternalKernelServices) IoUtility
94    .getFieldContent(KernelFacade.getKernelContext(), "services");
95  11 final QedeqFileDao loader = new XmlQedeqFileDao();
96  11 loader.setServices(services);
97  11 prop.setQedeqFileDao(loader);
98  11 prop.setQedeqVo(vo);
99  11 prop.setLoaded(vo, new ModuleLabelsCreator(prop).createLabels());
100  10 KernelFacade.getKernelContext().loadRequiredModules(prop.getModuleAddress());
101  10 KernelFacade.getKernelContext().checkModule(prop.getModuleAddress());
102  10 if (!prop.isChecked()) {
103  0 throw prop.getException();
104    }
105  10 QedeqBoDuplicateLanguageChecker.check(prop);
106    }
107   
108    /**
109    * Set location information where we are within the module.
110    *
111    * @param locationWithinModule Location within module.
112    */
 
113  24824 toggle protected void setLocationWithinModule(final String locationWithinModule) {
114  24824 Trace.param(CLASS, "setLocationWithinModule(String)",
115    "locationWithinModule > ", locationWithinModule);
116  24824 getCurrentContext().setLocationWithinModule(locationWithinModule);
117   
118  24824 try {
119  24824 DynamicGetter.get(getQedeqOriginal(), getCurrentContext().getLocationWithinModule());
120    } catch (RuntimeException e) {
121  0 System.err.println(getCurrentContext().getLocationWithinModule());
122  0 throw e;
123    } catch (IllegalAccessException e) {
124  0 throw new RuntimeException(e);
125    } catch (InvocationTargetException e) {
126  0 throw new RuntimeException(e);
127    }
128   
129  24824 SimpleXPath xpath;
130  24824 try {
131  24824 xpath = Context2SimpleXPath.getXPath(getCurrentContext(), getQedeqOriginal());
132    } catch (ModuleDataException e) {
133  0 throw new RuntimeException(e);
134    }
135  24824 Trace.param(CLASS, "setLocationWithinModule(String)",
136    "xpath < ", xpath);
137  24824 try {
138  24824 final InternalKernelServices services = (InternalKernelServices) IoUtility
139    .getFieldContent(KernelFacade.getKernelContext(), "services");
140  24824 final SimpleXPath find = XPathLocationParser.getXPathLocation(
141    services.getLocalFilePath(
142    getCurrentContext().getModuleLocation()), xpath,
143    getCurrentContext().getModuleLocation().getURL());
144  24824 if (find.getStartLocation() == null) {
145  0 System.out.println(getCurrentContext());
146  0 throw new RuntimeException("start not found: " + find + "\ncontext: "
147    + getCurrentContext().getLocationWithinModule());
148    }
149  24824 if (find.getEndLocation() == null) {
150  0 System.out.println(getCurrentContext());
151  0 throw new RuntimeException("end not found: " + find + "\ncontext: "
152    + getCurrentContext().getLocationWithinModule());
153    }
154   
155    } catch (ParserConfigurationException e) {
156  0 throw new RuntimeException(e);
157    } catch (SAXException e) {
158  0 throw new RuntimeException(e);
159    } catch (IOException e) {
160  0 throw new RuntimeException(e);
161    }
162    }
163    }