[FELIX-4525] Fix problem with DTO containing unsupported values
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1667221 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/DTOFactory.java b/framework/src/main/java/org/apache/felix/framework/DTOFactory.java
index 99cb8e7..3fba318 100644
--- a/framework/src/main/java/org/apache/felix/framework/DTOFactory.java
+++ b/framework/src/main/java/org/apache/felix/framework/DTOFactory.java
@@ -25,8 +25,8 @@
import java.util.Map;
import java.util.Set;
+import org.osgi.dto.DTO;
import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
@@ -357,7 +357,7 @@
private static FrameworkDTO createFrameworkDTO(Felix framework)
{
FrameworkDTO dto = new FrameworkDTO();
- dto.properties = framework.getConfig(); // This map is immutable, so it's fine to share
+ dto.properties = convertAttrsToDTO(framework.getConfig());
dto.bundles = new ArrayList<BundleDTO>();
for (Bundle b : framework.getBundleContext().getBundles())
@@ -424,15 +424,39 @@
Map<String, Object> m = new HashMap<String, Object>();
for (Map.Entry<String, Object> entry : map.entrySet())
{
- if (entry.getValue() instanceof Version)
- // DTOs don't support Version objects
- m.put(entry.getKey(), entry.getValue().toString());
- else
- m.put(entry.getKey(), entry.getValue());
+ Object value = convertAttrToDTO(entry.getValue());
+ if (value != null)
+ {
+ m.put(entry.getKey(), value);
+ }
}
return m;
}
+ private static Object convertAttrToDTO(Object value)
+ {
+ if (value instanceof Version)
+ {
+ return value.toString();
+ }
+ else if (isPermissibleAttribute(value.getClass())
+ || (value.getClass().isArray()
+ && isPermissibleAttribute(value.getClass().getComponentType())))
+ {
+ return value;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ private static boolean isPermissibleAttribute(Class clazz)
+ {
+ return clazz == Boolean.class || clazz == String.class
+ || DTO.class.isAssignableFrom(clazz);
+ }
+
private static int getWiringID(Wiring bw)
{
return bw.hashCode();