You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by no...@apache.org on 2011/03/09 20:15:26 UTC

svn commit: r1079946 - /aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/OBRCapability.java

Author: not
Date: Wed Mar  9 19:15:25 2011
New Revision: 1079946

URL: http://svn.apache.org/viewvc?rev=1079946&view=rev
Log:
ARIES-604 Fix our OBR generator so it can cope with String[]. This is a nasty hack, but it does work.

Modified:
    aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/OBRCapability.java

Modified: aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/OBRCapability.java
URL: http://svn.apache.org/viewvc/aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/OBRCapability.java?rev=1079946&r1=1079945&r2=1079946&view=diff
==============================================================================
--- aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/OBRCapability.java (original)
+++ aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/OBRCapability.java Wed Mar  9 19:15:25 2011
@@ -23,13 +23,18 @@ package org.apache.aries.application.res
 import static org.apache.aries.application.utils.AppConstants.LOG_ENTRY;
 import static org.apache.aries.application.utils.AppConstants.LOG_EXIT;
 
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.aries.application.modelling.Provider;
 import org.apache.felix.bundlerepository.Capability;
+import org.apache.felix.bundlerepository.DataModelHelper;
 import org.apache.felix.bundlerepository.Property;
 import org.apache.felix.bundlerepository.RepositoryAdmin;
+import org.osgi.framework.Constants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -75,9 +80,66 @@ public class OBRCapability implements Ca
   public Property[] getProperties()
   {
     logger.debug(LOG_ENTRY, "getProperties");
-    Property[] props = repositoryAdmin.getHelper().capability(getName(), _props).getProperties();
-    logger.debug(LOG_EXIT, "getProperties", props);
-    return props;
+    DataModelHelper helper = repositoryAdmin.getHelper();
+    
+    List<Property> properties = new ArrayList<Property>();
+    
+    // Felix BundleRepository doesn't appear to correctly cope with String[] value properties
+    // as a result we can't do multi value service properties. OBR doesn't really like implementations
+    // of its interfaces that it didn't generate, but it is a little weird when it does and doesn't.
+    // so we create a Property implemenation which we use to generate the OBR xml for a property which
+    // we then get OBR to parse. This is really convoluted and nasty.
+    for (final Map.Entry<String, Object> entry : _props.entrySet()) {
+      String propXML = helper.writeProperty(new Property() {
+        @Override
+        public String getValue()
+        {
+          Object value = entry.getValue();
+          
+          if (value instanceof String[]) {
+            String newValue = Arrays.toString((String[])value);
+            value = newValue.substring(1, newValue.length() - 1);
+          }
+          
+          return String.valueOf(value);
+        }
+        
+        @Override
+        public String getType()
+        {
+          String name = entry.getKey();
+          String type = null;
+          if (Constants.VERSION_ATTRIBUTE.equals(name) || (Constants.BUNDLE_VERSION_ATTRIBUTE.equals(name))) {
+            type =  "version";
+          } else if (Constants.OBJECTCLASS.equals(name) || (Constants.MANDATORY_DIRECTIVE + ":").equals(name) ||
+              entry.getValue() instanceof String[])
+            type = "set";
+          return type;
+        }
+        
+        @Override
+        public String getName()
+        {
+          return entry.getKey();
+        }
+        
+        @Override
+        public Object getConvertedValue()
+        {
+          return null;
+        }
+      });
+      
+      try {
+        properties.add(helper.readProperty(propXML));
+      } catch (Exception e) {
+        // Do nothing and hope it OBR doesn't generate XML it can't parse.
+      }
+    }
+    
+    
+    logger.debug(LOG_EXIT, "getProperties", properties);
+    return properties.toArray(new Property[properties.size()]);
   }
 
   public Map getPropertiesAsMap()