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