/** * Copyright (c) 2012-2016 Marsha Chechik, Alessio Di Sandro, Michalis Famelis, * Rick Salay. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Alessio Di Sandro - Implementation. */ package edu.toronto.cs.se.mmint.extensions; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtension; import org.eclipse.core.runtime.IStatus; import edu.toronto.cs.se.mmint.MMINT; import edu.toronto.cs.se.mmint.MMINTException; import edu.toronto.cs.se.mmint.MIDTypeRegistry; import edu.toronto.cs.se.mmint.mid.operator.Operator; /** * A listener for dynamic installation/unistallation of extensions to the * Operators extension point. * * @author Alessio Di Sandro * */ public class OperatorExtensionPointListener extends MMINTExtensionPointListener { /** * {@inheritDoc} * Installs a new Operators extension. */ @Override public void added(IExtension[] extensions) { IConfigurationElement[] configs; for (IExtension extension : extensions) { configs = extension.getConfigurationElements(); for (IConfigurationElement config : configs) { try { MMINT.createOperatorType(config); } catch (MMINTException e) { MMINTException.print(IStatus.ERROR, "Operator type can't be created in " + config.getContributor().getName(), e); } } } MMINT.storeTypeMID(); } /** * {@inheritDoc} * Uninstalls an Operators extension. */ @Override public void removed(IExtension[] extensions) { IConfigurationElement[] configs; for (IExtension extension : extensions) { configs = extension.getConfigurationElements(); for (IConfigurationElement config : configs) { String uri = config.getAttribute(MMINT.TYPE_ATTR_URI); Operator operatorType = MIDTypeRegistry.getType(uri); if (operatorType != null) { try { operatorType.deleteType(); } catch (MMINTException e) { // never happens by construction } } } } MMINT.storeTypeMID(); } }