FELIX-4852 ; Unbinding configuration does not have desired effect

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1690656 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigAdminSupport.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigAdminSupport.java
index 3d4a343..51cffcd 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigAdminSupport.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigAdminSupport.java
@@ -70,7 +70,7 @@
         CONFIG_PROPERTIES_HIDE.add(PROPERTY_FACTORYCONFIG_NAMEHINT);
     }
     private static final Pattern NAMEHINT_PLACEHOLER_REGEXP = Pattern.compile("\\{([^\\{\\}]*)}");
-    
+
     private final BundleContext bundleContext;
     private final ConfigurationAdmin service;
 
@@ -311,7 +311,7 @@
             }
 
             final String location = request.getParameter(ConfigManager.LOCATION);
-            if ( location == null || location.trim().length() == 0 )
+            if ( location == null || location.trim().length() == 0 || ConfigManager.UNBOUND_LOCATION.equals(location) )
             {
                 if ( config.getBundleLocation() != null )
                 {
@@ -451,8 +451,13 @@
             json.value( config.getFactoryPid() );
         }
 
+        String bundleLocation = config.getBundleLocation();
+        if ( ConfigManager.UNBOUND_LOCATION.equals(bundleLocation) )
+        {
+            bundleLocation = null;
+        }
         String location;
-        if ( config.getBundleLocation() == null )
+        if ( bundleLocation == null )
         {
             location = ""; //$NON-NLS-1$
         }
@@ -461,10 +466,10 @@
             // if the configuration is bound to a bundle location which
             // is not related to an installed bundle, we just print the
             // raw bundle location binding
-            Bundle bundle = MetaTypeServiceSupport.getBundle( this.getBundleContext(), config.getBundleLocation() );
+            Bundle bundle = MetaTypeServiceSupport.getBundle( this.getBundleContext(), bundleLocation );
             if ( bundle == null )
             {
-                location = config.getBundleLocation();
+                location = bundleLocation;
             }
             else
             {
@@ -504,7 +509,7 @@
             configManager.log( "Error getting service associated with configuration " + pid, t );
         }
         json.key( "bundle_location" ); //$NON-NLS-1$
-        json.value ( config.getBundleLocation() );
+        json.value ( bundleLocation );
         json.key( "service_location" ); //$NON-NLS-1$
         json.value ( serviceLocation );
     }
@@ -638,7 +643,7 @@
         {
             return null;
         }
-        
+
         // search for all variable patterns in name hint and replace them with configured/default values
         Matcher matcher = NAMEHINT_PLACEHOLER_REGEXP.matcher(nameHint);
         StringBuffer sb = new StringBuffer();
@@ -652,7 +657,7 @@
             matcher.appendReplacement(sb, matcherQuoteReplacement(value));
         }
         matcher.appendTail(sb);
-        
+
         // make sure name hint does not only contain whitespaces
         nameHint = sb.toString().trim();
         if (nameHint.length() == 0) {
@@ -662,7 +667,7 @@
             return nameHint;
         }
     }
-    
+
     /**
      * Gets configured service property value, or default value if no value is configured.
      * @param propertyName Property name
@@ -673,7 +678,7 @@
     private static String getConfigurationPropertyValueOrDefault(String propertyName, Dictionary props, Map adMap) {
         // get configured property value
         Object value = props.get(propertyName);
-        
+
         if (value != null)
         {
             // if set convert to string
@@ -701,10 +706,10 @@
                 return ad.getDefaultValue()[0];
             }
         }
-        
+
         return null;
     }
-    
+
     /**
      * Replacement for Matcher.quoteReplacement which is only available in JDK 1.5 and up.
      * @param str Unquoted string
@@ -722,7 +727,7 @@
         }
         return sb.toString();
     }
-    
+
     final void listFactoryConfigurations(JSONObject json, String pidFilter,
         String locale)
     {
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigManager.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigManager.java
index bc7c69c..f6154ff 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigManager.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigManager.java
@@ -64,6 +64,8 @@
     static final String CONFIGURATION_ADMIN_NAME = "org.osgi.service.cm.ConfigurationAdmin"; //$NON-NLS-1$
     static final String META_TYPE_NAME = "org.osgi.service.metatype.MetaTypeService"; //$NON-NLS-1$
 
+    public static final String UNBOUND_LOCATION = "??unbound:bundle/location";
+
     // templates
     private final String TEMPLATE;
 
@@ -182,17 +184,8 @@
         {
             if ( config != null && config.getBundleLocation() != null )
             {
-                config.setBundleLocation( null );
+                config.setBundleLocation( UNBOUND_LOCATION ); //$NON-NLS-1$
 
-                // workaround for Felix Config Admin 1.2.8 not clearing dynamic
-                // bundle location when clearing static bundle location. In
-                // this case we first set the static bundle location to the
-                // dynamic bundle location and then try to set both to null
-                if ( config.getBundleLocation() != null )
-                {
-                    config.setBundleLocation( "??invalid:bundle/location" ); //$NON-NLS-1$
-                    config.setBundleLocation( null );
-                }
             }
             response.setContentType( "application/json" ); //$NON-NLS-1$
             response.setCharacterEncoding( "UTF-8" ); //$NON-NLS-1$