cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1166226 - /cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/OSGiExtensionLocator.java
Date Wed, 07 Sep 2011 15:28:20 GMT
Author: dkulp
Date: Wed Sep  7 15:28:20 2011
New Revision: 1166226

URL: http://svn.apache.org/viewvc?rev=1166226&view=rev
Log:
When running in OSGi, you could create a non-osgi associated bus.
Don't NPE in that case.

Modified:
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/OSGiExtensionLocator.java

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/OSGiExtensionLocator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/OSGiExtensionLocator.java?rev=1166226&r1=1166225&r2=1166226&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/OSGiExtensionLocator.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/OSGiExtensionLocator.java Wed
Sep  7 15:28:20 2011
@@ -142,7 +142,6 @@ public class OSGiExtensionLocator implem
         public static final String CONTEXT_NAME_PROPERTY = "cxf.bus.id";
         
         Bus bus;
-        BundleContext context;
         ServiceRegistration service;
  
         public OSGIBusListener(Bus b) {
@@ -156,19 +155,23 @@ public class OSGiExtensionLocator implem
         }
  
         public void initComplete() {
-            context = bus.getExtension(BundleContext.class);
-            Properties props = new Properties();
-            props.put(CONTEXT_SYMBOLIC_NAME_PROPERTY, context.getBundle().getSymbolicName());
-            props.put(CONTEXT_VERSION_PROPERTY, getBundleVersion(context.getBundle()));
-            props.put(CONTEXT_NAME_PROPERTY, bus.getId());
-
-            service = context.registerService(Bus.class.getName(), bus, props);
+            BundleContext context = bus.getExtension(BundleContext.class);
+            if (context != null) {
+                Properties props = new Properties();
+                props.put(CONTEXT_SYMBOLIC_NAME_PROPERTY, context.getBundle().getSymbolicName());
+                props.put(CONTEXT_VERSION_PROPERTY, getBundleVersion(context.getBundle()));
+                props.put(CONTEXT_NAME_PROPERTY, bus.getId());
+    
+                service = context.registerService(Bus.class.getName(), bus, props);
+            }
         }
         public void preShutdown() {
         }
         public void postShutdown() {
-            service.unregister();
-            service = null;
+            if (service != null) {
+                service.unregister();
+                service = null;
+            }
         }
     }
     



Mime
View raw message