felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1564307 - in /felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl: Activator.java FelixPropertyAdapter.java OSGiCapabilityAdapter.java OSGiRepositoryImpl.java SpecXMLPullParser.java
Date Tue, 04 Feb 2014 14:12:28 GMT
Author: davidb
Date: Tue Feb  4 14:12:27 2014
New Revision: 1564307

URL: http://svn.apache.org/r1564307
Log:
[FELIX-4368] Work toward Repository 1.0 support

This commit registers the Repository Service in the OSGi service registry and also supports
parsing a few more data types from the XML.

Added:
    felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/FelixPropertyAdapter.java
Modified:
    felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/Activator.java
    felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/OSGiCapabilityAdapter.java
    felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryImpl.java
    felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/SpecXMLPullParser.java

Modified: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/Activator.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/Activator.java?rev=1564307&r1=1564306&r2=1564307&view=diff
==============================================================================
--- felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/Activator.java
(original)
+++ felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/Activator.java
Tue Feb  4 14:12:27 2014
@@ -20,11 +20,12 @@ package org.apache.felix.bundlerepositor
 
 import java.util.Hashtable;
 
+import org.apache.felix.bundlerepository.RepositoryAdmin;
 import org.apache.felix.bundlerepository.impl.wrapper.Wrapper;
 import org.apache.felix.utils.log.Logger;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
-import org.apache.felix.bundlerepository.RepositoryAdmin;
+import org.osgi.service.repository.Repository;
 import org.osgi.service.url.URLConstants;
 import org.osgi.service.url.URLStreamHandlerService;
 
@@ -72,6 +73,11 @@ public class Activator implements Bundle
             RepositoryAdmin.class.getName(),
             m_repoAdmin, null);
 
+        // Register the OSGi Repository-spec compliant facade
+        context.registerService(
+            Repository.class.getName(),
+            new OSGiRepositoryImpl(m_repoAdmin), null);
+
         try
         {
             context.registerService(

Added: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/FelixPropertyAdapter.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/FelixPropertyAdapter.java?rev=1564307&view=auto
==============================================================================
--- felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/FelixPropertyAdapter.java
(added)
+++ felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/FelixPropertyAdapter.java
Tue Feb  4 14:12:27 2014
@@ -0,0 +1,78 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+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
+{
+    private static Set<?> asSet(List<?> list)
+    {
+        return new HashSet<Object>(list);
+    }
+
+    private final String name;
+    private final Object value;
+
+    public FelixPropertyAdapter(String name, Object value)
+    {
+        if (name == null)
+            throw new NullPointerException("Missing required parameter: name");
+        if (value == null)
+            throw new NullPointerException("Missing required parameter: value");
+        this.name = name;
+        this.value = value;
+    }
+
+    public FelixPropertyAdapter(Map.Entry<String, Object> entry)
+    {
+        this(entry.getKey(), entry.getValue());
+    }
+
+    public Object getConvertedValue()
+    {
+        if (value instanceof List)
+            return asSet((List<?>) value);
+        return value;
+    }
+
+    public String getName()
+    {
+        return name;
+    }
+
+    public String getType()
+    {
+        if (value instanceof Version)
+            return Property.VERSION;
+        if (value instanceof Long)
+            return Property.LONG;
+        if (value instanceof Double)
+            return Property.DOUBLE;
+        if (value instanceof List<?>)
+            return Property.SET;
+        return null;
+    }
+
+    public String getValue()
+    {
+        return String.valueOf(value);
+    }
+}

Modified: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/OSGiCapabilityAdapter.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/OSGiCapabilityAdapter.java?rev=1564307&r1=1564306&r2=1564307&view=diff
==============================================================================
--- felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/OSGiCapabilityAdapter.java
(original)
+++ felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/OSGiCapabilityAdapter.java
Tue Feb  4 14:12:27 2014
@@ -16,14 +16,10 @@ package org.apache.felix.bundlerepositor
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
 import java.util.Map;
-import java.util.Set;
 
 import org.apache.felix.bundlerepository.Capability;
 import org.apache.felix.bundlerepository.Property;
-import org.osgi.framework.Version;
 
 public class OSGiCapabilityAdapter implements Capability
 {
@@ -53,10 +49,10 @@ public class OSGiCapabilityAdapter imple
         {
             if (entry.getKey().equals(capability.getNamespace()))
             {
-                result.add(new FelixProperty(getName(), entry.getValue()));
+                result.add(new FelixPropertyAdapter(getName(), entry.getValue()));
                 continue;
             }
-            result.add(new FelixProperty(entry));
+            result.add(new FelixPropertyAdapter(entry));
         }
         return result.toArray(new Property[result.size()]);
     }
@@ -73,60 +69,4 @@ public class OSGiCapabilityAdapter imple
     {
         return capability.hashCode();
     }
-
-    static class FelixProperty implements Property
-    {
-        private static Set<?> asSet(List<?> list)
-        {
-            return new HashSet<Object>(list);
-        }
-
-        private final String name;
-        private final Object value;
-
-        public FelixProperty(String name, Object value)
-        {
-            if (name == null)
-                throw new NullPointerException("Missing required parameter: name");
-            if (value == null)
-                throw new NullPointerException("Missing required parameter: value");
-            this.name = name;
-            this.value = value;
-        }
-
-        public FelixProperty(Map.Entry<String, Object> entry)
-        {
-            this(entry.getKey(), entry.getValue());
-        }
-
-        public Object getConvertedValue()
-        {
-            if (value instanceof List)
-                return asSet((List<?>) value);
-            return value;
-        }
-
-        public String getName()
-        {
-            return name;
-        }
-
-        public String getType()
-        {
-            if (value instanceof Version)
-                return Property.VERSION;
-            if (value instanceof Long)
-                return Property.LONG;
-            if (value instanceof Double)
-                return Property.DOUBLE;
-            if (value instanceof List<?>)
-                return Property.SET;
-            return null;
-        }
-
-        public String getValue()
-        {
-            return String.valueOf(value);
-        }
-    }
 }

Modified: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryImpl.java?rev=1564307&r1=1564306&r2=1564307&view=diff
==============================================================================
--- felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryImpl.java
(original)
+++ felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryImpl.java
Tue Feb  4 14:12:27 2014
@@ -46,7 +46,7 @@ import org.osgi.resource.Resource;
 import org.osgi.service.repository.ContentNamespace;
 import org.osgi.service.repository.Repository;
 
-public class OSGiRepositoryImpl implements Repository
+class OSGiRepositoryImpl implements Repository
 {
     private final RepositoryAdmin repository;
 

Modified: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/SpecXMLPullParser.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/SpecXMLPullParser.java?rev=1564307&r1=1564306&r2=1564307&view=diff
==============================================================================
--- felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/SpecXMLPullParser.java
(original)
+++ felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/SpecXMLPullParser.java
Tue Feb  4 14:12:27 2014
@@ -25,6 +25,7 @@ import java.util.Map;
 import org.apache.felix.bundlerepository.Capability;
 import org.apache.felix.bundlerepository.Requirement;
 import org.apache.felix.bundlerepository.Resource;
+import org.osgi.framework.Version;
 import org.osgi.framework.namespace.IdentityNamespace;
 import org.osgi.resource.Namespace;
 import org.osgi.service.repository.ContentNamespace;
@@ -140,7 +141,7 @@ public class SpecXMLPullParser
 
         for (Map.Entry<String, Object> entry : attributes.entrySet())
         {
-            capability.addProperty(entry.getKey(), "" + entry.getValue()); // TODO handle
non-string data types
+            capability.addProperty(new FelixPropertyAdapter(entry.getKey(), entry.getValue()));
         }
 
         return capability;
@@ -186,9 +187,9 @@ public class SpecXMLPullParser
             if (ATTRIBUTE.equals(element))
             {
                 String name = reader.getAttributeValue(null, "name");
-                String type = reader.getAttributeValue(null, "type"); // TODO handle
+                String type = reader.getAttributeValue(null, "type");
                 String value = reader.getAttributeValue(null, "value");
-                attributes.put(name, value);
+                attributes.put(name, getTypedValue(type, value));
                 PullParser.sanityCheckEndElement(reader, reader.nextTag(), ATTRIBUTE);
             }
             else
@@ -199,6 +200,21 @@ public class SpecXMLPullParser
         PullParser.sanityCheckEndElement(reader, event, parentTag);
     }
 
+    private static Object getTypedValue(String type, String value)
+    {
+        if (type == null)
+            return value;
+
+        type = type.trim();
+        if ("Version".equals(type))
+            return Version.parseVersion(value);
+        else if ("Long".equals(type))
+            return Long.parseLong(value);
+        else if ("Double".equals(type))
+            return Double.parseDouble(value);
+        return value;
+    }
+
     private static Requirement parseRequirement(XmlPullParser reader) throws Exception
     {
         RequirementImpl requirement = new RequirementImpl();



Mime
View raw message