| /** |
| * |
| * 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.xtext.reportdsl.oda.datamart; |
| |
| import java.util.HashSet; |
| import java.util.Set; |
| |
| import org.eclipse.osbp.utils.classloader.IClassLoader; |
| import org.osgi.service.component.annotations.Component; |
| import org.osgi.service.component.annotations.Reference; |
| import org.osgi.service.component.annotations.ReferenceCardinality; |
| import org.osgi.service.component.annotations.ReferencePolicy; |
| |
| |
| @Component |
| public class ServiceListener { |
| |
| private static final Set<IClassLoader> sClassLoaderServices = new HashSet<IClassLoader>(); |
| |
| /** |
| * @param className |
| * @return reloaded class via declarative services |
| */ |
| public static Class<?> reloadClass(String className) { |
| Class<?> reloadedClass = null; |
| for (IClassLoader classLoader : sClassLoaderServices) { |
| reloadedClass = classLoader.reloadClass(className); |
| if (reloadedClass != null) { |
| return reloadedClass; |
| } |
| } |
| return null; |
| } |
| |
| /** |
| * @param classLoaderService declarative service loaded |
| */ |
| @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC) |
| public static void bindClassLoaderService(IClassLoader classLoaderService) { |
| System.err.println(ServiceListener.class.getCanonicalName()+": "+classLoaderService.getClass().getCanonicalName()+" bound"); |
| sClassLoaderServices.add(classLoaderService); |
| } |
| |
| /** |
| * @param classLoaderService declarative service unloaded |
| */ |
| public static void unbindClassLoaderService(IClassLoader classLoaderService) { |
| System.err.println(ServiceListener.class.getCanonicalName()+": "+classLoaderService.getClass().getCanonicalName()+" unbound"); |
| sClassLoaderServices.remove(classLoaderService); |
| } |
| |
| } |