Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Do Mai 10 2007 03:16:40 CEST
file stats: LOC: 942   Methods: 41
NCLOC: 768   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.2 2007/05/10 00:37:51 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.2 $
 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  28 protected QedeqBoFactory(final String globalContext) {
 127  28 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  17 public static DefaultQedeqBo createQedeq(final String globalContext, final Qedeq original)
 145    throws ModuleDataException {
 146  17 final QedeqBoFactory creator = new QedeqBoFactory(globalContext);
 147  17 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  16 QedeqBoFormalLogicChecker.check(globalContext, bo);
 153  10 QedeqBoDuplicateLanguageChecker.check(globalContext, bo);
 154  9 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  28 protected final DefaultQedeqBo create(final Qedeq original) throws IllegalModuleDataException {
 172  28 this.original = original;
 173  28 getCurrentContext().setLocationWithinModule("");
 174  28 if (original == null) {
 175  0 qedeq = null;
 176  0 return qedeq;
 177    }
 178  28 qedeq = new DefaultQedeqBo();
 179  28 final String context = getCurrentContext().getLocationWithinModule();
 180  28 if (original.getHeader() != null) {
 181  28 getCurrentContext().setLocationWithinModule(context + "getHeader()");
 182  28 qedeq.setHeader(create(original.getHeader()));
 183    }
 184  28 if (original.getChapterList() != null) {
 185  28 getCurrentContext().setLocationWithinModule(context + "getChapterList()");
 186  28 qedeq.setChapterList(create(original.getChapterList()));
 187    }
 188  26 if (original.getLiteratureItemList() != null) {
 189  9 getCurrentContext().setLocationWithinModule(context + "getLiteratureItemList()");
 190  9 qedeq.setLiteratureItemList(create(original.getLiteratureItemList()));
 191    }
 192  26 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  28 private final HeaderVo create(final Header header)
 209    throws IllegalModuleDataException {
 210  28 if (header == null) {
 211  0 return null;
 212    }
 213  28 final HeaderVo h = new HeaderVo();
 214  28 final String context = getCurrentContext().getLocationWithinModule();
 215  28 if (header.getTitle() != null) {
 216  28 setLocationWithinModule(context + ".getTitle()");
 217  28 h.setTitle(create(header.getTitle()));
 218    }
 219  28 if (header.getAuthorList() != null) {
 220  28 setLocationWithinModule(context + ".getAuthorList()");
 221  28 h.setAuthorList(create(header.getAuthorList()));
 222    }
 223  28 if (header.getSummary() != null) {
 224  28 setLocationWithinModule(context + ".getSummary()");
 225  28 h.setSummary(create(header.getSummary()));
 226    }
 227  28 if (header.getEmail() != null) {
 228  28 setLocationWithinModule(context + ".getEmail()");
 229  28 h.setEmail(header.getEmail());
 230    }
 231  28 if (header.getSpecification() != null) {
 232  28 setLocationWithinModule(context + ".getSpecification()");
 233  28 h.setSpecification(create(header.getSpecification()));
 234    }
 235  28 if (header.getImportList() != null) {
 236  15 setLocationWithinModule(context + ".getImportList()");
 237  15 h.setImportList(create(header.getImportList()));
 238    }
 239  28 if (header.getUsedByList() != null) {
 240  12 setLocationWithinModule(context + ".getUsedByList()");
 241  12 h.setUsedByList(create(header.getUsedByList()));
 242    }
 243  28 setLocationWithinModule(context);
 244  28 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  12 private final UsedByListVo create(final UsedByList usedByList) {
 260  12 if (usedByList == null) {
 261  0 return null;
 262    }
 263  12 final String context = getCurrentContext().getLocationWithinModule();
 264  12 final UsedByListVo list = new UsedByListVo();
 265  12 for (int i = 0; i < usedByList.size(); i++) {
 266  12 setLocationWithinModule(context + ".get(" + i + ")");
 267  12 list.add(create(usedByList.get(i)));
 268    }
 269  12 setLocationWithinModule(context);
 270  12 return list;
 271    }
 272   
 273  15 private final ImportListVo create(final ImportList importList) {
 274  15 if (importList == null) {
 275  0 return null;
 276    }
 277  15 final String context = getCurrentContext().getLocationWithinModule();
 278  15 final ImportListVo list = new ImportListVo();
 279  15 for (int i = 0; i < importList.size(); i++) {
 280  24 setLocationWithinModule(context + ".get(" + i + ")");
 281  24 list.add(create(importList.get(i)));
 282    }
 283  15 setLocationWithinModule(context);
 284  15 return list;
 285    }
 286   
 287  24 private final ImportVo create(final Import imp) {
 288  24 if (imp == null) {
 289  0 return null;
 290    }
 291  24 final ImportVo i = new ImportVo();
 292  24 final String context = getCurrentContext().getLocationWithinModule();
 293  24 if (imp.getLabel() != null) {
 294  24 setLocationWithinModule(context + ".getLabel()");
 295  24 i.setLabel(imp.getLabel());
 296    }
 297  24 if (imp.getSpecification() != null) {
 298  24 setLocationWithinModule(context + ".getSpecification()");
 299  24 i.setSpecification(create(imp.getSpecification()));
 300    }
 301  24 setLocationWithinModule(context);
 302  24 return i;
 303    }
 304   
 305  64 private final SpecificationVo create(final Specification specification) {
 306  64 if (specification == null) {
 307  0 return null;
 308    }
 309  64 final SpecificationVo s = new SpecificationVo();
 310  64 final String context = getCurrentContext().getLocationWithinModule();
 311  64 if (specification.getName() != null) {
 312  64 setLocationWithinModule(context + ".getName()");
 313  64 s.setName(specification.getName());
 314    }
 315  64 if (specification.getRuleVersion() != null) {
 316  64 setLocationWithinModule(context + ".getRuleVersion()");
 317  64 s.setRuleVersion(specification.getRuleVersion());
 318    }
 319  64 if (specification.getLocationList() != null) {
 320  64 setLocationWithinModule(context + ".getLocationList()");
 321  64 s.setLocationList(create(specification.getLocationList()));
 322    }
 323  64 setLocationWithinModule(context);
 324  64 return s;
 325    }
 326   
 327  64 private final LocationListVo create(final LocationList locationList) {
 328  64 if (locationList == null) {
 329  0 return null;
 330    }
 331  64 final LocationListVo list = new LocationListVo();
 332  64 final String context = getCurrentContext().getLocationWithinModule();
 333  64 for (int i = 0; i < locationList.size(); i++) {
 334  64 setLocationWithinModule(context + ".get(" + i + ")");
 335  64 list.add(create(locationList.get(i)));
 336    }
 337  64 setLocationWithinModule(context);
 338  64 return list;
 339    }
 340   
 341  64 private final LocationVo create(final Location location) {
 342  64 if (location == null) {
 343  0 return null;
 344    }
 345  64 final LocationVo loc = new LocationVo();
 346  64 final String context = getCurrentContext().getLocationWithinModule();
 347  64 if (location.getLocation() != null) {
 348  64 setLocationWithinModule(context + ".getLocation()");
 349  64 loc.setLocation(location.getLocation());
 350    }
 351  64 setLocationWithinModule(context);
 352  64 return loc;
 353    }
 354   
 355  28 private final AuthorListVo create(final AuthorList authorList) {
 356  28 if (authorList == null) {
 357  0 return null;
 358    }
 359  28 final AuthorListVo list = new AuthorListVo();
 360  28 final String context = getCurrentContext().getLocationWithinModule();
 361  28 for (int i = 0; i < authorList.size(); i++) {
 362  28 setLocationWithinModule(context + ".get(" + i + ")");
 363  28 list.add(create(authorList.get(i)));
 364    }
 365  28 setLocationWithinModule(context);
 366  28 return list;
 367    }
 368   
 369  28 private final AuthorVo create(final Author author) {
 370  28 if (author == null) {
 371  0 return null;
 372    }
 373  28 final AuthorVo a = new AuthorVo();
 374  28 final String context = getCurrentContext().getLocationWithinModule();
 375  28 if (author.getName() != null) {
 376  28 setLocationWithinModule(context + ".getName()");
 377  28 a.setName(create(author.getName()));
 378    }
 379  28 if (author.getEmail() != null) {
 380  28 setLocationWithinModule(context + ".getEmail()");
 381  28 a.setEmail(author.getEmail());
 382    }
 383  28 setLocationWithinModule(context);
 384  28 return a;
 385    }
 386   
 387  28 private final ChapterListVo create(final ChapterList chapterList)
 388    throws IllegalModuleDataException {
 389  28 if (chapterList == null) {
 390  0 return null;
 391    }
 392  28 final ChapterListVo list = new ChapterListVo();
 393  28 final String context = getCurrentContext().getLocationWithinModule();
 394  28 for (int i = 0; i < chapterList.size(); i++) {
 395  121 setLocationWithinModule(context + ".get(" + i + ")");
 396  121 list.add(create(chapterList.get(i)));
 397    }
 398  26 setLocationWithinModule(context);
 399  26 return list;
 400    }
 401   
 402  121 private final ChapterVo create(final Chapter chapter)
 403    throws IllegalModuleDataException {
 404  121 if (chapter == null) {
 405  0 return null;
 406    }
 407  121 final ChapterVo c = new ChapterVo();
 408  121 final String context = getCurrentContext().getLocationWithinModule();
 409  121 if (chapter.getTitle() != null) {
 410  121 setLocationWithinModule(context + ".getTitle()");
 411  121 c.setTitle(create(chapter.getTitle()));
 412    }
 413  121 if (chapter.getNoNumber() != null) {
 414  38 setLocationWithinModule(context + ".getNoNumber()");
 415  38 c.setNoNumber(chapter.getNoNumber());
 416    }
 417  121 if (chapter.getIntroduction() != null) {
 418  118 setLocationWithinModule(context + ".getIntroduction()");
 419  118 c.setIntroduction(create(chapter.getIntroduction()));
 420    }
 421  121 if (chapter.getSectionList() != null) {
 422  75 setLocationWithinModule(context + ".getSectionList()");
 423  75 c.setSectionList(create(chapter.getSectionList()));
 424    }
 425  119 setLocationWithinModule(context);
 426  119 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 + ")");