[FELIX-4369] Additional work towards support for the OSGi Repository API
This commit contains logic around parsing of list attributes from the Repository XML.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1585928 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/FelixPropertyAdapter.java b/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/FelixPropertyAdapter.java
index d2aabe8..5080ff0 100644
--- a/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/FelixPropertyAdapter.java
+++ b/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/FelixPropertyAdapter.java
@@ -13,21 +13,14 @@
*/
package org.apache.felix.bundlerepository.impl;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import org.apache.felix.bundlerepository.Property;
import org.osgi.framework.Version;
- class FelixPropertyAdapter implements Property
+class FelixPropertyAdapter implements Property
{
- private static Set<?> asSet(List<?> list)
- {
- return new HashSet<Object>(list);
- }
-
private final String name;
private final Object value;
@@ -48,8 +41,6 @@
public Object getConvertedValue()
{
- if (value instanceof List)
- return asSet((List<?>) value);
return value;
}
diff --git a/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/SpecXMLPullParser.java b/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/SpecXMLPullParser.java
index 3700c17..340680f 100644
--- a/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/SpecXMLPullParser.java
+++ b/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/SpecXMLPullParser.java
@@ -19,7 +19,9 @@
package org.apache.felix.bundlerepository.impl;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.apache.felix.bundlerepository.Capability;
@@ -200,7 +202,7 @@
PullParser.sanityCheckEndElement(reader, event, parentTag);
}
- private static Object getTypedValue(String type, String value)
+ private static Object getTypedValue(String type, String value) throws IOException
{
if (type == null)
return value;
@@ -212,9 +214,87 @@
return Long.parseLong(value);
else if ("Double".equals(type))
return Double.parseDouble(value);
+ else if ("List<String>".equals(type))
+ return parseStringList(value);
+ else if ("List<Version>".equals(type))
+ return parseVersionList(value);
+ else if ("List<Long>".equals(type))
+ return parseLongList(value);
+ else if ("List<Double>".equals(type))
+ return parseDoubleList(value);
return value;
}
+ private static List<String> parseStringList(String value)
+ {
+ List<String> l = new ArrayList<String>();
+ StringBuilder sb = new StringBuilder();
+
+ boolean escaped = false;
+ for (char c : value.toCharArray())
+ {
+ if (escaped)
+ {
+ sb.append(c);
+ escaped = false;
+ }
+ else
+ {
+ switch (c)
+ {
+ case '\\':
+ escaped = true;
+ break;
+ case ',':
+ l.add(sb.toString().trim());
+ sb.setLength(0);
+ break;
+ default:
+ sb.append(c);
+ }
+ }
+ }
+
+ if (sb.length() > 0)
+ l.add(sb.toString().trim());
+
+ return l;
+ }
+
+ private static List<Version> parseVersionList(String value)
+ {
+ List<Version> l = new ArrayList<Version>();
+
+ // Version strings cannot contain a comma, as it's not an allowed character in it anywhere
+ for (String v : value.split(","))
+ {
+ l.add(Version.parseVersion(v.trim()));
+ }
+ return l;
+ }
+
+ private static List<Long> parseLongList(String value)
+ {
+ List<Long> l = new ArrayList<Long>();
+
+ for (String x : value.split(","))
+ {
+ l.add(Long.parseLong(x.trim()));
+ }
+ return l;
+ }
+
+ private static List<Double> parseDoubleList(String value)
+ {
+ List<Double> l = new ArrayList<Double>();
+
+ for (String d : value.split(","))
+ {
+ l.add(Double.parseDouble(d.trim()));
+ }
+ return l;
+ }
+
private static Requirement parseRequirement(XmlPullParser reader) throws Exception
{
RequirementImpl requirement = new RequirementImpl();