Return-Path: X-Original-To: apmail-felix-commits-archive@www.apache.org Delivered-To: apmail-felix-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2307810AF0 for ; Tue, 4 Feb 2014 14:13:00 +0000 (UTC) Received: (qmail 1182 invoked by uid 500); 4 Feb 2014 14:12:59 -0000 Delivered-To: apmail-felix-commits-archive@felix.apache.org Received: (qmail 1063 invoked by uid 500); 4 Feb 2014 14:12:52 -0000 Mailing-List: contact commits-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list commits@felix.apache.org Received: (qmail 1046 invoked by uid 99); 4 Feb 2014 14:12:50 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Feb 2014 14:12:50 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Feb 2014 14:12:48 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 952EA2388993; Tue, 4 Feb 2014 14:12:28 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@felix.apache.org From: davidb@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140204141228.952EA2388993@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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(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 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(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 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 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();