| /******************************************************************************* |
| * 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, |
| * Sebastien Gemme - initial API and implementation |
| * |
| * SPDX-License-Identifier: EPL-1.0 |
| * |
| *******************************************************************************/ |
| package org.eclipse.apogy.core; |
| |
| import java.util.ArrayList; |
| import java.util.List; |
| |
| import org.eclipse.core.runtime.IConfigurationElement; |
| import org.eclipse.core.runtime.IExtensionPoint; |
| import org.eclipse.core.runtime.Platform; |
| import org.eclipse.emf.common.util.URI; |
| import org.slf4j.Logger; |
| import org.slf4j.LoggerFactory; |
| |
| public class WorksiteContributorsRegistry { |
| private static final Logger Logger = LoggerFactory.getLogger(WorksiteContributorsRegistry.class); |
| |
| public static final String WORKSITE_CONTRIBUTORS_POINT_ID = "org.eclipse.apogy.core.worksiteProvider"; |
| public static final String WORKSITE_CONTRIBUTORS_NAME_ID = "Name"; |
| public static final String WORKSITE_CONTRIBUTORS_DESCRIPTION_ID = "Description"; |
| public static final String WORKSITE_CONTRIBUTORS_URI_ID = "URI"; |
| |
| private List<WorksiteContributor> registeredWorksiteProviders = null; |
| |
| public WorksiteContributorsRegistry() { |
| } |
| |
| public List<WorksiteContributor> getRegisteredWorksiteProviders() { |
| if (this.registeredWorksiteProviders == null) { |
| this.registeredWorksiteProviders = new ArrayList<WorksiteContributor>(); |
| |
| IExtensionPoint extensionPoint = Platform.getExtensionRegistry() |
| .getExtensionPoint(WORKSITE_CONTRIBUTORS_POINT_ID); |
| |
| IConfigurationElement[] contributors = extensionPoint.getConfigurationElements(); |
| |
| for (int i = 0; i < contributors.length; i++) { |
| IConfigurationElement contributor = contributors[i]; |
| |
| try { |
| String name = contributor.getAttribute(WORKSITE_CONTRIBUTORS_NAME_ID); |
| String description = contributor.getAttribute(WORKSITE_CONTRIBUTORS_DESCRIPTION_ID); |
| String uriString = contributor.getAttribute(WORKSITE_CONTRIBUTORS_URI_ID); |
| |
| URI uri = URI.createURI( |
| "platform:/plugin/" + contributor.getNamespaceIdentifier() + "/" + uriString, true); |
| |
| WorksiteContributor sessionContributor = new WorksiteContributor(name, description, uri); |
| this.registeredWorksiteProviders.add(sessionContributor); |
| } catch (Exception e) { |
| Logger.error(e.getMessage(), e); |
| } |
| } |
| |
| Logger.debug("Worksite Contributors :"); |
| for (WorksiteContributor worksiteContributor : this.registeredWorksiteProviders) { |
| Logger.debug("\t Name : " + worksiteContributor.name); |
| Logger.debug("\t Description : " + worksiteContributor.description); |
| Logger.debug("\t URI : " + worksiteContributor.uri); |
| } |
| Logger.info("Found <" + this.registeredWorksiteProviders.size() + "> registered Worksite Providers."); |
| } |
| |
| return this.registeredWorksiteProviders; |
| } |
| } |