- getCurrentSession().getRequests().add(request);
- getCurrentSession().getAnswers().add(answer);
- log.info("Sent answer " + answer);
- return answer;
+ // no bundle name specified or it failed
+ if (!appContextServiceTrackers.containsKey(ALL_APP_CONTEXTS_KEY)) {
+ ServiceTracker nSt = new ServiceTracker(bundleContext,
+ ApplicationContext.class.getName(), null);
+ nSt.open();
+ appContextServiceTrackers.put(ALL_APP_CONTEXTS_KEY, nSt);
+ }
+ ServiceTracker st = (ServiceTracker) appContextServiceTrackers
+ .get(ALL_APP_CONTEXTS_KEY);
+ Object[] arr = st.getServices();
+ for (int i = 0; i < arr.length; i++) {
+ ApplicationContext appC = (ApplicationContext) arr[i];
+ if (appC.containsBean(request.getRef())) {
+ sourceAppContext = appC;
+ if (log.isTraceEnabled())
+ log
+ .trace("Retrieved source application context "
+ + "by scanning all published application contexts.");
+ try {
+ Object obj = sourceAppContext.getBean(request.getRef());
+ return obj;
+ } catch (Exception e) {
+ if (log.isTraceEnabled())
+ log.trace("Could not retrieve " + request.getRef()
+ + " from app context " + appC + ": " + e);
+ }
+ }
+ }
+
+ throw new Exception(
+ "Cannot find any published application context containing bean "
+ + request.getRef());