Author: ogrisel
Date: Mon Apr  4 00:13:32 2011
New Revision: 1088454

URL: http://svn.apache.org/viewvc?rev=1088454&view=rev
Log:
STANBOL-120: better handling of unregistration of web fragments

Modified:
    
incubator/stanbol/branches/http-endpoint-refactoring/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/JerseyEndpoint.java

Modified: 
incubator/stanbol/branches/http-endpoint-refactoring/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/JerseyEndpoint.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/branches/http-endpoint-refactoring/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/JerseyEndpoint.java?rev=1088454&r1=1088453&r2=1088454&view=diff
==============================================================================
--- 
incubator/stanbol/branches/http-endpoint-refactoring/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/JerseyEndpoint.java
 (original)
+++ 
incubator/stanbol/branches/http-endpoint-refactoring/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/JerseyEndpoint.java
 Mon Apr  4 00:13:32 2011
@@ -67,9 +67,14 @@ public class JerseyEndpoint {
 
     @Activate
     protected void activate(ComponentContext ctx) throws IOException, 
ServletException, NamespaceException {
+        if (webFragments.isEmpty()) {
+            // nothing to activate
+            return;
+        }
+        
         this.componentContext = ctx;
         this.registeredAliases = new ArrayList<String>();
-
+        
         // register all the JAX-RS resources into a a JAX-RS application and 
bind it to a configurable URL
         // prefix
         JerseyEndpointApplication app = new JerseyEndpointApplication();
@@ -124,6 +129,7 @@ public class JerseyEndpoint {
             httpService.unregister(alias);
         }
         servletContext = null;
+        componentContext = null;
     }
 
     protected void bindHttpService(HttpService httpService) {
@@ -140,8 +146,9 @@ public class JerseyEndpoint {
         // TODO: support some ordering for jax-rs resource and template 
overrides?
         webFragments.add(webFragment);
         if (componentContext != null) {
-            deactivate(componentContext);
-            activate(componentContext);
+            ComponentContext oldContext = componentContext;
+            deactivate(oldContext);
+            activate(oldContext);
         }
     }
 
@@ -150,8 +157,9 @@ public class JerseyEndpoint {
                                                              
NamespaceException {
         webFragments.remove(webFragment);
         if (componentContext != null) {
-            deactivate(componentContext);
-            activate(componentContext);
+            ComponentContext oldContext = componentContext;
+            deactivate(oldContext);
+            activate(oldContext);
         }
     }
 


Reply via email to