+ protected synchronized Object retrieveStep(DetachedRequest request)
+ throws Exception {
+
+ // Check whether there is a cached object
+ if (request.getCachedObject() != null) {
+ Object cachedObj = request.getCachedObject();
+ if (log.isTraceEnabled())
+ log.trace("Use cached object " + cachedObj + " for request "
+ + request);
+ return cachedObj;
+ }
+
+ // Check its own app context (typically for admin steps)
+ if (applicationContext.containsBean(request.getRef())) {
+ try {
+ Object obj = applicationContext.getBean(request.getRef());
+ if (log.isTraceEnabled())
+ log.trace("Retrieve from server app context " + obj
+ + " for request " + request);
+ return obj;
+ } catch (Exception e) {
+ if (log.isTraceEnabled())
+ log.trace("Could not retrieve " + request.getRef()
+ + " from server app context: " + e);
+ }
+ }
+
+ // Check whether the source bundle is set
+ String bundleName = request.getProperties().getProperty(
+ Constants.BUNDLE_SYMBOLICNAME);
+
+ ApplicationContext sourceAppContext = null;
+ if (bundleName != null) {
+ if (!appContextServiceTrackers.containsKey(bundleName)) {
+ ServiceTracker nSt = new ServiceTracker(bundleContext,
+ bundleContext.createFilter("(Bundle-SymbolicName="
+ + bundleName + ")"), null);
+ nSt.open();
+ appContextServiceTrackers.put(bundleName, nSt);
+ }
+ ServiceTracker st = (ServiceTracker) appContextServiceTrackers
+ .get(bundleName);
+ sourceAppContext = (ApplicationContext) st.getService();
+ if (log.isTraceEnabled())
+ log.trace("Use source application context from bundle "
+ + bundleName);
+
+ Object obj = null;
+ try {
+ obj = sourceAppContext.getBean(request.getRef());
+ } catch (Exception e) {
+ if (log.isTraceEnabled())
+ log.trace("Could not retrieve " + request.getRef()
+ + " from app context of " + bundleName + ": " + e);
+ }
+ return obj;
+ }
+
+ // 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());
+ }
+
+ protected synchronized DetachedAnswer processStep(DetachedStep obj,