Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: So Mrz 11 2007 07:05:19 CET
file stats: LOC: 934   Methods: 41
NCLOC: 766   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
QedeqBoFactory.java 66,3% 89,3% 100% 82,6%
coverage coverage
<
 1    /* $Id: QedeqBoFactory.java,v 1.28 2007/03/11 01:19:34 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.28 $
 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  32 protected QedeqBoFactory(final String globalContext) {
 119  32 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  21 public static QedeqBo createQedeq(final String globalContext, final Qedeq original)
 137    throws ModuleDataException {
 138  21 final QedeqBoFactory creator = new QedeqBoFactory(globalContext);
 139  21 QedeqBo bo = creator.create(original);
 140   
 141    // TODO mime 20070305: just for testing purpose the following two checks are
 142    // integrated here in the BO creation. The checking results should be maintained
 143    // later on as additional information to a module (e.g. globalContext?).
 144  20 QedeqBoFormalLogicChecker.check(globalContext, bo);
 145  14 QedeqBoDuplicateLanguageChecker.check(globalContext, bo);
 146  13 return bo;
 147    }
 148   
 149    /**
 150    * Create {@link QedeqBo} out of an {@link Qedeq} instance.
 151    * During that procedure some basic checking is done. E.g. the uniqueness of entries
 152    * is tested. The resulting business object has no references to the original
 153    * {@link Qedeq} instance.
 154    * <p>
 155    * During the creation process the caller must assert that no modifications are made
 156    * to the {@link Qedeq} instance including its referenced objects.
 157    *
 158    * @param original Basic QEDEQ module object.
 159    * @return Filled header business object. Is equal to the parameter <code>header</code>.
 160    * @throws IllegalModuleDataException Basic semantic error occurred.
 161    */
 162  32 protected final QedeqBo create(final Qedeq original) throws IllegalModuleDataException {
 163  32 this.original = original;
 164  32 getCurrentContext().setLocationWithinModule("");
 165  32 if (original == null) {
 166  0 qedeq = null;
 167  0 return qedeq;
 168    }
 169  32 qedeq = new QedeqBo();
 170  32 final String context = getCurrentContext().getLocationWithinModule();
 171  32 if (original.getHeader() != null) {
 172  32 getCurrentContext().setLocationWithinModule(context + "getHeader()");
 173  32 qedeq.setHeader(create(original.getHeader()));
 174    }
 175  32 if (original.getChapterList() != null) {
 176  32 getCurrentContext().setLocationWithinModule(context + "getChapterList()");
 177  32 qedeq.setChapterList(create(original.getChapterList()));
 178    }
 179  30 if (original.getLiteratureItemList() != null) {
 180  9 getCurrentContext().setLocationWithinModule(context + "getLiteratureItemList()");
 181  9 qedeq.setLiteratureItemList(create(original.getLiteratureItemList()));
 182    }
 183  30 return qedeq;
 184    }
 185   
 186    /**
 187    * Create {@link HeaderVo} out of an {@link Header} instance.
 188    * During that procedure some basic checking is done. E.g. the uniqueness of entries
 189    * is tested. The resulting business object has no references to the original
 190    * {@link Header} instance.
 191    * <p>
 192    * During the creation process the caller must assert that no modifications are made
 193    * to the {@link Header} instance including its referenced objects.
 194    *
 195    * @param header Basic header object.
 196    * @return Filled header business object. Is equal to the parameter <code>header</code>.
 197    * @throws IllegalModuleDataException Basic semantic error occurred.
 198    */
 199  32 private final HeaderVo create(final Header header)
 200    throws IllegalModuleDataException {
 201  32 if (header == null) {
 202  0 return null;
 203    }
 204  32 final HeaderVo h = new HeaderVo();
 205  32 final String context = getCurrentContext().getLocationWithinModule();
 206  32 if (header.getTitle() != null) {
 207  32 setLocationWithinModule(context + ".getTitle()");
 208  32 h.setTitle(create(header.getTitle()));
 209    }
 210  32 if (header.getAuthorList() != null) {
 211  32 setLocationWithinModule(context + ".getAuthorList()");
 212  32 h.setAuthorList(create(header.getAuthorList()));
 213    }
 214  32 if (header.getSummary() != null) {
 215  32 setLocationWithinModule(context + ".getSummary()");
 216  32 h.setSummary(create(header.getSummary()));
 217    }
 218  32 if (header.getEmail() != null) {
 219  32 setLocationWithinModule(context + ".getEmail()");
 220  32 h.setEmail(header.getEmail());
 221    }
 222  32 if (header.getSpecification() != null) {
 223  32 setLocationWithinModule(context + ".getSpecification()");
 224  32 h.setSpecification(create(header.getSpecification()));
 225    }
 226  32 if (header.getImportList() != null) {
 227  16 setLocationWithinModule(context + ".getImportList()");
 228  16 h.setImportList(create(header.getImportList()));
 229    }
 230  32 if (header.getUsedByList() != null) {
 231  15 setLocationWithinModule(context + ".getUsedByList()");
 232  15 h.setUsedByList(create(header.getUsedByList()));
 233    }
 234  32 setLocationWithinModule(context);
 235  32 return h;
 236    }
 237   
 238    /**
 239    * Create {@link UsedByListVo} out of an {@link UsedByList} instance.
 240    * During that procedure some basic checking is done. E.g. the uniqueness of entries
 241    * is tested. The resulting business object has no references to the original
 242    * {@link UsedByList} instance.
 243    * <p>
 244    * During the creation process the caller must assert that no modifications are made
 245    * to the {@link UsedByList} instance including its referenced objects.
 246    *
 247    * @param usedByList Basic header object.
 248    * @return Filled used by business object. Is equal to the parameter <code>usedByList</code>.
 249    */
 250  15 private final UsedByListVo create(final UsedByList usedByList) {
 251  15 if (usedByList == null) {
 252  0 return null;
 253    }
 254  15 final String context = getCurrentContext().getLocationWithinModule();
 255  15 final UsedByListVo list = new UsedByListVo();
 256  15 for (int i = 0; i < usedByList.size(); i++) {
 257  15 setLocationWithinModule(context + ".get(" + i + ")");
 258  15 list.add(create(usedByList.get(i)));
 259    }
 260  15 setLocationWithinModule(context);
 261  15 return list;
 262    }
 263   
 264  16 private final ImportListVo create(final ImportList importList) {
 265  16 if (importList == null) {
 266  0 return null;
 267    }
 268  16 final String context = getCurrentContext().getLocationWithinModule();
 269  16 final ImportListVo list = new ImportListVo();
 270  16 for (int i = 0; i < importList.size(); i++) {
 271  27 setLocationWithinModule(context + ".get(" + i + ")");
 272  27 list.add(create(importList.get(i)));
 273    }
 274  16 setLocationWithinModule(context);
 275  16 return list;
 276    }
 277   
 278  27 private final ImportVo create(final Import imp) {
 279  27 if (imp == null) {
 280  0 return null;
 281    }
 282  27 final ImportVo i = new ImportVo();
 283  27 final String context = getCurrentContext().getLocationWithinModule();
 284  27 if (imp.getLabel() != null) {
 285  27 setLocationWithinModule(context + ".getLabel()");
 286  27 i.setLabel(imp.getLabel());
 287    }
 288  27 if (imp.getSpecification() != null) {
 289  27 setLocationWithinModule(context + ".getSpecification()");
 290  27 i.setSpecification(create(imp.getSpecification()));
 291    }
 292  27 setLocationWithinModule(context);
 293  27 return i;
 294    }
 295   
 296  74 private final SpecificationVo create(final Specification specification) {
 297  74 if (specification == null) {
 298  0 return null;
 299    }
 300  74 final SpecificationVo s = new SpecificationVo();
 301  74 final String context = getCurrentContext().getLocationWithinModule();
 302  74 if (specification.getName() != null) {
 303  74 setLocationWithinModule(context + ".getName()");
 304  74 s.setName(specification.getName());
 305    }
 306  74 if (specification.getRuleVersion() != null) {
 307  74 setLocationWithinModule(context + ".getRuleVersion()");
 308  74 s.setRuleVersion(specification.getRuleVersion());
 309    }
 310  74 if (specification.getLocationList() != null) {
 311  74 setLocationWithinModule(context + ".getLocationList()");
 312  74 s.setLocationList(create(specification.getLocationList()));
 313    }
 314  74 setLocationWithinModule(context);
 315  74 return s;
 316    }
 317   
 318  74 private final LocationListVo create(final LocationList locationList) {
 319  74 if (locationList == null) {
 320  0 return null;
 321    }
 322  74 final LocationListVo list = new LocationListVo();
 323  74 final String context = getCurrentContext().getLocationWithinModule();
 324  74 for (int i = 0; i < locationList.size(); i++) {
 325  74 setLocationWithinModule(context + ".get(" + i + ")");
 326  74 list.add(create(locationList.get(i)));
 327    }
 328  74 setLocationWithinModule(context);
 329  74 return list;
 330    }
 331   
 332  74 private final LocationVo create(final Location location) {
 333  74 if (location == null) {
 334  0 return null;
 335    }
 336  74 final LocationVo loc = new LocationVo();
 337  74 final String context = getCurrentContext().getLocationWithinModule();
 338  74 if (location.getLocation() != null) {
 339  74 setLocationWithinModule(context + ".getLocation()");
 340  74 loc.setLocation(location.getLocation());
 341    }
 342  74 setLocationWithinModule(context);
 343  74 return loc;
 344    }
 345   
 346  32 private final AuthorListVo create(final AuthorList authorList) {
 347  32 if (authorList == null) {
 348  0 return null;
 349    }
 350  32 final AuthorListVo list = new AuthorListVo();
 351  32 final String context = getCurrentContext().getLocationWithinModule();
 352  32 for (int i = 0; i < authorList.size(); i++) {
 353  32 setLocationWithinModule(context + ".get(" + i + ")");
 354  32 list.add(create(authorList.get(i)));
 355    }
 356  32 setLocationWithinModule(context);
 357  32 return list;
 358    }
 359   
 360  32 private final AuthorVo create(final Author author) {
 361  32 if (author == null) {
 362  0 return null;
 363    }
 364  32 final AuthorVo a = new AuthorVo();
 365  32 final String context = getCurrentContext().getLocationWithinModule();
 366  32 if (author.getName() != null) {
 367  32 setLocationWithinModule(context + ".getName()");
 368  32 a.setName(create(author.getName()));
 369    }
 370  32 if (author.getEmail() != null) {
 371  32 setLocationWithinModule(context + ".getEmail()");
 372  32 a.setEmail(author.getEmail());
 373    }
 374  32 setLocationWithinModule(context);
 375  32 return a;
 376    }
 377   
 378  32 private final ChapterListVo create(final ChapterList chapterList)
 379    throws IllegalModuleDataException {
 380  32 if (chapterList == null) {
 381  0 return null;
 382    }
 383  32 final ChapterListVo list = new ChapterListVo();
 384  32 final String context = getCurrentContext().getLocationWithinModule();
 385  32 for (int i = 0; i < chapterList.size(); i++) {
 386  133 setLocationWithinModule(context + ".get(" + i + ")");
 387  133 list.add(create(chapterList.get(i)));
 388    }
 389  30 setLocationWithinModule(context);
 390  30 return list;
 391    }
 392   
 393  133 private final ChapterVo create(final Chapter chapter)
 394    throws IllegalModuleDataException {
 395  133 if (chapter == null) {
 396  0 return null;
 397    }
 398  133 final ChapterVo c = new ChapterVo();
 399  133 final String context = getCurrentContext().getLocationWithinModule();
 400  133 if (chapter.getTitle() != null) {
 401  133 setLocationWithinModule(context + ".getTitle()");
 402  133 c.setTitle(create(chapter.getTitle()));
 403    }
 404  133 if (chapter.getNoNumber() != null) {
 405  42 setLocationWithinModule(context + ".getNoNumber()");
 406  42 c.setNoNumber(chapter.getNoNumber());
 407    }
 408  133 if (chapter.getIntroduction() != null) {
 409  130 setLocationWithinModule(context + ".getIntroduction()");
 410  130 c.setIntroduction(create(chapter.getIntroduction()));
 411    }
 412  133 if (chapter.getSectionList() != null) {
 413  82 setLocationWithinModule(context + ".getSectionList()");
 414  82 c.setSectionList(create(chapter.getSectionList()));
 415    }
 416  131 setLocationWithinModule(context);
 417  131 return c;
 418    }
 419   
 420  9 private LiteratureItemListVo create(final LiteratureItemList literatureItemList)
 421    throws IllegalModuleDataException {
 422  9 if (literatureItemList == null) {
 423  0 return null;
 424    }
 425  9 final LiteratureItemListVo list = new LiteratureItemListVo();
 426  9 final String context = getCurrentContext().getLocationWithinModule();
 427  9 for (int i = 0; i < literatureItemList.size(); i++) {
 428  43 setLocationWithinModule(context + ".get(" + i + ")");
 429  43 list.add(create(literatureItemList.get(i)));
 430    }
 431  9 setLocationWithinModule(context);
 432  9 return list;
 433    }
 434   
 435  43 private LiteratureItemVo create(final LiteratureItem item)
 436    throws IllegalModuleDataException {
 437  43