Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: So Sep 2 2007 02:40:58 CEST
file stats: LOC: 942   Methods: 41
NCLOC: 767   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
QedeqBoFactory.java 66,7% 89,3% 100% 82,7%
coverage coverage
 1    /* $Id: QedeqBoFactory.java,v 1.4 2007/08/21 21:03:30 m31 Exp $
 2    *
 3    * This file is part of the project "Hilbert II" - http://www.qedeq.org
 4    *
 5    * Copyright 2000-2007, 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.load;
 19   
 20    import org.qedeq.kernel.base.list.Atom;
 21    import org.qedeq.kernel.base.list.Element;
 22    import org.qedeq.kernel.base.list.ElementList;
 23    import org.qedeq.kernel.base.module.Author;
 24    import org.qedeq.kernel.base.module.AuthorList;
 25    import org.qedeq.kernel.base.module.Axiom;
 26    import org.qedeq.kernel.base.module.Chapter;
 27    import org.qedeq.kernel.base.module.ChapterList;
 28    import org.qedeq.kernel.base.module.Formula;
 29    import org.qedeq.kernel.base.module.FunctionDefinition;
 30    import org.qedeq.kernel.base.module.Header;
 31    import org.qedeq.kernel.base.module.Import;
 32    import org.qedeq.kernel.base.module.ImportList;
 33    import org.qedeq.kernel.base.module.Latex;
 34    import org.qedeq.kernel.base.module.LatexList;
 35    import org.qedeq.kernel.base.module.LinkList;
 36    import org.qedeq.kernel.base.module.LiteratureItem;
 37    import org.qedeq.kernel.base.module.LiteratureItemList;
 38    import org.qedeq.kernel.base.module.Location;
 39    import org.qedeq.kernel.base.module.LocationList;
 40    import org.qedeq.kernel.base.module.Node;
 41    import org.qedeq.kernel.base.module.PredicateDefinition;
 42    import org.qedeq.kernel.base.module.Proof;
 43    import org.qedeq.kernel.base.module.ProofList;
 44    import org.qedeq.kernel.base.module.Proposition;
 45    import org.qedeq.kernel.base.module.Qedeq;
 46    import org.qedeq.kernel.base.module.Rule;
 47    import org.qedeq.kernel.base.module.Section;
 48    import org.qedeq.kernel.base.module.SectionList;
 49    import org.qedeq.kernel.base.module.Specification;
 50    import org.qedeq.kernel.base.module.Subsection;
 51    import org.qedeq.kernel.base.module.SubsectionList;
 52    import org.qedeq.kernel.base.module.Term;
 53    import org.qedeq.kernel.base.module.UsedByList;
 54    import org.qedeq.kernel.base.module.VariableList;
 55    import org.qedeq.kernel.bo.control.QedeqBoDuplicateLanguageChecker;
 56    import org.qedeq.kernel.bo.control.QedeqBoFormalLogicChecker;
 57    import org.qedeq.kernel.bo.module.IllegalModuleDataException;
 58    import org.qedeq.kernel.bo.module.ModuleContext;
 59    import org.qedeq.kernel.bo.module.ModuleDataException;
 60    import org.qedeq.kernel.bo.module.QedeqBo;
 61    import org.qedeq.kernel.dto.list.DefaultAtom;
 62    import org.qedeq.kernel.dto.list.DefaultElementList;
 63    import org.qedeq.kernel.dto.module.AuthorListVo;
 64    import org.qedeq.kernel.dto.module.AuthorVo;
 65    import org.qedeq.kernel.dto.module.AxiomVo;
 66    import org.qedeq.kernel.dto.module.ChapterListVo;
 67    import org.qedeq.kernel.dto.module.ChapterVo;
 68    import org.qedeq.kernel.dto.module.FormulaVo;
 69    import org.qedeq.kernel.dto.module.FunctionDefinitionVo;
 70    import org.qedeq.kernel.dto.module.HeaderVo;
 71    import org.qedeq.kernel.dto.module.ImportListVo;
 72    import org.qedeq.kernel.dto.module.ImportVo;
 73    import org.qedeq.kernel.dto.module.LatexListVo;
 74    import org.qedeq.kernel.dto.module.LatexVo;
 75    import org.qedeq.kernel.dto.module.LinkListVo;
 76    import org.qedeq.kernel.dto.module.LiteratureItemListVo;
 77    import org.qedeq.kernel.dto.module.LiteratureItemVo;
 78    import org.qedeq.kernel.dto.module.LocationListVo;
 79    import org.qedeq.kernel.dto.module.LocationVo;
 80    import org.qedeq.kernel.dto.module.NodeVo;
 81    import org.qedeq.kernel.dto.module.PredicateDefinitionVo;
 82    import org.qedeq.kernel.dto.module.ProofListVo;
 83    import org.qedeq.kernel.dto.module.ProofVo;
 84    import org.qedeq.kernel.dto.module.PropositionVo;
 85    import org.qedeq.kernel.dto.module.RuleVo;
 86    import org.qedeq.kernel.dto.module.SectionListVo;
 87    import org.qedeq.kernel.dto.module.SectionVo;
 88    import org.qedeq.kernel.dto.module.SpecificationVo;
 89    import org.qedeq.kernel.dto.module.SubsectionListVo;
 90    import org.qedeq.kernel.dto.module.SubsectionVo;
 91    import org.qedeq.kernel.dto.module.TermVo;
 92    import org.qedeq.kernel.dto.module.UsedByListVo;
 93    import org.qedeq.kernel.dto.module.VariableListVo;
 94   
 95   
 96    /**
 97    * An factory for creating {@link org.qedeq.kernel.bo.load.DefaultQedeqBo}s. This factory takes
 98    * something that implements the QEDEQ interfaces (beginning with
 99    * (@link org.qedeq.kernel.base.module.Qedeq} and makes copies that are out of the package
 100    * <code>org.qedeq.kernel.dto.*</code>. Only elements that are not <code>null</code> are
 101    * copied.
 102    *
 103    * <p>
 104    * LATER mime 20050707: use director pattern or transfer creation methods
 105    * into BOs or use visitor pattern
 106    *
 107    * @version $Revision: 1.4 $
 108    * @author Michael Meyling
 109    */
 110    public class QedeqBoFactory {
 111   
 112    /** QEDEQ module business object. */
 113    private DefaultQedeqBo qedeq;
 114   
 115    /** QEDEQ module input object. */
 116    private Qedeq original;
 117   
 118    /** Current context during creation. */
 119    private ModuleContext currentContext;
 120   
 121    /**
 122    * Constructor.
 123    *
 124    * @param globalContext Module location information.
 125    */
 126  41 protected QedeqBoFactory(final String globalContext) {
 127  41 currentContext = new ModuleContext(globalContext);
 128    }
 129   
 130    /**
 131    * Create {@link DefaultQedeqBo} out of an {@link Qedeq} instance.
 132    * During that procedure some basic checking is done. E.g. the uniqueness of entries
 133    * is tested. The resulting business object has no references to the original
 134    * {@link Qedeq} instance.
 135    * <p>
 136    * During the creation process the caller must assert that no modifications are made
 137    * to the {@link Qedeq} instance including its referenced objects.
 138    *
 139    * @param globalContext Module location information.
 140    * @param original Basic QEDEQ module object.
 141    * @return Filled QEDEQ business object. Is equal to the parameter <code>qedeq</code>.
 142    * @throws ModuleDataException Invalid data found.
 143    */
 144  30 public static DefaultQedeqBo createQedeq(final String globalContext, final Qedeq original)
 145    throws ModuleDataException {
 146  30 final QedeqBoFactory creator = new QedeqBoFactory(globalContext);
 147  30 DefaultQedeqBo bo = creator.create(original);
 148   
 149    // FIXME mime 20070325: just for testing purpose the following two checks are
 150    // integrated here in the BO creation. The checking results should be maintained
 151    // later on as additional information to a module (e.g. globalContext?).
 152    // QedeqBoFormalLogicChecker.check(globalContext, bo);
 153  28 QedeqBoDuplicateLanguageChecker.check(globalContext, bo);
 154  26 return bo;
 155    }
 156   
 157    /**
 158    * Create {@link DefaultQedeqBo} out of an {@link Qedeq} instance.
 159    * During that procedure some basic checking is done. E.g. the uniqueness of entries
 160    * is tested. The resulting business object has no references to the original
 161    * {@link Qedeq} instance.
 162    *
 163    * <p>
 164    * During the creation process the caller must assert that no modifications are made
 165    * to the {@link Qedeq} instance including its referenced objects.
 166    *
 167    * @param original Basic QEDEQ module object.
 168    * @return Filled header business object. Is equal to the parameter <code>header</code>.
 169    * @throws IllegalModuleDataException Basic semantic error occurred.
 170    */
 171  41 protected final DefaultQedeqBo create(final Qedeq original) throws IllegalModuleDataException {
 172  41 this.original = original;
 173  41 getCurrentContext().setLocationWithinModule("");
 174  41 if (original == null) {
 175  0 qedeq = null;
 176  0 return qedeq;
 177    }
 178  41 qedeq = new DefaultQedeqBo();
 179  41 final String context = getCurrentContext().getLocationWithinModule();
 180  41 if (original.getHeader() != null) {
 181  41 getCurrentContext().setLocationWithinModule(context + "getHeader()");
 182  41 qedeq.setHeader(create(original.getHeader()));
 183    }
 184  41 if (original.getChapterList() != null) {
 185  41 getCurrentContext().setLocationWithinModule(context + "getChapterList()");
 186  41 qedeq.setChapterList(create(original.getChapterList()));
 187    }
 188  38 if (original.getLiteratureItemList() != null) {
 189  9 getCurrentContext().setLocationWithinModule(context + "getLiteratureItemList()");
 190  9 qedeq.setLiteratureItemList(create(original.getLiteratureItemList()));
 191    }
 192  38 return qedeq;
 193    }
 194   
 195    /**
 196    * Create {@link HeaderVo} out of an {@link Header} instance.
 197    * During that procedure some basic checking is done. E.g. the uniqueness of entries
 198    * is tested. The resulting business object has no references to the original
 199    * {@link Header} instance.
 200    * <p>
 201    * During the creation process the caller must assert that no modifications are made
 202    * to the {@link Header} instance including its referenced objects.
 203    *
 204    * @param header Basic header object.
 205    * @return Filled header business object. Is equal to the parameter <code>header</code>.
 206    * @throws IllegalModuleDataException Basic semantic error occurred.
 207    */
 208  41 private final HeaderVo create(final Header header)
 209    throws IllegalModuleDataException {
 210  41 if (header == null) {
 211  0 return null;
 212    }
 213  41 final HeaderVo h = new HeaderVo();
 214  41 final String context = getCurrentContext().getLocationWithinModule();
 215  41 if (header.getTitle() != null) {
 216  41 setLocationWithinModule(context + ".getTitle()");
 217  41 h.setTitle(create(header.getTitle()));
 218    }
 219  41 if (header.getAuthorList() != null) {
 220  41 setLocationWithinModule(context + ".getAuthorList()");
 221  41 h.setAuthorList(create(header.getAuthorList()));
 222    }
 223  41 if (header.getSummary() != null) {
 224  41 setLocationWithinModule(context + ".getSummary()");
 225  41 h.setSummary(create(header.getSummary()));
 226    }
 227  41 if (header.getEmail() != null) {
 228  41 setLocationWithinModule(context + ".getEmail()");
 229  41 h.setEmail(header.getEmail());
 230    }
 231  41 if (header.getSpecification() != null) {
 232  41 setLocationWithinModule(context + ".getSpecification()");
 233  41 h.setSpecification(create(header.getSpecification()));
 234    }
 235  41 if (header.getImportList() != null) {
 236  20 setLocationWithinModule(context + ".getImportList()");
 237  20 h.setImportList(create(header.getImportList()));
 238    }
 239  41 if (header.getUsedByList() != null) {
 240  17 setLocationWithinModule(context + ".getUsedByList()");
 241  17 h.setUsedByList(create(header.getUsedByList()));
 242    }
 243  41 setLocationWithinModule(context);
 244  41 return h;
 245    }
 246   
 247    /**
 248    * Create {@link UsedByListVo} out of an {@link UsedByList} instance.
 249    * During that procedure some basic checking is done. E.g. the uniqueness of entries
 250    * is tested. The resulting business object has no references to the original
 251    * {@link UsedByList} instance.
 252    * <p>
 253    * During the creation process the caller must assert that no modifications are made
 254    * to the {@link UsedByList} instance including its referenced objects.
 255    *
 256    * @param usedByList Basic header object.
 257    * @return Filled used by business object. Is equal to the parameter <code>usedByList</code>.
 258    */
 259  17 private final UsedByListVo create(final UsedByList usedByList) {
 260  17 if (usedByList == null) {
 261  0 return null;
 262    }
 263  17 final String context = getCurrentContext().getLocationWithinModule();
 264  17 final UsedByListVo list = new UsedByListVo();
 265  17 for (int i = 0; i < usedByList.size(); i++) {
 266  17 setLocationWithinModule(context + ".get(" + i + ")");
 267  17 list.add(create(usedByList.get(i)));
 268    }
 269  17 setLocationWithinModule(context);
 270  17 return list;
 271    }
 272   
 273  20 private final ImportListVo create(final ImportList importList) {
 274  20 if (importList == null) {
 275  0 return null;
 276    }
 277  20 final String context = getCurrentContext().getLocationWithinModule();
 278  20 final ImportListVo list = new ImportListVo();
 279  20 for (int i = 0; i < importList.size(); i++) {
 280  34 setLocationWithinModule(context + ".get(" + i + ")");
 281  34 list.add(create(importList.get(i)));
 282    }
 283  20 setLocationWithinModule(context);
 284  20 return list;
 285    }
 286   
 287  34 private final ImportVo create(final Import imp) {
 288  34 if (imp == null) {
 289  0 return null;
 290    }
 291  34 final ImportVo i = new ImportVo();
 292  34 final String context = getCurrentContext().getLocationWithinModule();
 293  34 if (imp.getLabel() != null) {
 294  34 setLocationWithinModule(context + ".getLabel()");
 295  34 i.setLabel(imp.getLabel());
 296    }
 297  34 if (imp.getSpecification() != null) {
 298  34 setLocationWithinModule(context + ".getSpecification()");
 299  34 i.setSpecification(create(imp.getSpecification()));
 300    }
 301  34 setLocationWithinModule(context);
 302  34 return i;
 303    }
 304   
 305  92 private final SpecificationVo create(final Specification specification) {
 306  92 if (specification == null) {
 307  0 return null;
 308    }
 309  92 final SpecificationVo s = new SpecificationVo();
 310  92 final String context = getCurrentContext().getLocationWithinModule();
 311  92 if (specification.getName() != null) {
 312  92 setLocationWithinModule(context + ".getName()");
 313  92 s.setName(specification.getName());
 314    }
 315  92 if (specification.getRuleVersion() != null) {
 316  92 setLocationWithinModule(context + ".getRuleVersion()");
 317  92 s.setRuleVersion(specification.getRuleVersion());
 318    }
 319  92 if (specification.getLocationList() != null) {
 320  92 setLocationWithinModule(context + ".getLocationList()");
 321  92 s.setLocationList(create(specification.getLocationList()));
 322    }
 323  92 setLocationWithinModule(context);
 324  92 return s;
 325    }
 326   
 327  92 private final LocationListVo create(final LocationList locationList) {
 328  92 if (locationList == null) {
 329  0 return null;
 330    }
 331  92 final LocationListVo list = new LocationListVo();
 332  92 final String context = getCurrentContext().getLocationWithinModule();
 333  92 for (int i = 0; i < locationList.size(); i++) {
 334  92 setLocationWithinModule(context + ".get(" + i + ")");
 335  92 list.add(create(locationList.get(i)));
 336    }
 337  92 setLocationWithinModule(context);
 338  92 return list;
 339    }
 340   
 341  92 private final LocationVo create(final Location location) {
 342  92 if (location == null) {
 343  0 return null;
 344    }
 345  92 final LocationVo loc = new LocationVo();
 346  92 final String context = getCurrentContext().getLocationWithinModule();
 347  92 if (location.getLocation() != null) {
 348  92 setLocationWithinModule(context + ".getLocation()");
 349  92 loc.setLocation(location.getLocation());
 350    }
 351  92 setLocationWithinModule(context);
 352  92 return loc;
 353    }
 354   
 355  41 private final AuthorListVo create(final AuthorList authorList) {
 356  41 if (authorList == null) {
 357  0 return null;
 358    }
 359  41 final AuthorListVo list = new AuthorListVo();
 360  41 final String context = getCurrentContext().getLocationWithinModule();
 361  41 for (int i = 0; i < authorList.size(); i++) {
 362  41 setLocationWithinModule(context + ".get(" + i + ")");
 363  41 list.add(create(authorList.get(i)));
 364    }
 365  41 setLocationWithinModule(context);
 366  41 return list;
 367    }
 368   
 369  41 private final AuthorVo create(final Author author) {
 370  41 if (author == null) {
 371  0 return null;
 372    }
 373  41 final AuthorVo a = new AuthorVo();
 374  41 final String context = getCurrentContext().getLocationWithinModule();
 375  41 if (author.getName() != null) {
 376  41 setLocationWithinModule(context + ".getName()");
 377  41 a.setName(create(author.getName()));
 378    }
 379  41 if (author.getEmail() != null) {
 380  41 setLocationWithinModule(context + ".getEmail()");
 381  41 a.setEmail(author.getEmail());
 382    }
 383  41 setLocationWithinModule(context);
 384  41 return a;
 385    }
 386   
 387  41 private final ChapterListVo create(final ChapterList chapterList)
 388    throws IllegalModuleDataException {
 389  41 if (chapterList == null) {
 390  0 return null;
 391    }
 392  41 final ChapterListVo list = new ChapterListVo();
 393  41 final String context = getCurrentContext().getLocationWithinModule();
 394  41 for (int i = 0; i < chapterList.size(); i++) {
 395  140 setLocationWithinModule(context + ".get(" + i + ")");
 396  140 list.add(create(chapterList.get(i)));
 397    }
 398  38 setLocationWithinModule(context);
 399  38 return list;
 400    }
 401   
 402  140 private final ChapterVo create(final Chapter chapter)
 403    throws IllegalModuleDataException {
 404  140 if (chapter == null) {
 405  0 return null;
 406    }
 407  140 final ChapterVo c = new ChapterVo();
 408  140 final String context = getCurrentContext().getLocationWithinModule();
 409  140 if (chapter.getTitle() != null) {
 410  140 setLocationWithinModule(context + ".getTitle()");
 411  140 c.setTitle(create(chapter.getTitle()));
 412    }
 413  140 if (chapter.getNoNumber() != null) {
 414  45 setLocationWithinModule(context + ".getNoNumber()");
 415  45 c.setNoNumber(chapter.getNoNumber());
 416    }
 417  140 if (chapter.getIntroduction() != null) {
 418  131 setLocationWithinModule(context + ".getIntroduction()");
 419  131 c.setIntroduction(create(chapter.getIntroduction()));
 420    }
 421  140 if (chapter.getSectionList() != null) {
 422  92 setLocationWithinModule(context + ".getSectionList()");
 423  92 c.setSectionList(create(chapter.getSectionList()));
 424    }
 425  137 setLocationWithinModule(context);
 426  137 return c;
 427    }
 428   
 429  9 private LiteratureItemListVo create(final LiteratureItemList literatureItemList)
 430    throws IllegalModuleDataException {
 431  9 if (literatureItemList == null) {
 432  0 return null;
 433    }
 434  9 final LiteratureItemListVo list = new LiteratureItemListVo();
 435  9 final String context = getCurrentContext().getLocationWithinModule();
 436  9 for (int i = 0; i < literatureItemList.size(); i++) {
 437  39 setLocationWithinModule(context + ".get(" + i + ")");
 438