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