From 80f02ef1e708ae3fe18dd649ee6493ebae205fa7 Mon Sep 17 00:00:00 2001 From: apoltavtsev Date: Tue, 10 Nov 2020 15:58:06 +0100 Subject: [PATCH] feat(TESB-29949) Pass the data source to a job using a context variable --- .../java/routines/system/BundleUtils.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/main/plugins/org.talend.librariesmanager/resources/java/routines/system/BundleUtils.java b/main/plugins/org.talend.librariesmanager/resources/java/routines/system/BundleUtils.java index e0bac051aa..4cbf73d375 100644 --- a/main/plugins/org.talend.librariesmanager/resources/java/routines/system/BundleUtils.java +++ b/main/plugins/org.talend.librariesmanager/resources/java/routines/system/BundleUtils.java @@ -13,6 +13,9 @@ package routines.system; import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.List; +import java.util.Map; public final class BundleUtils { @@ -75,6 +78,31 @@ public final class BundleUtils { return null; } } + + public static Map getServices(List serviceReferences, Class serviceClass ) { + + Map services = new HashMap(); + + if (BUNDLE == null || SERVICE_REFERENCE_CLASS == null ) { + return services; + } + + try { + for (Object serviceRef : serviceReferences) { + Object serviceId = serviceRef.getClass().getMethod("getProperty", + java.lang.String.class).invoke(serviceRef, "osgi.jndi.service.name"); + Method getBundleContext = BUNDLE.getClass().getMethod("getBundleContext"); + Object context = getBundleContext.invoke(BUNDLE); + Class ctxClass = context.getClass(); + Method getService = ctxClass.getMethod("getService", SERVICE_REFERENCE_CLASS); + services.put(serviceId.toString(), serviceClass.cast(getService.invoke(context, serviceRef))); + } + return services; + } catch (Exception e) { + return services; + } + } + public static boolean inOSGi() { return BUNDLE != null;