blob: 8fb8a6fa389c35fd5c99bd72bb6f5acd45cb3196 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2018 Agence spatiale canadienne / Canadian Space Agency
* 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:
* Pierre Allard,
* Regent L'Archeveque,
* Olivier L. Larouche - initial API and implementation
*
* SPDX-License-Identifier: EPL-1.0
*
*******************************************************************************/
package org.eclipse.apogy.core.invocator.impl;
import java.util.HashMap;
import org.eclipse.apogy.common.emf.ApogyCommonEMFFacade;
import org.eclipse.apogy.core.invocator.ProgramFactory;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.ecore.EClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ProgramFactoriesRegistryCustomImpl extends ProgramFactoriesRegistryImpl {
private static final Logger Logger = LoggerFactory.getLogger(ProgramFactoriesRegistryImpl.class);
public HashMap<EClass, ProgramFactory> getProgramFactoriesMap() {
HashMap<EClass, ProgramFactory> map = super.getProgramFactoriesMap();
if (this.programFactoriesMap == null) {
map = new HashMap<EClass, ProgramFactory>();
IExtensionPoint extensionPoint = Platform.getExtensionRegistry()
.getExtensionPoint(getPROGRAM_FACTORY_PROVIDER_CONTRIBUTORS_POINT_ID());
IConfigurationElement[] contributors = extensionPoint.getConfigurationElements();
for (int i = 0; i < contributors.length; i++) {
IConfigurationElement contributor = contributors[i];
try {
String eClassStr = contributor.getAttribute(getPROGRAM_FACTORY_PROVIDER_CONTRIBUTORS_ECLASS_ID());
EClass eClass = ApogyCommonEMFFacade.INSTANCE.getEClass(eClassStr);
ProgramFactory programFactory = (ProgramFactory) contributor
.createExecutableExtension(getPROGRAM_FACTORY_PROVIDER_CONTRIBUTORS_FACTORY_ID());
map.put(eClass, programFactory);
} catch (Exception e) {
Logger.error(
"Failed to load contributed ProgramFactory from <" + contributor.getClass().getName() + ">",
e);
}
}
setProgramFactoriesMap(map);
}
return map;
}
public ProgramFactory getFactory(EClass eClass) {
return getProgramFactoriesMap().get(eClass);
}
} // ProgramFactoriesRegistryImpl