001 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
002 *
003 * Copyright 2000-2013, Michael Meyling <mime@qedeq.org>.
004 *
005 * "Hilbert II" is free software; you can redistribute
006 * it and/or modify it under the terms of the GNU General Public
007 * License as published by the Free Software Foundation; either
008 * version 2 of the License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU General Public License for more details.
014 */
015
016 package org.qedeq.kernel.bo.service;
017
018 import org.qedeq.base.trace.Trace;
019 import org.qedeq.kernel.bo.module.ControlVisitor;
020 import org.qedeq.kernel.bo.module.KernelModuleReferenceList;
021 import org.qedeq.kernel.bo.module.KernelQedeqBo;
022 import org.qedeq.kernel.se.base.module.Import;
023 import org.qedeq.kernel.se.base.module.ImportList;
024 import org.qedeq.kernel.se.common.ModuleContext;
025 import org.qedeq.kernel.se.common.ModuleDataException;
026 import org.qedeq.kernel.se.common.Plugin;
027 import org.qedeq.kernel.se.common.SourceFileExceptionList;
028
029
030 /**
031 * Load all required QEDEQ modules.
032 *
033 * @author Michael Meyling
034 */
035 public final class LoadDirectlyRequiredModules extends ControlVisitor {
036
037 /** This class. */
038 private static final Class CLASS = LoadDirectlyRequiredModules.class;
039
040 /** List of required QEDEQ modules. */
041 private final KernelModuleReferenceList required;
042
043 /**
044 * Constructor.
045 *
046 * @param plugin Plugin we work for.
047 * @param prop Internal QedeqBo.
048 */
049 LoadDirectlyRequiredModules(final Plugin plugin, final KernelQedeqBo prop) {
050 super(plugin, prop);
051 this.required = new KernelModuleReferenceList();
052 }
053
054 /**
055 * Load all directly imported QEDEQ modules for a given QEDEQ module.
056 *
057 * @return List of all directly imported QEDEQ modules.
058 * @throws SourceFileExceptionList Failure(s).
059 */
060 KernelModuleReferenceList load()
061 throws SourceFileExceptionList {
062 traverse();
063 return required;
064 }
065
066 /**
067 * Get list of directly referenced modules.
068 *
069 * @return List of directly required modules.
070 */
071 KernelModuleReferenceList getRequired() {
072 return required;
073 }
074
075 /**
076 * Visit import. Loads referenced QEDEQ module and saves reference.
077 *
078 * @param imp Begin visit of this element.
079 * @throws ModuleDataException Major problem occurred.
080 */
081 public void visitEnter(final Import imp) throws ModuleDataException {
082 final ModuleContext context = getCurrentContext();
083 context.setLocationWithinModule(context.getLocationWithinModule() + ".getLabel()");
084 try {
085 final KernelQedeqBo propNew = getQedeqBo().getKernelServices().loadModule(
086 getQedeqBo().getModuleAddress(), imp.getSpecification());
087 getRequired().addLabelUnique(context, imp.getLabel(), propNew);
088 Trace.param(CLASS, "visitEnter(Import)", "adding context", getCurrentContext());
089 } catch (SourceFileExceptionList e) {
090 final ModuleDataException me = new LoadRequiredModuleException(e.get(0).getErrorCode(),
091 "import of module with label \"" + imp.getLabel() + "\" failed: "
092 + e.get(0).getMessage(), context);
093 // TODO mime 20080227: also include reference area in sf creation?
094 addError(me);
095 Trace.trace(CLASS, this, "visitEnter(Import)", e);
096 }
097 }
098
099 /**
100 * End of visit of import list. Blocks further visits.
101 *
102 * @param imports This visit has just ended.
103 */
104 public void visitLeave(final ImportList imports) {
105 setBlocked(true); // block further traverse
106 }
107
108 }
|