You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2007/09/11 14:41:49 UTC
svn commit: r574575 - in /felix/sandbox/clement/obr.url.handler: ./ src/
src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/felix/ src/main/java/org/apache/felix/ipojo/
src/main/java/org/apache/felix/ipojo/ar...
Author: clement
Date: Tue Sep 11 05:41:48 2007
New Revision: 574575
URL: http://svn.apache.org/viewvc?rev=574575&view=rev
Log:
Initial import of a simple obr:// url handler
Added:
felix/sandbox/clement/obr.url.handler/pom.xml
felix/sandbox/clement/obr.url.handler/src/
felix/sandbox/clement/obr.url.handler/src/main/
felix/sandbox/clement/obr.url.handler/src/main/java/
felix/sandbox/clement/obr.url.handler/src/main/java/org/
felix/sandbox/clement/obr.url.handler/src/main/java/org/apache/
felix/sandbox/clement/obr.url.handler/src/main/java/org/apache/felix/
felix/sandbox/clement/obr.url.handler/src/main/java/org/apache/felix/ipojo/
felix/sandbox/clement/obr.url.handler/src/main/java/org/apache/felix/ipojo/arch/
felix/sandbox/clement/obr.url.handler/src/main/java/org/apache/felix/sandbox/
felix/sandbox/clement/obr.url.handler/src/main/java/org/apache/felix/sandbox/obr/
felix/sandbox/clement/obr.url.handler/src/main/java/org/apache/felix/sandbox/obr/url/
felix/sandbox/clement/obr.url.handler/src/main/java/org/apache/felix/sandbox/obr/url/handler/
felix/sandbox/clement/obr.url.handler/src/main/java/org/apache/felix/sandbox/obr/url/handler/OBRUrlHandler.java
felix/sandbox/clement/obr.url.handler/src/main/resources/
felix/sandbox/clement/obr.url.handler/src/main/resources/metadata.xml
Added: felix/sandbox/clement/obr.url.handler/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/obr.url.handler/pom.xml?rev=574575&view=auto
==============================================================================
--- felix/sandbox/clement/obr.url.handler/pom.xml (added)
+++ felix/sandbox/clement/obr.url.handler/pom.xml Tue Sep 11 05:41:48 2007
@@ -0,0 +1,51 @@
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>bundle</packaging>
+ <name>Apache Felix OBR Url Handler</name>
+ <version>0.0.1-SNAPSHOT</version>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.obr.url.handler</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.bundlerepository</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+ <Private-Package>org.apache.felix.sandbox.obr.url.handler</Private-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo.plugin</artifactId>
+ <version>0.7.3-SNAPSHOT</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>ipojo-bundle</goal>
+ </goals>
+ <configuration>
+ <metadata>metadata.xml</metadata>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Added: felix/sandbox/clement/obr.url.handler/src/main/java/org/apache/felix/sandbox/obr/url/handler/OBRUrlHandler.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/obr.url.handler/src/main/java/org/apache/felix/sandbox/obr/url/handler/OBRUrlHandler.java?rev=574575&view=auto
==============================================================================
--- felix/sandbox/clement/obr.url.handler/src/main/java/org/apache/felix/sandbox/obr/url/handler/OBRUrlHandler.java (added)
+++ felix/sandbox/clement/obr.url.handler/src/main/java/org/apache/felix/sandbox/obr/url/handler/OBRUrlHandler.java Tue Sep 11 05:41:48 2007
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.sandbox.obr.url.handler;
+
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLConnection;
+
+import org.osgi.service.obr.RepositoryAdmin;
+import org.osgi.service.obr.Resource;
+import org.osgi.service.url.AbstractURLStreamHandlerService;
+import org.osgi.service.url.URLStreamHandlerService;
+
+/**
+ * This component provides an URL Handler to manage obr:// urls.
+ * It allows to update bundles already deployed with OBR.
+ * It updates the bundle with the file deployed on the OBR.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class OBRUrlHandler extends AbstractURLStreamHandlerService implements URLStreamHandlerService {
+
+ /**
+ * OBR Admin service.
+ */
+ private RepositoryAdmin m_admin;
+
+ /**
+ * Open Connection method.
+ * This method parses the given url and gather the bundle symbolic name.
+ * Then it looks inside the OBR repositories for a bundle with the same symbolic name.
+ * If found, it open a connection on the found resource, otherwise it throws an exception.
+ * @param arg0 : given URL (begin with obr://)
+ * @return the URLConnection for the given url
+ * @throws IOException occurs if the looked bundle is not present inside installed OBR repositories.
+ * @see org.osgi.service.url.AbstractURLStreamHandlerService#openConnection(java.net.URL)
+ */
+ public URLConnection openConnection(URL arg0) throws IOException {
+ String url = arg0.toString();
+ System.out.println("URL : " + url);
+ int end = url.lastIndexOf("/");
+ String sn = url.substring("obr://".length(), end);
+ String filter = "(symbolicname=" + sn + ")";
+
+ Resource[] res = m_admin.discoverResources(filter);
+
+ URL updateLoc = null;
+ if (res != null && res.length > 0) {
+ updateLoc = res[0].getURL();
+ System.out.println("Update-Location : " + updateLoc.toString());
+ return updateLoc.openConnection();
+ } else {
+ throw new IOException("The bundle " + sn + " is not available inside OBR repositories");
+ }
+ }
+
+}
+
Added: felix/sandbox/clement/obr.url.handler/src/main/resources/metadata.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/obr.url.handler/src/main/resources/metadata.xml?rev=574575&view=auto
==============================================================================
--- felix/sandbox/clement/obr.url.handler/src/main/resources/metadata.xml (added)
+++ felix/sandbox/clement/obr.url.handler/src/main/resources/metadata.xml Tue Sep 11 05:41:48 2007
@@ -0,0 +1,9 @@
+<ipojo>
+<component classname="org.apache.felix.sandbox.obr.url.handler.OBRUrlHandler" name="obr">
+ <requires field="m_admin"/>
+ <provides>
+ <property name="url.handler.protocol" type="string" value="obr"/>
+ </provides>
+</component>
+<instance component="obr"/>
+</ipojo>
\ No newline at end of file