QedeqVoBuilder.java
0001 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
0002  *
0003  * Copyright 2000-2011,  Michael Meyling <mime@qedeq.org>.
0004  *
0005  * "Hilbert II" is free software; you can redistribute
0006  * it and/or modify it under the terms of the GNU General Public
0007  * License as published by the Free Software Foundation; either
0008  * version 2 of the License, or (at your option) any later version.
0009  *
0010  * This program is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0013  * GNU General Public License for more details.
0014  */
0015 
0016 package org.qedeq.kernel.bo.service;
0017 
0018 import org.qedeq.kernel.se.base.list.Atom;
0019 import org.qedeq.kernel.se.base.list.Element;
0020 import org.qedeq.kernel.se.base.list.ElementList;
0021 import org.qedeq.kernel.se.base.module.Add;
0022 import org.qedeq.kernel.se.base.module.Author;
0023 import org.qedeq.kernel.se.base.module.AuthorList;
0024 import org.qedeq.kernel.se.base.module.Axiom;
0025 import org.qedeq.kernel.se.base.module.ChangedRule;
0026 import org.qedeq.kernel.se.base.module.ChangedRuleList;
0027 import org.qedeq.kernel.se.base.module.Chapter;
0028 import org.qedeq.kernel.se.base.module.ChapterList;
0029 import org.qedeq.kernel.se.base.module.Conclusion;
0030 import org.qedeq.kernel.se.base.module.ConditionalProof;
0031 import org.qedeq.kernel.se.base.module.Existential;
0032 import org.qedeq.kernel.se.base.module.FormalProof;
0033 import org.qedeq.kernel.se.base.module.FormalProofLine;
0034 import org.qedeq.kernel.se.base.module.FormalProofLineList;
0035 import org.qedeq.kernel.se.base.module.FormalProofList;
0036 import org.qedeq.kernel.se.base.module.Formula;
0037 import org.qedeq.kernel.se.base.module.FunctionDefinition;
0038 import org.qedeq.kernel.se.base.module.Header;
0039 import org.qedeq.kernel.se.base.module.Hypothesis;
0040 import org.qedeq.kernel.se.base.module.Import;
0041 import org.qedeq.kernel.se.base.module.ImportList;
0042 import org.qedeq.kernel.se.base.module.InitialFunctionDefinition;
0043 import org.qedeq.kernel.se.base.module.InitialPredicateDefinition;
0044 import org.qedeq.kernel.se.base.module.Latex;
0045 import org.qedeq.kernel.se.base.module.LatexList;
0046 import org.qedeq.kernel.se.base.module.LinkList;
0047 import org.qedeq.kernel.se.base.module.LiteratureItem;
0048 import org.qedeq.kernel.se.base.module.LiteratureItemList;
0049 import org.qedeq.kernel.se.base.module.Location;
0050 import org.qedeq.kernel.se.base.module.LocationList;
0051 import org.qedeq.kernel.se.base.module.ModusPonens;
0052 import org.qedeq.kernel.se.base.module.Node;
0053 import org.qedeq.kernel.se.base.module.PredicateDefinition;
0054 import org.qedeq.kernel.se.base.module.Proof;
0055 import org.qedeq.kernel.se.base.module.ProofList;
0056 import org.qedeq.kernel.se.base.module.Proposition;
0057 import org.qedeq.kernel.se.base.module.Qedeq;
0058 import org.qedeq.kernel.se.base.module.Reason;
0059 import org.qedeq.kernel.se.base.module.Rename;
0060 import org.qedeq.kernel.se.base.module.Rule;
0061 import org.qedeq.kernel.se.base.module.Section;
0062 import org.qedeq.kernel.se.base.module.SectionList;
0063 import org.qedeq.kernel.se.base.module.Specification;
0064 import org.qedeq.kernel.se.base.module.Subsection;
0065 import org.qedeq.kernel.se.base.module.SubsectionList;
0066 import org.qedeq.kernel.se.base.module.SubstFree;
0067 import org.qedeq.kernel.se.base.module.SubstFunc;
0068 import org.qedeq.kernel.se.base.module.SubstPred;
0069 import org.qedeq.kernel.se.base.module.Universal;
0070 import org.qedeq.kernel.se.base.module.UsedByList;
0071 import org.qedeq.kernel.se.common.IllegalModuleDataException;
0072 import org.qedeq.kernel.se.common.ModuleAddress;
0073 import org.qedeq.kernel.se.common.ModuleContext;
0074 import org.qedeq.kernel.se.common.ModuleDataException;
0075 import org.qedeq.kernel.se.dto.list.DefaultAtom;
0076 import org.qedeq.kernel.se.dto.list.DefaultElementList;
0077 import org.qedeq.kernel.se.dto.module.AddVo;
0078 import org.qedeq.kernel.se.dto.module.AuthorListVo;
0079 import org.qedeq.kernel.se.dto.module.AuthorVo;
0080 import org.qedeq.kernel.se.dto.module.AxiomVo;
0081 import org.qedeq.kernel.se.dto.module.ChangedRuleListVo;
0082 import org.qedeq.kernel.se.dto.module.ChangedRuleVo;
0083 import org.qedeq.kernel.se.dto.module.ChapterListVo;
0084 import org.qedeq.kernel.se.dto.module.ChapterVo;
0085 import org.qedeq.kernel.se.dto.module.ConclusionVo;
0086 import org.qedeq.kernel.se.dto.module.ConditionalProofVo;
0087 import org.qedeq.kernel.se.dto.module.ExistentialVo;
0088 import org.qedeq.kernel.se.dto.module.FormalProofLineListVo;
0089 import org.qedeq.kernel.se.dto.module.FormalProofLineVo;
0090 import org.qedeq.kernel.se.dto.module.FormalProofListVo;
0091 import org.qedeq.kernel.se.dto.module.FormalProofVo;
0092 import org.qedeq.kernel.se.dto.module.FormulaVo;
0093 import org.qedeq.kernel.se.dto.module.FunctionDefinitionVo;
0094 import org.qedeq.kernel.se.dto.module.HeaderVo;
0095 import org.qedeq.kernel.se.dto.module.HypothesisVo;
0096 import org.qedeq.kernel.se.dto.module.ImportListVo;
0097 import org.qedeq.kernel.se.dto.module.ImportVo;
0098 import org.qedeq.kernel.se.dto.module.InitialFunctionDefinitionVo;
0099 import org.qedeq.kernel.se.dto.module.InitialPredicateDefinitionVo;
0100 import org.qedeq.kernel.se.dto.module.LatexListVo;
0101 import org.qedeq.kernel.se.dto.module.LatexVo;
0102 import org.qedeq.kernel.se.dto.module.LinkListVo;
0103 import org.qedeq.kernel.se.dto.module.LiteratureItemListVo;
0104 import org.qedeq.kernel.se.dto.module.LiteratureItemVo;
0105 import org.qedeq.kernel.se.dto.module.LocationListVo;
0106 import org.qedeq.kernel.se.dto.module.LocationVo;
0107 import org.qedeq.kernel.se.dto.module.ModusPonensVo;
0108 import org.qedeq.kernel.se.dto.module.NodeVo;
0109 import org.qedeq.kernel.se.dto.module.PredicateDefinitionVo;
0110 import org.qedeq.kernel.se.dto.module.ProofListVo;
0111 import org.qedeq.kernel.se.dto.module.ProofVo;
0112 import org.qedeq.kernel.se.dto.module.PropositionVo;
0113 import org.qedeq.kernel.se.dto.module.QedeqVo;
0114 import org.qedeq.kernel.se.dto.module.RenameVo;
0115 import org.qedeq.kernel.se.dto.module.RuleVo;
0116 import org.qedeq.kernel.se.dto.module.SectionListVo;
0117 import org.qedeq.kernel.se.dto.module.SectionVo;
0118 import org.qedeq.kernel.se.dto.module.SpecificationVo;
0119 import org.qedeq.kernel.se.dto.module.SubsectionListVo;
0120 import org.qedeq.kernel.se.dto.module.SubsectionVo;
0121 import org.qedeq.kernel.se.dto.module.SubstFreeVo;
0122 import org.qedeq.kernel.se.dto.module.SubstFuncVo;
0123 import org.qedeq.kernel.se.dto.module.SubstPredVo;
0124 import org.qedeq.kernel.se.dto.module.UniversalVo;
0125 import org.qedeq.kernel.se.dto.module.UsedByListVo;
0126 
0127 
0128 /**
0129  * FIXME 20110125 m31: why do we need this builder? To make copies. Why don't we take the original?
0130  * At least use director pattern or transfer creation methods into BOs or use visitor pattern!
0131  * We have lots of duplicate code here!
0132  <p>
0133  * An builder for creating {@link org.qedeq.kernel.se.dto.module.QedeqVo}s. This builder takes
0134  * something that implements the QEDEQ interfaces (beginning with
0135  * (@link org.qedeq.kernel.base.module.Qedeq} and makes copies that are out of the package
0136  <code>org.qedeq.kernel.dto.*</code>. Only elements that are not <code>null</code> are
0137  * copied.
0138 
0139  @author    Michael Meyling
0140  */
0141 public class QedeqVoBuilder {
0142 
0143     /** QEDEQ module input object. */
0144     private Qedeq original;
0145 
0146     /** Current context during creation. */
0147     private ModuleContext currentContext;
0148 
0149     /**
0150      * Constructor.
0151      *
0152      @param   address QEDEQ address.
0153      */
0154     protected QedeqVoBuilder(final ModuleAddress address) {
0155         this.currentContext = address.createModuleContext();
0156     }
0157 
0158     /**
0159      * Create {@link QedeqVo} out of an {@link Qedeq} instance.
0160      * The resulting object has no references to the original {@link Qedeq} instance.
0161      <p>
0162      * During the creation process the caller must assert that no modifications are made
0163      * to the {@link Qedeq} instance including its referenced objects.
0164      *
0165      @param   address     Module address.
0166      @param   original    Basic QEDEQ module object.
0167      @return  Created copy object.
0168      @throws  ModuleDataException     Invalid data found.
0169      */
0170     public static QedeqVo createQedeq(final ModuleAddress address,
0171             final Qedeq originalthrows ModuleDataException {
0172         final QedeqVoBuilder creator = new QedeqVoBuilder(address);
0173         QedeqVo vo = creator.create(original);
0174         return vo;
0175     }
0176 
0177     /**
0178      * Create {@linkQedeqVo} out of an {@link Qedeq} instance.
0179      * During that procedure some basic checking is done. E.g. the uniqueness of entries
0180      * is tested. The resulting business object has no references to the original
0181      * {@link Qedeq} instance.
0182      *
0183      <p>
0184      * During the creation process the caller must assert that no modifications are made
0185      * to the {@link Qedeq} instance including its referenced objects.
0186      *
0187      @param   original    Basic QEDEQ module object.
0188      @return  Copied QEDEQ object.
0189      @throws  IllegalModuleDataException  Basic semantic error occurred.
0190      */
0191     protected final QedeqVo create(final Qedeq originalthrows IllegalModuleDataException {
0192         this.original = original;
0193         getCurrentContext().setLocationWithinModule("");
0194         QedeqVo qedeq;
0195         if (original == null) {
0196             qedeq = null;
0197             return qedeq;
0198         }
0199         qedeq = new QedeqVo();
0200         final String context = getCurrentContext().getLocationWithinModule();
0201         if (original.getHeader() != null) {
0202             getCurrentContext().setLocationWithinModule(context + "getHeader()");
0203             qedeq.setHeader(create(original.getHeader()));
0204         }
0205         if (original.getChapterList() != null) {
0206             getCurrentContext().setLocationWithinModule(context + "getChapterList()");
0207             qedeq.setChapterList(create(original.getChapterList()));
0208         }
0209         if (original.getLiteratureItemList() != null) {
0210             getCurrentContext().setLocationWithinModule(context + "getLiteratureItemList()");
0211             qedeq.setLiteratureItemList(create(original.getLiteratureItemList()));
0212         }
0213         return qedeq;
0214     }
0215 
0216     /**
0217      * Create {@link HeaderVo} out of an {@link Header} instance.
0218      * During that procedure some basic checking is done. E.g. the uniqueness of entries
0219      * is tested. The resulting business object has no references to the original
0220      * {@link Header} instance.
0221      <p>
0222      * During the creation process the caller must assert that no modifications are made
0223      * to the {@link Header} instance including its referenced objects.
0224      *
0225      @param   header  Basic header object.
0226      @return  Filled header business object. Is equal to the parameter <code>header</code>.
0227      @throws  IllegalModuleDataException  Basic semantic error occurred.
0228      */
0229     private final HeaderVo create(final Header header)
0230             throws IllegalModuleDataException {
0231         if (header == null) {
0232             return null;
0233         }
0234         final HeaderVo h = new HeaderVo();
0235         final String context = getCurrentContext().getLocationWithinModule();
0236         if (header.getTitle() != null) {
0237             setLocationWithinModule(context + ".getTitle()");
0238             h.setTitle(create(header.getTitle()));
0239         }
0240         if (header.getAuthorList() != null) {
0241             setLocationWithinModule(context + ".getAuthorList()");
0242             h.setAuthorList(create(header.getAuthorList()));
0243         }
0244         if (header.getSummary() != null) {
0245             setLocationWithinModule(context + ".getSummary()");
0246             h.setSummary(create(header.getSummary()));
0247         }
0248         if (header.getEmail() != null) {
0249             setLocationWithinModule(context + ".getEmail()");
0250             h.setEmail(header.getEmail());
0251         }
0252         if (header.getSpecification() != null) {
0253             setLocationWithinModule(context + ".getSpecification()");
0254             h.setSpecification(create(header.getSpecification()));
0255         }
0256         if (header.getImportList() != null) {
0257             setLocationWithinModule(context + ".getImportList()");
0258             h.setImportList(create(header.getImportList()));
0259         }
0260         if (header.getUsedByList() != null) {
0261             setLocationWithinModule(context + ".getUsedByList()");
0262             h.setUsedByList(create(header.getUsedByList()));
0263         }
0264         setLocationWithinModule(context);
0265         return h;
0266     }
0267 
0268     /**
0269      * Create {@link UsedByListVo} out of an {@link UsedByList} instance.
0270      * During that procedure some basic checking is done. E.g. the uniqueness of entries
0271      * is tested. The resulting business object has no references to the original
0272      * {@link UsedByList} instance.
0273      <p>
0274      * During the creation process the caller must assert that no modifications are made
0275      * to the {@link UsedByList} instance including its referenced objects.
0276      *
0277      @param   usedByList  Basic header object.
0278      @return  Filled used by business object. Is equal to the parameter <code>usedByList</code>.
0279      */
0280     private final UsedByListVo create(final UsedByList usedByList) {
0281         if (usedByList == null) {
0282             return null;
0283         }
0284         final String context = getCurrentContext().getLocationWithinModule();
0285         final UsedByListVo list = new UsedByListVo();
0286         for (int i = 0; i < usedByList.size(); i++) {
0287             setLocationWithinModule(context + ".get(" + i + ")");
0288             list.add(create(usedByList.get(i)));
0289         }
0290         setLocationWithinModule(context);
0291         return list;
0292     }
0293 
0294     private final ImportListVo create(final ImportList importList) {
0295         if (importList == null) {
0296             return null;
0297         }
0298         final String context = getCurrentContext().getLocationWithinModule();
0299         final ImportListVo list = new ImportListVo();
0300         for (int i = 0; i < importList.size(); i++) {
0301             setLocationWithinModule(context + ".get(" + i + ")");
0302             list.add(create(importList.get(i)));
0303         }
0304         setLocationWithinModule(context);
0305         return list;
0306     }
0307 
0308     private final ImportVo create(final Import imp) {
0309         if (imp == null) {
0310             return null;
0311         }
0312         final ImportVo i = new ImportVo();
0313         final String context = getCurrentContext().getLocationWithinModule();
0314         if (imp.getLabel() != null) {
0315             setLocationWithinModule(context + ".getLabel()");
0316             i.setLabel(imp.getLabel());
0317         }
0318         if (imp.getSpecification() != null) {
0319             setLocationWithinModule(context + ".getSpecification()");
0320             i.setSpecification(create(imp.getSpecification()));
0321         }
0322         setLocationWithinModule(context);
0323         return i;
0324     }
0325 
0326     private final SpecificationVo create(final Specification specification) {
0327         if (specification == null) {
0328             return null;
0329         }
0330         final SpecificationVo s = new SpecificationVo();
0331         final String context = getCurrentContext().getLocationWithinModule();
0332         if (specification.getName() != null) {
0333             setLocationWithinModule(context + ".getName()");
0334             s.setName(specification.getName());
0335         }
0336         if (specification.getRuleVersion() != null) {
0337             setLocationWithinModule(context + ".getRuleVersion()");
0338             s.setRuleVersion(specification.getRuleVersion());
0339         }
0340         if (specification.getLocationList() != null) {
0341             setLocationWithinModule(context + ".getLocationList()");
0342             s.setLocationList(create(specification.getLocationList()));
0343         }
0344         setLocationWithinModule(context);
0345         return s;
0346     }
0347 
0348     private final LocationListVo create(final LocationList locationList) {
0349         if (locationList == null) {
0350             return null;
0351         }
0352         final LocationListVo list = new LocationListVo();
0353         final String context = getCurrentContext().getLocationWithinModule();
0354         for (int i = 0; i < locationList.size(); i++) {
0355             setLocationWithinModule(context + ".get(" + i + ")");
0356             list.add(create(locationList.get(i)));
0357         }
0358         setLocationWithinModule(context);
0359         return list;
0360     }
0361 
0362     private final LocationVo create(final Location location) {
0363         if (location == null) {
0364             return null;
0365         }
0366         final LocationVo loc = new LocationVo();
0367         final String context = getCurrentContext().getLocationWithinModule();
0368         if (location.getLocation() != null) {
0369             setLocationWithinModule(context + ".getLocation()");
0370             loc.setLocation(location.getLocation());
0371         }
0372         setLocationWithinModule(context);
0373         return loc;
0374     }
0375 
0376     private final AuthorListVo create(final AuthorList authorList) {
0377         if (authorList == null) {
0378             return null;
0379         }
0380         final AuthorListVo list = new AuthorListVo();
0381         final String context = getCurrentContext().getLocationWithinModule();
0382         for (int i = 0; i < authorList.size(); i++) {
0383             setLocationWithinModule(context + ".get(" + i + ")");
0384             list.add(create(authorList.get(i)));
0385         }
0386         setLocationWithinModule(context);
0387         return list;
0388     }
0389 
0390     private final AuthorVo create(final Author author) {
0391         if (author == null) {
0392             return null;
0393         }
0394         final AuthorVo a = new AuthorVo();
0395         final String context = getCurrentContext().getLocationWithinModule();
0396         if (author.getName() != null) {
0397             setLocationWithinModule(context + ".getName()");
0398             a.setName(create(author.getName()));
0399         }
0400         if (author.getEmail() != null) {
0401             setLocationWithinModule(context + ".getEmail()");
0402             a.setEmail(author.getEmail());
0403         }
0404         setLocationWithinModule(context);
0405         return a;
0406     }
0407 
0408     private final ChapterListVo create(final ChapterList chapterList)
0409             throws IllegalModuleDataException {
0410         if (chapterList == null) {
0411             return null;
0412         }
0413         final ChapterListVo list = new ChapterListVo();
0414         final String context = getCurrentContext().getLocationWithinModule();
0415         for (int i = 0; i < chapterList.size(); i++) {
0416             setLocationWithinModule(context + ".get(" + i + ")");
0417             list.add(create(chapterList.get(i)));
0418         }
0419         setLocationWithinModule(context);
0420         return list;
0421     }
0422 
0423     private final ChapterVo create(final Chapter chapter)
0424             throws IllegalModuleDataException {
0425         if (chapter == null) {
0426             return null;
0427         }
0428         final ChapterVo c = new ChapterVo();
0429         final String context = getCurrentContext().getLocationWithinModule();
0430         if (chapter.getTitle() != null) {
0431             setLocationWithinModule(context + ".getTitle()");
0432             c.setTitle(create(chapter.getTitle()));
0433         }
0434         if (chapter.getNoNumber() != null) {
0435             setLocationWithinModule(context + ".getNoNumber()");
0436             c.setNoNumber(chapter.getNoNumber());
0437         }
0438         if (chapter.getIntroduction() != null) {
0439             setLocationWithinModule(context + ".getIntroduction()");
0440             c.setIntroduction(create(chapter.getIntroduction()));
0441         }
0442         if (chapter.getSectionList() != null) {
0443             setLocationWithinModule(context + ".getSectionList()");
0444             c.setSectionList(create(chapter.getSectionList()));
0445         }
0446         setLocationWithinModule(context);
0447         return c;
0448     }
0449 
0450     private LiteratureItemListVo create(final LiteratureItemList literatureItemList)
0451             throws IllegalModuleDataException {
0452         if (literatureItemList == null) {
0453             return null;
0454         }
0455         final LiteratureItemListVo list = new LiteratureItemListVo();
0456         final String context = getCurrentContext().getLocationWithinModule();
0457         for (int i = 0; i < literatureItemList.size(); i++) {
0458             setLocationWithinModule(context + ".get(" + i + ")");
0459             list.add(create(literatureItemList.get(i)));
0460         }
0461         setLocationWithinModule(context);
0462         return list;
0463     }
0464 
0465     private LiteratureItemVo create(final LiteratureItem item)
0466             throws IllegalModuleDataException {
0467         if (item == null) {
0468             return null;
0469         }
0470         final LiteratureItemVo it = new LiteratureItemVo();
0471         final String context = getCurrentContext().getLocationWithinModule();
0472         if (item.getLabel() != null) {
0473             setLocationWithinModule(context + ".getLabel()");
0474             it.setLabel(item.getLabel());
0475         }
0476         if (item.getItem() != null) {
0477             setLocationWithinModule(context + ".getItem()");
0478             it.setItem(create(item.getItem()));
0479         }
0480         setLocationWithinModule(context);
0481         return it;
0482 
0483     }
0484 
0485     private final SectionListVo create(final SectionList sectionList)
0486             throws IllegalModuleDataException {
0487         if (sectionList == null) {
0488             return null;
0489         }
0490         final SectionListVo list = new SectionListVo();
0491         final String context = getCurrentContext().getLocationWithinModule();
0492         for (int i = 0; i < sectionList.size(); i++) {
0493             setLocationWithinModule(context + ".get(" + i + ")");
0494             list.add(create(sectionList.get(i)));
0495         }
0496         setLocationWithinModule(context);
0497         return list;
0498     }
0499 
0500     private final SectionVo create(final Section section)
0501             throws IllegalModuleDataException {
0502         if (section == null) {
0503             return null;
0504         }
0505         final SectionVo s = new SectionVo();
0506         final String context = getCurrentContext().getLocationWithinModule();
0507         if (section.getTitle() != null) {
0508             setLocationWithinModule(context + ".getTitle()");
0509             s.setTitle(create(section.getTitle()));
0510         }
0511         if (section.getNoNumber() != null) {
0512             setLocationWithinModule(context + ".getNoNumber()");
0513             s.setNoNumber(section.getNoNumber());
0514         }
0515         if (section.getIntroduction() != null) {
0516             setLocationWithinModule(context + ".getIntroduction()");
0517             s.setIntroduction(create(section.getIntroduction()));
0518         }
0519         if (section.getSubsectionList() != null) {
0520             setLocationWithinModule(context + ".getSubsectionList()");
0521             s.setSubsectionList(create(section.getSubsectionList()));
0522         }
0523         setLocationWithinModule(context);
0524         return s;
0525     }
0526 
0527     private final SubsectionListVo create(final SubsectionList subsectionList)
0528             throws IllegalModuleDataException {
0529         if (subsectionList == null) {
0530             return null;
0531         }
0532         final SubsectionListVo list = new SubsectionListVo();
0533         final String context = getCurrentContext().getLocationWithinModule();
0534         for (int i = 0; i < subsectionList.size(); i++) {
0535             setLocationWithinModule(context + ".get(" + i + ")");
0536             // TODO mime 20050608: here the Subsection context is type dependently specified
0537             if (subsectionList.get(iinstanceof Subsection) {
0538                 list.add(create((SubsectionsubsectionList.get(i)));
0539             else if (subsectionList.get(iinstanceof Node) {
0540                 list.add(create((NodesubsectionList.get(i)));
0541             else {
0542                 throw new IllegalArgumentException("unexpected subsection type: "
0543                     + subsectionList.get(i).getClass());
0544             }
0545         }
0546         setLocationWithinModule(context);
0547         return list;
0548     }
0549 
0550     private final SubsectionVo create(final Subsection subsection) {
0551         if (subsection == null) {
0552             return null;
0553         }
0554         final SubsectionVo s = new SubsectionVo();
0555         final String context = getCurrentContext().getLocationWithinModule();
0556         if (subsection.getId() != null) {
0557             setLocationWithinModule(context + ".getId()");
0558             s.setId(subsection.getId());
0559         }
0560         if (subsection.getLevel() != null) {
0561             setLocationWithinModule(context + ".getLevel()");
0562             s.setLevel(subsection.getLevel());
0563         }
0564         if (subsection.getTitle() != null) {
0565             setLocationWithinModule(context + ".getTitle()");
0566             s.setTitle(create(subsection.getTitle()));
0567         }
0568         if (subsection.getLatex() != null) {
0569             setLocationWithinModule(context + ".getLatex()");
0570             s.setLatex(create(subsection.getLatex()));
0571         }
0572         setLocationWithinModule(context);
0573         return s;
0574     }
0575 
0576     private final NodeVo create(final Node node)
0577             throws IllegalModuleDataException {
0578         if (node == null) {
0579             return null;
0580         }
0581         final NodeVo n = new NodeVo();
0582         final String context = getCurrentContext().getLocationWithinModule();
0583         if (node.getName() != null) {
0584             setLocationWithinModule(context + ".getName()");
0585             n.setName(create(node.getName()));
0586         }
0587         if (node.getId() != null) {
0588             setLocationWithinModule(context + ".getId()");
0589             n.setId(node.getId());
0590         }
0591         if (node.getLevel() != null) {
0592             setLocationWithinModule(context + ".getLevel()");
0593             n.setLevel(node.getLevel());
0594         }
0595         if (node.getTitle() != null) {
0596             setLocationWithinModule(context + ".getTitle()");
0597             n.setTitle(create(node.getTitle()));
0598         }
0599         if (node.getPrecedingText() != null) {
0600             setLocationWithinModule(context + ".getPrecedingText()");
0601             n.setPrecedingText(create(node.getPrecedingText()));
0602         }
0603         if (node.getNodeType() != null) {
0604             setLocationWithinModule(context + ".getNodeType()");
0605             if (node.getNodeType() instanceof Axiom) {
0606                 setLocationWithinModule(context + ".getNodeType().getAxiom()");
0607                 n.setNodeType(create((Axiomnode.getNodeType()));
0608             else if (node.getNodeType() instanceof InitialPredicateDefinition) {
0609                 setLocationWithinModule(context + ".getNodeType().getInitialPredicateDefinition()");
0610                 n.setNodeType(create((InitialPredicateDefinitionnode.getNodeType()));
0611             else if (node.getNodeType() instanceof PredicateDefinition) {
0612                 setLocationWithinModule(context + ".getNodeType().getPredicateDefinition()");
0613                 n.setNodeType(create((PredicateDefinitionnode.getNodeType()));
0614             else if (node.getNodeType() instanceof InitialFunctionDefinition) {
0615                 setLocationWithinModule(context + ".getNodeType().getInitialFunctionDefinition()");
0616                 n.setNodeType(create((InitialFunctionDefinitionnode.getNodeType()));
0617             else if (node.getNodeType() instanceof FunctionDefinition) {
0618                 setLocationWithinModule(context + ".getNodeType().getFunctionDefinition()");
0619                 n.setNodeType(create((FunctionDefinitionnode.getNodeType()));
0620             else if (node.getNodeType() instanceof Proposition) {
0621                 setLocationWithinModule(context + ".getNodeType().getProposition()");
0622                 n.setNodeType(create((Propositionnode.getNodeType()));
0623             else if (node.getNodeType() instanceof Rule) {
0624                 setLocationWithinModule(context + ".getNodeType().getRule()");
0625                 n.setNodeType(create((Rulenode.getNodeType()));
0626             else {
0627                 throw new IllegalModuleDataException(ServiceErrors.RUNTIME_ERROR_CODE,
0628                     ServiceErrors.RUNTIME_ERROR_TEXT + " "
0629                     "unexpected node type: " + node.getNodeType().getClass(),
0630                     getCurrentContext());
0631             }
0632         }
0633         if (node.getSucceedingText() != null) {
0634             setLocationWithinModule(context + ".getSucceedingText()");
0635             n.setSucceedingText(create(node.getSucceedingText()));
0636         }
0637         setLocationWithinModule(context);
0638         return n;
0639     }
0640 
0641     private final AxiomVo create(final Axiom axiom) {
0642         if (axiom == null) {
0643             return null;
0644         }
0645         final AxiomVo a = new AxiomVo();
0646         final String context = getCurrentContext().getLocationWithinModule();
0647         if (axiom.getDefinedOperator() != null) {
0648             setLocationWithinModule(context + ".getDefinedOperator()");
0649             a.setDefinedOperator(axiom.getDefinedOperator());
0650         }
0651         if (axiom.getFormula() != null) {
0652             setLocationWithinModule(context + ".getFormula()");
0653             a.setFormula(create(axiom.getFormula()));
0654         }
0655         if (axiom.getDescription() != null) {
0656             setLocationWithinModule(context + ".getDescription()");
0657             a.setDescription(create(axiom.getDescription()));
0658         }
0659         setLocationWithinModule(context);
0660         return a;
0661     }
0662 
0663     private final InitialPredicateDefinitionVo create(final InitialPredicateDefinition definition) {
0664         if (definition == null) {
0665             return null;
0666         }
0667         final InitialPredicateDefinitionVo d = new InitialPredicateDefinitionVo();
0668         final String context = getCurrentContext().getLocationWithinModule();
0669         if (definition.getLatexPattern() != null) {
0670             setLocationWithinModule(context + ".getLatexPattern()");
0671             d.setLatexPattern(definition.getLatexPattern());
0672         }
0673         if (definition.getName() != null) {
0674             setLocationWithinModule(context + ".getName()");
0675             d.setName(definition.getName());
0676         }
0677         if (definition.getArgumentNumber() != null) {
0678             setLocationWithinModule(context + ".getArgumentNumber()");
0679             d.setArgumentNumber(definition.getArgumentNumber());
0680         }
0681         if (definition.getPredCon() != null) {
0682             setLocationWithinModule(context + ".getPredCon()");
0683             d.setPredCon(create(definition.getPredCon()));
0684         }
0685         if (definition.getDescription() != null) {
0686             setLocationWithinModule(context + ".getDescription()");
0687             d.setDescription(create(definition.getDescription()));
0688         }
0689         setLocationWithinModule(context);
0690         return d;
0691     }
0692 
0693     private final PredicateDefinitionVo create(final PredicateDefinition definition) {
0694         if (definition == null) {
0695             return null;
0696         }
0697         final PredicateDefinitionVo d = new PredicateDefinitionVo();
0698         final String context = getCurrentContext().getLocationWithinModule();
0699         if (definition.getLatexPattern() != null) {
0700             setLocationWithinModule(context + ".getLatexPattern()");
0701             d.setLatexPattern(definition.getLatexPattern());
0702         }
0703         if (definition.getName() != null) {
0704             setLocationWithinModule(context + ".getName()");
0705             d.setName(definition.getName());
0706         }
0707         if (definition.getArgumentNumber() != null) {
0708             setLocationWithinModule(context + ".getArgumentNumber()");
0709             d.setArgumentNumber(definition.getArgumentNumber());
0710         }
0711         if (definition.getFormula() != null) {
0712             setLocationWithinModule(context + ".getFormula()");
0713             d.setFormula(create(definition.getFormula()));
0714         }
0715         if (definition.getDescription() != null) {
0716             setLocationWithinModule(context + ".getDescription()");
0717             d.setDescription(create(definition.getDescription()));
0718         }
0719         setLocationWithinModule(context);
0720         return d;
0721     }
0722 
0723     private final InitialFunctionDefinitionVo create(final InitialFunctionDefinition definition) {
0724         if (definition == null) {
0725             return null;
0726         }
0727         final InitialFunctionDefinitionVo d = new InitialFunctionDefinitionVo();
0728         final String context = getCurrentContext().getLocationWithinModule();
0729         if (definition.getLatexPattern() != null) {
0730             setLocationWithinModule(context + ".getLatexPattern()");
0731             d.setLatexPattern(definition.getLatexPattern());
0732         }
0733         if (definition.getArgumentNumber() != null) {
0734             setLocationWithinModule(context + ".getArgumentNumber()");
0735             d.setArgumentNumber(definition.getArgumentNumber());
0736         }
0737         if (definition.getName() != null) {
0738             setLocationWithinModule(context + ".getName()");
0739             d.setName(definition.getName());
0740         }
0741         if (definition.getFunCon() != null) {
0742             setLocationWithinModule(context + ".getFunCon()");
0743             d.setFunCon(create(definition.getFunCon()));
0744         }
0745         if (definition.getDescription() != null) {
0746             setLocationWithinModule(context + ".getDescription()");
0747             d.setDescription(create(definition.getDescription()));
0748         }
0749         setLocationWithinModule(context);
0750         return d;
0751     }
0752 
0753     private final FunctionDefinitionVo create(final FunctionDefinition definition) {
0754         if (definition == null) {
0755             return null;
0756         }
0757         final FunctionDefinitionVo d = new FunctionDefinitionVo();
0758         final String context = getCurrentContext().getLocationWithinModule();
0759         if (definition.getLatexPattern() != null) {
0760             setLocationWithinModule(context + ".getLatexPattern()");
0761             d.setLatexPattern(definition.getLatexPattern());
0762         }
0763         if (definition.getArgumentNumber() != null) {
0764             setLocationWithinModule(context + ".getArgumentNumber()");
0765             d.setArgumentNumber(definition.getArgumentNumber());
0766         }
0767         if (definition.getName() != null) {
0768             setLocationWithinModule(context + ".getName()");
0769             d.setName(definition.getName());
0770         }
0771         if (definition.getFormula() != null) {
0772             setLocationWithinModule(context + ".getFormula()");
0773             d.setFormula(create(definition.getFormula()));
0774         }
0775         if (definition.getDescription() != null) {
0776             setLocationWithinModule(context + ".getDescription()");
0777             d.setDescription(create(definition.getDescription()));
0778         }
0779         setLocationWithinModule(context);
0780         return d;
0781     }
0782 
0783     private final PropositionVo create(final Proposition proposition) {
0784         if (proposition == null) {
0785             return null;
0786         }
0787         final PropositionVo p = new PropositionVo();
0788         final String context = getCurrentContext().getLocationWithinModule();
0789         if (proposition.getFormula() != null) {
0790             setLocationWithinModule(context + ".getFormula()");
0791             p.setFormula(create(proposition.getFormula()));
0792         }
0793         if (proposition.getDescription() != null) {
0794             setLocationWithinModule(context + ".getDescription()");
0795             p.setDescription(create(proposition.getDescription()));
0796         }
0797         if (proposition.getProofList() != null) {
0798             setLocationWithinModule(context + ".getProofList()");
0799             p.setProofList(create(proposition.getProofList()));
0800         }
0801         if (proposition.getFormalProofList() != null) {
0802             setLocationWithinModule(context + ".getFormalProofList()");
0803             p.setFormalProofList(create(proposition.getFormalProofList()));
0804         }
0805         setLocationWithinModule(context);
0806         return p;
0807     }
0808 
0809     private final RuleVo create(final Rule rule) {
0810         if (rule == null) {
0811             return null;
0812         }
0813         final RuleVo r = new RuleVo();
0814         final String context = getCurrentContext().getLocationWithinModule();
0815         if (rule.getName() != null) {
0816             setLocationWithinModule(context + ".getName()");
0817             r.setName(rule.getName());
0818         }
0819         if (rule.getVersion() != null) {
0820             setLocationWithinModule(context + ".getVersion()");
0821             r.setVersion(rule.getVersion());
0822         }
0823         if (rule.getLinkList() != null) {
0824             setLocationWithinModule(context + ".getLinkList()");
0825             r.setLinkList(create(rule.getLinkList()));
0826         }
0827         if (rule.getDescription() != null) {
0828             setLocationWithinModule(context + ".getDescription()");
0829             r.setDescription(create(rule.getDescription()));
0830         }
0831         if (rule.getChangedRuleList() != null) {
0832             setLocationWithinModule(context + ".getChangedRuleList()");
0833             r.setChangedRuleList(create(rule.getChangedRuleList()));
0834         }
0835         if (rule.getProofList() != null) {
0836             setLocationWithinModule(context + ".getProofList()");
0837             r.setProofList(create(rule.getProofList()));
0838         }
0839         setLocationWithinModule(context);
0840         return r;
0841     }
0842 
0843     private final ChangedRuleListVo create(final ChangedRuleList changedRuleList) {
0844         if (changedRuleList == null) {
0845             return null;
0846         }
0847         final ChangedRuleListVo list = new ChangedRuleListVo();
0848         final String context = getCurrentContext().getLocationWithinModule();
0849         for (int i = 0; i < changedRuleList.size(); i++) {
0850             setLocationWithinModule(context + ".get(" + i + ")");
0851             list.add(create(changedRuleList.get(i)));
0852         }
0853         setLocationWithinModule(context);
0854         return list;
0855     }
0856 
0857     private final ChangedRuleVo create(final ChangedRule rule) {
0858         if (rule == null) {
0859             return null;
0860         }
0861         final ChangedRuleVo r = new ChangedRuleVo();
0862         final String context = getCurrentContext().getLocationWithinModule();
0863         if (rule.getName() != null) {
0864             setLocationWithinModule(context + ".getName()");
0865             r.setName(rule.getName());
0866         }
0867         if (rule.getVersion() != null) {
0868             setLocationWithinModule(context + ".getVersion()");
0869             r.setVersion(rule.getVersion());
0870         }
0871         if (rule.getDescription() != null) {
0872             setLocationWithinModule(context + ".getDescription()");
0873             r.setDescription(create(rule.getDescription()));
0874         }
0875         setLocationWithinModule(context);
0876         return r;
0877     }
0878 
0879     private final LinkListVo create(final LinkList linkList) {
0880         if (linkList == null) {
0881             return null;
0882         }
0883         final LinkListVo list = new LinkListVo();
0884         final String context = getCurrentContext().getLocationWithinModule();
0885         for (int i = 0; i < linkList.size(); i++) {
0886             setLocationWithinModule(context + ".get(" + i + ")");
0887             list.add(linkList.get(i));
0888         }
0889         setLocationWithinModule(context);
0890         return list;
0891     }
0892 
0893     private final ProofListVo create(final ProofList proofList) {
0894         if (proofList == null) {
0895             return null;
0896         }
0897         final ProofListVo list = new ProofListVo();
0898         final String context = getCurrentContext().getLocationWithinModule();
0899         for (int i = 0; i < proofList.size(); i++) {
0900             setLocationWithinModule(context + ".get(" + i + ")");
0901             list.add(create(proofList.get(i)));
0902         }
0903         setLocationWithinModule(context);
0904         return list;
0905     }
0906 
0907     private final ProofVo create(final Proof proof) {
0908         if (proof == null) {
0909             return null;
0910         }
0911         final ProofVo p = new ProofVo();
0912         final String context = getCurrentContext().getLocationWithinModule();
0913         setLocationWithinModule(context + ".getKind()");
0914         p.setKind(proof.getKind());
0915         setLocationWithinModule(context + ".getLevel()");
0916         p.setLevel(proof.getLevel());
0917         setLocationWithinModule(context);
0918         if (proof.getNonFormalProof() != null) {
0919             setLocationWithinModule(context + ".getNonFormalProof()");
0920             p.setNonFormalProof(create(proof.getNonFormalProof()));
0921         }
0922         setLocationWithinModule(context);
0923         return p;
0924     }
0925 
0926     private final FormalProofListVo create(final FormalProofList proofList) {
0927         if (proofList == null) {
0928             return null;
0929         }
0930         final FormalProofListVo list = new FormalProofListVo();
0931         final String context = getCurrentContext().getLocationWithinModule();
0932         for (int i = 0; i < proofList.size(); i++) {
0933             setLocationWithinModule(context + ".get(" + i + ")");
0934             list.add(create(proofList.get(i)));
0935         }
0936         setLocationWithinModule(context);
0937         return list;
0938     }
0939 
0940     private final FormalProofVo create(final FormalProof proof) {
0941         if (proof == null) {
0942             return null;
0943         }
0944         final FormalProofVo p = new FormalProofVo();
0945         final String context = getCurrentContext().getLocationWithinModule();
0946         setLocationWithinModule(context);
0947         if (proof.getPrecedingText() != null) {
0948             setLocationWithinModule(context + ".getPrecedingText()");
0949             p.setPrecedingText(create(proof.getPrecedingText()));
0950         }
0951         if (proof.getFormalProofLineList() != null) {
0952             setLocationWithinModule(context + ".getFormalProofLineList()");
0953             p.setFormalProofLineList(create(proof.getFormalProofLineList()));
0954         }
0955         if (proof.getSucceedingText() != null) {
0956             setLocationWithinModule(context + ".getSucceedingText()");
0957             p.setSucceedingText(create(proof.getSucceedingText()));
0958         }
0959         setLocationWithinModule(context);
0960         return p;
0961     }
0962 
0963     private final FormalProofLineListVo create(final FormalProofLineList proofList) {
0964         if (proofList == null) {
0965             return null;
0966         }
0967         final FormalProofLineListVo list = new FormalProofLineListVo();
0968         final String context = getCurrentContext().getLocationWithinModule();
0969         for (int i = 0; i < proofList.size(); i++) {
0970             setLocationWithinModule(context + ".get(" + i + ")");
0971             if (proofList.get(iinstanceof ConditionalProof) {
0972                 list.add(create((ConditionalProofproofList.get(i)));
0973             else {
0974                 list.add(create(proofList.get(i)));
0975             }
0976         }
0977         setLocationWithinModule(context);
0978         return list;
0979     }
0980 
0981     private final FormalProofLineVo create(final FormalProofLine proofLine) {
0982         if (proofLine == null) {
0983             return null;
0984         }
0985         final FormalProofLineVo line = new FormalProofLineVo();
0986         final String context = getCurrentContext().getLocationWithinModule();
0987         if (proofLine.getLabel() != null) {
0988             setLocationWithinModule(context + ".getLabel()");
0989             line.setLabel(proofLine.getLabel());
0990         }
0991         if (proofLine.getFormula() != null) {
0992             setLocationWithinModule(context + ".getFormula()");
0993             line.setFormula(create(proofLine.getFormula()));
0994         }
0995         if (proofLine.getReason() != null) {
0996             setLocationWithinModule(context + ".getReason()");
0997             line.setReason(create(proofLine.getReason()));
0998         }
0999         setLocationWithinModule(context);
1000         return line;
1001     }
1002 
1003     private final ConditionalProofVo create(final ConditionalProof proofLine) {
1004         if (proofLine == null) {
1005             return null;
1006         }
1007         final ConditionalProofVo line = new ConditionalProofVo();
1008         final String context = getCurrentContext().getLocationWithinModule();
1009         if (proofLine.getHypothesis() != null) {
1010             setLocationWithinModule(context + ".getHypothesis()");
1011             line.setHypothesis(proofLine.getHypothesis());
1012         }
1013         if (proofLine.getFormalProofLineList() != null) {
1014             setLocationWithinModule(context + ".getFormalProofLineList()");
1015             line.setFormalProofLineList(create(proofLine.getFormalProofLineList()));
1016         }
1017         if (proofLine.getConclusion() != null) {
1018             setLocationWithinModule(context + ".getConclusion()");
1019             line.setConclusion(create(proofLine.getConclusion()));
1020         }
1021         setLocationWithinModule(context);
1022         return line;
1023     }
1024 
1025     private final Reason create(final Reason reason) {
1026         if (reason == null) {
1027             return null;
1028         }
1029         final String context = getCurrentContext().getLocationWithinModule();
1030         Reason result = null;
1031         if (reason instanceof ModusPonens) {
1032             setLocationWithinModule(context + ".getModusPonens()");
1033             final ModusPonens r = (ModusPonensreason;
1034             result = new ModusPonensVo(r.getReference1(), r.getReference2());
1035         else if (reason instanceof Add) {
1036             setLocationWithinModule(context + ".getAdd()");
1037             final Add r = (Addreason;
1038             result = new AddVo(r.getReference());
1039         else if (reason instanceof Rename) {
1040             setLocationWithinModule(context + ".getRename()");
1041             final Rename r = (Renamereason;
1042             result = new RenameVo(r.getReference(), r.getOriginalSubjectVariable(),
1043                 r.getReplacementSubjectVariable(), r.getOccurrence());
1044         else if (reason instanceof SubstFree) {
1045             setLocationWithinModule(context + ".getSubstFree()");
1046             final SubstFree r = (SubstFreereason;
1047             result = new SubstFreeVo(r.getReference(), r.getSubjectVariable(),
1048                 r.getSubstituteTerm());
1049         else if (reason instanceof SubstFunc) {
1050             setLocationWithinModule(context + ".getSubstFunc()");
1051             final SubstFunc r = (SubstFuncreason;
1052             result = new SubstFuncVo(r.getReference(), r.getFunctionVariable(),
1053                 r.getSubstituteTerm());
1054         else if (reason instanceof SubstPred) {
1055             setLocationWithinModule(context + ".getSubstPred()");
1056             final SubstPred r = (SubstPredreason;
1057             result = new SubstPredVo(r.getReference(), r.getPredicateVariable(),
1058                 r.getSubstituteFormula());
1059         else if (reason instanceof Existential) {
1060             setLocationWithinModule(context + ".getExistential()");
1061             final Existential r = (Existentialreason;
1062             result = new ExistentialVo(r.getReference(), r.getSubjectVariable());
1063         else if (reason instanceof Universal) {
1064             setLocationWithinModule(context + ".getUniversal()");
1065             final Universal r = (Universalreason;
1066             result = new UniversalVo(r.getReference(), r.getSubjectVariable());
1067         else if (reason instanceof ConditionalProof) {
1068             setLocationWithinModule(context + ".getConditionalProof()");
1069             final ConditionalProof r = (ConditionalProofreason;
1070             setLocationWithinModule(context + ".getConditionalProof().getHypothesis()");
1071             final Hypothesis h = create(r.getHypothesis());
1072             setLocationWithinModule(context + ".getConditionalProof().getFormalProofLineList()");
1073             final FormalProofLineList l = create(r.getFormalProofLineList());
1074             setLocationWithinModule(context + ".getConditionalProof().getConclusion()");
1075             final Conclusion c = create(r.getConclusion());
1076             result = new ConditionalProofVo(h, l, c);
1077         else {
1078             throw new RuntimeException("unknown reason class: " + reason.getClass());
1079         }
1080         setLocationWithinModule(context);
1081         return result;
1082     }
1083 
1084     private final HypothesisVo create(final Hypothesis hypothesis) {
1085         if (hypothesis == null) {
1086             return null;
1087         }
1088         final HypothesisVo h = new HypothesisVo();
1089         final String context = getCurrentContext().getLocationWithinModule();
1090         if (hypothesis.getLabel() != null) {
1091             h.setLabel(hypothesis.getLabel());
1092         }
1093         if (hypothesis.getFormula() != null) {
1094             setLocationWithinModule(context + ".getFormula()");
1095             h.setFormula(create(hypothesis.getFormula()));
1096         }
1097         setLocationWithinModule(context);
1098         return h;
1099     }
1100 
1101     private final ConclusionVo create(final Conclusion conclusion) {
1102         if (conclusion == null) {
1103             return null;
1104         }
1105         final ConclusionVo c = new ConclusionVo();
1106         final String context = getCurrentContext().getLocationWithinModule();
1107         if (conclusion.getLabel() != null) {
1108             c.setLabel(conclusion.getLabel());
1109         }
1110         if (conclusion.getFormula() != null) {
1111             setLocationWithinModule(context + ".getFormula()");
1112             c.setFormula(create(conclusion.getFormula()));
1113         }
1114         setLocationWithinModule(context);
1115         return c;
1116     }
1117 
1118     private final FormulaVo create(final Formula formula) {
1119         if (formula == null) {
1120             return null;
1121         }
1122         final FormulaVo f = new FormulaVo();
1123         final String context = getCurrentContext().getLocationWithinModule();
1124         if (formula.getElement() != null) {
1125             setLocationWithinModule(context + ".getElement()");
1126             f.setElement(create(formula.getElement()));
1127         }
1128         setLocationWithinModule(context);
1129         return f;
1130     }
1131 
1132     private final Element create(final Element element) {
1133         if (element == null) {
1134             return null;
1135         }
1136         final Element e;
1137         final String context = getCurrentContext().getLocationWithinModule();
1138         if (element.isList()) {
1139             setLocationWithinModule(context + ".getList()");
1140             e =  create(element.getList());
1141         else if (element.isAtom()) {
1142 //            setLocationWithinModule(context + ".getAtom()");
1143             return create(element.getAtom());
1144         else {
1145             throw new RuntimeException("unknown element type: " + element);
1146         }
1147         setLocationWithinModule(context);
1148         return e;
1149     }
1150 
1151 
1152     private final DefaultElementList create(final ElementList list) {
1153         if (list == null) {
1154             return null;
1155         }
1156         final DefaultElementList n = new DefaultElementList(list.getOperator()new Element[] {});
1157         final String context = getCurrentContext().getLocationWithinModule();
1158         for (int i = 0; i < list.size(); i++) {
1159             if (list.getElement(i).isList()) {
1160                 setLocationWithinModule(context + ".getElement(" + i + ")");
1161             }
1162             n.add(create(list.getElement(i)));
1163         }
1164         setLocationWithinModule(context);
1165         return n;
1166     }
1167 
1168     private final DefaultAtom create(final Atom atom) {
1169         if (atom == null) {
1170             return null;
1171         }
1172         return new DefaultAtom(atom.getString());
1173     }
1174 
1175     private final LatexListVo create(final LatexList latexList) {
1176         if (latexList == null) {
1177             return null;
1178         }
1179         final LatexListVo list = new LatexListVo();
1180         final String context = getCurrentContext().getLocationWithinModule();
1181         for (int i = 0; i < latexList.size(); i++) {
1182             setLocationWithinModule(context + ".get(" + i + ")");
1183             list.add(create(latexList.get(i)));
1184         }
1185         setLocationWithinModule(context);
1186         return list;
1187     }
1188 
1189     /**
1190      * Creates LaTeX business object.
1191      *
1192      @param   latex   LaTeX object.
1193      @return  LaTeX business object.
1194      */
1195     private final LatexVo create(final Latex latex) {
1196         if (latex == null) {
1197             return null;
1198         }
1199         final LatexVo lat = new LatexVo();
1200         lat.setLanguage(latex.getLanguage());
1201         lat.setLatex(latex.getLatex());
1202         return lat;
1203     }
1204 
1205     /**
1206      * Set location information where are we within the original module.
1207      *
1208      @param   locationWithinModule    Location within module.
1209      */
1210     protected void setLocationWithinModule(final String locationWithinModule) {
1211         getCurrentContext().setLocationWithinModule(locationWithinModule);
1212     }
1213 
1214     /**
1215      * Get current context within original.
1216      *
1217      @return  Current context.
1218      */
1219     protected final ModuleContext getCurrentContext() {
1220         return currentContext;
1221     }
1222 
1223     /**
1224      * Get original QEDEQ module.
1225      *
1226      @return  Original QEDEQ module.
1227      */
1228     protected final Qedeq getQedeqOriginal() {
1229         return original;
1230     }
1231 
1232 }