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