blob: 2a92ccb591bff61eb64747c3c69cd537c92671f5 [file] [log] [blame]
/**
*
* Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
*/
package org.eclipse.osbp.utils.common;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.xtext.resource.IEObjectDescription;
import org.eclipse.xtext.resource.XtextResourceSet;
import org.eclipse.osbp.utils.classloader.IEObjectLoader;
public class ServiceListener {
private static final Set<IEObjectLoader> sEObjectLoaderServices = new HashSet<IEObjectLoader>();
public static XtextResourceSet getConfiguredXtextResourceFor(EClass eClass, String qualifiedName) {
XtextResourceSet xtextResourceSet = null;
for (IEObjectLoader eObjectLoader : sEObjectLoaderServices) {
xtextResourceSet = eObjectLoader.getConfiguredXtextResourceFor(eClass, qualifiedName);
if (xtextResourceSet != null) {
return xtextResourceSet;
}
}
return null;
}
public static Iterable<IEObjectDescription> getEObjectDescriptions(EClass eClass, String qualifiedName) {
Iterable<IEObjectDescription> eObjectDescriptions = null;
for (IEObjectLoader eObjectLoader : sEObjectLoaderServices) {
eObjectDescriptions = eObjectLoader.getEObjectDescriptions(eClass, qualifiedName);
if (eObjectDescriptions != null) {
return eObjectDescriptions;
}
}
return null;
}
/**
* @param eObjectLoaderService declarative service loaded
*/
public static void bindEObjectLoaderService(IEObjectLoader eObjectLoaderService) {
System.err.println(ServiceListener.class.getCanonicalName()+": "+eObjectLoaderService.getClass().getCanonicalName()+" bound");
sEObjectLoaderServices.add(eObjectLoaderService);
}
/**
* @param eObjectLoaderService declarative service unloaded
*/
public static void unbindEObjectLoaderService(IEObjectLoader eObjectLoaderService) {
System.err.println(ServiceListener.class.getCanonicalName()+": "+eObjectLoaderService.getClass().getCanonicalName()+" unbound");
sEObjectLoaderServices.remove(eObjectLoaderService);
}
}