[jboss-osgi-commits] JBoss-OSGI SVN: r96223 - in projects/jboss-osgi/trunk/reactor/framework: src/main/java/org/jboss/osgi/framework and 3 other directories.
jboss-osgi-commits at lists.jboss.org
jboss-osgi-commits at lists.jboss.org
Tue Nov 10 11:49:20 EST 2009
Author: alesj
Date: 2009-11-10 11:49:19 -0500 (Tue, 10 Nov 2009)
New Revision: 96223
Added:
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiControllerContextActions.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs/
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs/BundleHandler.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs/BundleVFSContext.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs/BundleVFSContextFactory.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs/bundle/
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs/bundle/Handler.java
Modified:
projects/jboss-osgi/trunk/reactor/framework/pom.xml
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java
Log:
[JBOSGI-201]; handle bundle:// protocol; TODO - tests.
[JBOSGI-141]; initial work on service mix.
Update MC libs - CL, Deployers, VFS.
Modified: projects/jboss-osgi/trunk/reactor/framework/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/pom.xml 2009-11-10 15:14:51 UTC (rev 96222)
+++ projects/jboss-osgi/trunk/reactor/framework/pom.xml 2009-11-10 16:49:19 UTC (rev 96223)
@@ -37,8 +37,9 @@
<!-- Properties -->
<properties>
<version.jboss.aop>2.1.0.CR3</version.jboss.aop>
- <version.jboss.classloading>2.0.7.CR2</version.jboss.classloading>
- <version.jboss.deployers>2.0.8.GA</version.jboss.deployers>
+ <version.jboss.vfs>2.2.0-SNAPSHOT</version.jboss.vfs>
+ <version.jboss.classloading>2.0.8-SNAPSHOT</version.jboss.classloading>
+ <version.jboss.deployers>2.0.9-SNAPSHOT</version.jboss.deployers>
<version.jboss.microcontainer>2.0.9.GA</version.jboss.microcontainer>
<version.jboss.test>1.1.4.GA</version.jboss.test>
</properties>
@@ -93,6 +94,10 @@
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
+ <exclusion>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-vfs</artifactId>
+ </exclusion>
</exclusions>
</dependency>
<dependency>
@@ -101,6 +106,11 @@
<version>${version.jboss.classloading}</version>
</dependency>
<dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-vfs</artifactId>
+ <version>${version.jboss.vfs}</version>
+ </dependency>
+ <dependency>
<groupId>org.jboss.cl</groupId>
<artifactId>jboss-classloading</artifactId>
<version>${version.jboss.classloading}</version>
@@ -109,6 +119,12 @@
<groupId>org.jboss.cl</groupId>
<artifactId>jboss-classloading-vfs</artifactId>
<version>${version.jboss.classloading}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-vfs</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.jboss.deployers</groupId>
@@ -119,16 +135,34 @@
<groupId>org.jboss.deployers</groupId>
<artifactId>jboss-deployers-vfs-spi</artifactId>
<version>${version.jboss.deployers}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-vfs</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.jboss.deployers</groupId>
<artifactId>jboss-deployers-vfs</artifactId>
<version>${version.jboss.deployers}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-vfs</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.jboss.microcontainer</groupId>
<artifactId>jboss-kernel</artifactId>
<version>${version.jboss.microcontainer}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-vfs</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.jboss.osgi</groupId>
@@ -137,10 +171,22 @@
<dependency>
<groupId>org.jboss.osgi.runtime</groupId>
<artifactId>jboss-osgi-deployers</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-vfs</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.jboss.osgi.runtime</groupId>
<artifactId>jboss-osgi-deployment</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-vfs</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<!-- Provided Dependencies -->
@@ -397,9 +443,9 @@
<!-- Subversion -->
<scm>
- <connection>scm:svn:http://anonsvn.jboss.org/repos/jbossas/projects/jboss-osgi/projects/runtime/microcontainer/trunk</connection>
- <developerConnection>scm:svn:https://svn.jboss.org/repos/jbossas/projects/jboss-osgi/projects/runtime/microcontainer/trunk</developerConnection>
- <url>http://fisheye.jboss.com/qsearch/JBossOSGi/projects/runtime/microcontainer/trunk</url>
+ <connection>scm:svn:http://anonsvn.jboss.org/repos/jbossas/projects/jboss-osgi/trunk/reactor/framework</connection>
+ <developerConnection>scm:svn:https://svn.jboss.org/repos/jbossas/projects/jboss-osgi/trunk/reactor/framework</developerConnection>
+ <url>http://fisheye.jboss.com/qsearch/JBossOSGi/projects/jboss-osgi/trunk/reactor/framework</url>
</scm>
</project>
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java 2009-11-10 15:14:51 UTC (rev 96222)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java 2009-11-10 16:49:19 UTC (rev 96223)
@@ -94,7 +94,7 @@
protected Set<OSGiServiceState> registeredServices = new ConcurrentSet<OSGiServiceState>();
/** The services in use */
- protected Map<OSGiServiceState, Integer> servicesInUse = new ConcurrentHashMap<OSGiServiceState, Integer>();
+ protected final Map<OSGiServiceState, Integer> servicesInUse = new ConcurrentHashMap<OSGiServiceState, Integer>();
/** The cached symbolic name */
private String symbolicName;
@@ -346,6 +346,7 @@
* True if the use count of a service for this bundle is grater that 0.
*
* @param serviceState the service
+ * @return true if counter is bigger than zero, false otherwise
*/
boolean isServiceInUse(OSGiServiceState serviceState)
{
@@ -652,7 +653,7 @@
int previous = getState();
// Get the corresponding bundle event type
- int bundleEventType = 0;
+ int bundleEventType;
switch (state)
{
case Bundle.STARTING:
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-11-10 15:14:51 UTC (rev 96222)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-11-10 16:49:19 UTC (rev 96223)
@@ -21,8 +21,6 @@
*/
package org.jboss.osgi.framework.bundle;
-import static org.jboss.osgi.spi.OSGiConstants.PROPERTY_AUTO_START;
-
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -48,9 +46,10 @@
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.jar.Attributes;
+import java.util.jar.Attributes.Name;
import java.util.jar.Manifest;
-import java.util.jar.Attributes.Name;
+import org.jboss.dependency.spi.Controller;
import org.jboss.dependency.spi.ControllerContext;
import org.jboss.dependency.spi.ControllerState;
import org.jboss.deployers.client.spi.DeployerClient;
@@ -75,6 +74,7 @@
import org.jboss.osgi.framework.plugins.Plugin;
import org.jboss.osgi.framework.plugins.ServicePlugin;
import org.jboss.osgi.framework.util.NoFilter;
+import static org.jboss.osgi.spi.OSGiConstants.PROPERTY_AUTO_START;
import org.jboss.util.collection.ConcurrentSet;
import org.jboss.virtual.VFS;
import org.jboss.virtual.VFSUtils;
@@ -97,6 +97,7 @@
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
* @author Thomas.Diesler at jboss.com
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
* @version $Revision: 1.1 $
*/
public class OSGiBundleManager
@@ -639,7 +640,6 @@
*/
private void validateBundle(AbstractBundleState bundleState)
{
-
OSGiMetaData metaData = bundleState.getOSGiMetaData();
String symbolicName = metaData.getBundleSymbolicName();
@@ -952,7 +952,7 @@
/**
* Get services
*
- * @param bundleState the referencing bundle
+ * @param bundle the referencing bundle
* @param clazz any class
* @param filter any filter
* @param checkAssignable whether to check isAssignable
@@ -1055,7 +1055,6 @@
* @param bundle the referencing bundle
* @param clazz any class
* @param filterStr any filter
- * @param checkAssignable
* @param checkAssignable whether to check isAssignable
* @return the services
* @throws InvalidSyntaxException when the filter is invalid
@@ -1084,8 +1083,25 @@
OSGiServiceState result = new OSGiServiceState(bundleState, clazzes, service, properties);
result.internalRegister();
registeredServices.add(result);
+
+ try
+ {
+ Controller controller = kernel.getController();
+ controller.install(result);
+ }
+ catch (Throwable t)
+ {
+ fireError(bundleState, "installing service to MC in", t);
+
+ registeredServices.remove(result);
+ result.internalUnregister();
+
+ throw new RuntimeException(t);
+ }
+
FrameworkEventsPlugin plugin = getPlugin(FrameworkEventsPlugin.class);
plugin.fireServiceEvent(bundleState, ServiceEvent.REGISTERED, result);
+
return result;
}
@@ -1096,9 +1112,12 @@
*/
void unregisterService(OSGiServiceState serviceState)
{
- log.debug("Unregistering service: " + serviceState.toLongString());
+ Controller controller = kernel.getController();
+ controller.uninstall(serviceState.getName());
+
FrameworkEventsPlugin plugin = getPlugin(FrameworkEventsPlugin.class);
plugin.fireServiceEvent(serviceState.getBundleState(), ServiceEvent.UNREGISTERING, serviceState);
+
registeredServices.remove(serviceState);
serviceState.internalUnregister();
}
@@ -1306,7 +1325,7 @@
/**
* Fire a framework error
*
- * @param bundleState the bundle state
+ * @param bundle the bundle
* @param context the msg context
* @param t the throwable
*/
@@ -1324,7 +1343,7 @@
/**
* Fire a framework error
*
- * @param bundleState the bundle state
+ * @param bundle the bundle
* @param context the msg context
* @param t the throwable
*/
Copied: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiControllerContextActions.java (from rev 96195, projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiControllerContextActions.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiControllerContextActions.java 2009-11-10 16:49:19 UTC (rev 96223)
@@ -0,0 +1,44 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.osgi.framework.bundle;
+
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerContextActions;
+import org.jboss.dependency.spi.ControllerState;
+
+/**
+ * OSGi actions.
+ *
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
+ */
+class OSGiControllerContextActions implements ControllerContextActions
+{
+ static final ControllerContextActions ACTIONS = new OSGiControllerContextActions();
+
+ public void install(ControllerContext context, ControllerState fromState, ControllerState toState) throws Throwable
+ {
+ }
+
+ public void uninstall(ControllerContext context, ControllerState fromState, ControllerState toState)
+ {
+ }
+}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java 2009-11-10 15:14:51 UTC (rev 96222)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java 2009-11-10 16:49:19 UTC (rev 96223)
@@ -32,10 +32,12 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;
+import org.jboss.dependency.plugins.AbstractControllerContext;
import org.jboss.logging.Logger;
import org.jboss.osgi.framework.plugins.FrameworkEventsPlugin;
import org.jboss.osgi.framework.util.CaseInsensitiveDictionary;
import org.jboss.util.collection.ConcurrentSet;
+import org.jboss.util.id.GUID;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
@@ -50,9 +52,10 @@
* OSGiServiceState.
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
* @version $Revision: 1.1 $
*/
-public class OSGiServiceState implements ServiceReference, ServiceRegistration
+public class OSGiServiceState extends AbstractControllerContext implements ServiceReference, ServiceRegistration
{
/** The log */
private static final Logger log = Logger.getLogger(OSGiServiceState.class);
@@ -99,6 +102,9 @@
@SuppressWarnings("unchecked")
public OSGiServiceState(AbstractBundleState bundleState, String[] clazzes, Object service, Dictionary properties)
{
+ // name is random / unique, we use aliases
+ super(GUID.asString(), OSGiControllerContextActions.ACTIONS, null, service);
+
if (bundleState == null)
throw new IllegalArgumentException("Null bundle state");
if (clazzes == null || clazzes.length == 0)
@@ -158,13 +164,20 @@
return clazzes;
}
+ @Override
+ public Object getTarget()
+ {
+ // do we cache this? or how to unget?
+ return getService(getBundleState());
+ }
+
/**
* Get the service.
*
* @param bundleState the bundle that requested the service
* @return the service.
*/
- public Object getService(AbstractBundleState bundleState)
+ Object getService(AbstractBundleState bundleState)
{
// [TODO] fix race condition with unregistration
if (isUnregistered())
Added: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs/BundleHandler.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs/BundleHandler.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs/BundleHandler.java 2009-11-10 16:49:19 UTC (rev 96223)
@@ -0,0 +1,130 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.framework.vfs;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.jboss.osgi.framework.bundle.OSGiBundleState;
+import org.jboss.virtual.plugins.context.AbstractVirtualFileHandler;
+import org.jboss.virtual.spi.VFSContext;
+import org.jboss.virtual.spi.VirtualFileHandler;
+
+/**
+ * Bundle handler.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+class BundleHandler extends AbstractVirtualFileHandler
+{
+ private VirtualFileHandler handler;
+ private OSGiBundleState bundleState;
+
+ public BundleHandler(VFSContext context, VirtualFileHandler parent, VirtualFileHandler handler, OSGiBundleState bundleState)
+ {
+ super(context, parent, handler.getName());
+ this.handler = handler;
+ this.bundleState = bundleState;
+ }
+
+ public URI toURI() throws URISyntaxException
+ {
+ return new URI("bundle", Long.toString(bundleState.getBundleId()), handler.getLocalPathName(), null);
+ }
+
+ public long getLastModified() throws IOException
+ {
+ return bundleState.getLastModified();
+ }
+
+ public InputStream openStream() throws IOException
+ {
+ bundleState.getResource(""); // permission check
+
+ return handler.openStream();
+ }
+
+ public List<VirtualFileHandler> getChildren(boolean ignoreErrors) throws IOException
+ {
+ bundleState.findEntries("", null, false); // permission check
+
+ List<VirtualFileHandler> children = handler.getChildren(ignoreErrors);
+ if (children != null && children.isEmpty() == false)
+ {
+ List<VirtualFileHandler> handlers = new ArrayList<VirtualFileHandler>(children.size());
+ for (VirtualFileHandler child : children)
+ {
+ handlers.add(new BundleHandler(getVFSContext(), handler, child, bundleState));
+ }
+ return handlers;
+ }
+ return Collections.emptyList();
+ }
+
+ public VirtualFileHandler getChild(String path) throws IOException
+ {
+ URL entry = bundleState.getEntry(path); // permission check
+ if (entry == null)
+ return null;
+
+ VirtualFileHandler child = handler.getChild(path); // the child should exist, since entry does
+ return new BundleHandler(getVFSContext(), handler, child, bundleState);
+ }
+
+ //---------------------------------------------------------
+
+ public long getSize() throws IOException
+ {
+ return handler.getSize();
+ }
+
+ public boolean exists() throws IOException
+ {
+ return handler.exists();
+ }
+
+ public boolean isLeaf() throws IOException
+ {
+ return handler.isLeaf();
+ }
+
+ public boolean isHidden() throws IOException
+ {
+ return handler.isHidden();
+ }
+
+ public boolean removeChild(String name) throws IOException
+ {
+ return handler.removeChild(name);
+ }
+
+ public boolean isNested() throws IOException
+ {
+ return handler.isNested();
+ }
+}
\ No newline at end of file
Added: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs/BundleVFSContext.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs/BundleVFSContext.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs/BundleVFSContext.java 2009-11-10 16:49:19 UTC (rev 96223)
@@ -0,0 +1,119 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.framework.vfs;
+
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.net.URI;
+import java.security.AccessController;
+import java.security.PrivilegedExceptionAction;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.osgi.framework.bundle.AbstractBundleState;
+import org.jboss.osgi.framework.bundle.OSGiBundleManager;
+import org.jboss.osgi.framework.bundle.OSGiBundleState;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.plugins.context.AbstractVFSContext;
+import org.jboss.virtual.spi.VirtualFileHandler;
+
+/**
+ * Bundle vfs context.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class BundleVFSContext extends AbstractVFSContext
+{
+ private static final Method getHandler;
+
+ static
+ {
+ try
+ {
+ PrivilegedExceptionAction<Method> action = new PrivilegedExceptionAction<Method>()
+ {
+ public Method run() throws Exception
+ {
+ Method method = VirtualFile.class.getDeclaredMethod("getHandler");
+ method.setAccessible(true);
+ return method;
+ }
+ };
+ getHandler = AccessController.doPrivileged(action);
+
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private String host;
+ private VirtualFileHandler root;
+
+ public BundleVFSContext(URI rootURI, OSGiBundleManager manager) throws IOException
+ {
+ super(rootURI);
+
+ host = rootURI.getHost();
+ long id = Long.parseLong(host);
+ if (id == 0)
+ throw new IllegalArgumentException("Cannot handle system bundle, it's too abstract.");
+
+ AbstractBundleState abs = manager.getBundleById(id);
+ if (abs == null)
+ throw new IllegalArgumentException("No such bundle: " + id);
+
+ OSGiBundleState bundleState = OSGiBundleState.class.cast(abs); // should be able to cast, as it's not system
+ DeploymentUnit unit = bundleState.getDeploymentUnit();
+ if (unit instanceof VFSDeploymentUnit == false)
+ throw new IllegalArgumentException("Cannot handle non VFS deployments: " + unit);
+
+ String path = rootURI.getPath();
+ if (path == null)
+ path = "";
+
+ VFSDeploymentUnit vdu = VFSDeploymentUnit.class.cast(unit);
+ VirtualFile file = vdu.getFile(path);
+ try
+ {
+ VirtualFileHandler handler = (VirtualFileHandler)getHandler.invoke(file);
+ root = new BundleHandler(this, handler.getParent(), handler, bundleState);
+ }
+ catch (Exception e)
+ {
+ IOException ioe = new IOException();
+ ioe.initCause(e);
+ throw ioe;
+ }
+ }
+
+ public String getName()
+ {
+ return host;
+ }
+
+ public VirtualFileHandler getRoot() throws IOException
+ {
+ return root;
+ }
+}
Added: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs/BundleVFSContextFactory.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs/BundleVFSContextFactory.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs/BundleVFSContextFactory.java 2009-11-10 16:49:19 UTC (rev 96223)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.framework.vfs;
+
+import java.net.URL;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.io.IOException;
+
+import org.jboss.virtual.plugins.context.AbstractContextFactory;
+import org.jboss.virtual.spi.VFSContext;
+import org.jboss.virtual.spi.VFSContextFactoryLocator;
+import org.jboss.osgi.framework.bundle.OSGiBundleManager;
+
+/**
+ * Bundle vfs context factory.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class BundleVFSContextFactory extends AbstractContextFactory
+{
+ static
+ {
+ init();
+ }
+
+ private OSGiBundleManager manager;
+
+ public BundleVFSContextFactory(OSGiBundleManager manager)
+ {
+ super("bundle");
+ if (manager == null)
+ throw new IllegalArgumentException("Null manager");
+ this.manager = manager;
+ }
+
+ public static void init()
+ {
+ String pkgs = System.getProperty("java.protocol.handler.pkgs");
+ if (pkgs == null || pkgs.trim().length() == 0)
+ {
+ pkgs = "org.jboss.osgi.framework.vfs";
+ System.setProperty("java.protocol.handler.pkgs", pkgs);
+ }
+ else if (!pkgs.contains("org.jboss.virtual.protocol"))
+ {
+ pkgs += "|org.jboss.osgi.framework.vfs";
+ System.setProperty("java.protocol.handler.pkgs", pkgs);
+ }
+ }
+
+ public void start()
+ {
+ VFSContextFactoryLocator.registerFactory(this);
+ }
+
+ public void stop()
+ {
+ VFSContextFactoryLocator.unregisterFactory(this);
+ }
+
+ public VFSContext getVFS(URL rootURL) throws IOException
+ {
+ try
+ {
+ return getVFS(rootURL.toURI());
+ }
+ catch (URISyntaxException e)
+ {
+ IOException ioe = new IOException();
+ ioe.initCause(e);
+ throw ioe;
+ }
+ }
+
+ public VFSContext getVFS(URI rootURI) throws IOException
+ {
+ return new BundleVFSContext(rootURI, manager);
+ }
+}
Added: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs/bundle/Handler.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs/bundle/Handler.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs/bundle/Handler.java 2009-11-10 16:49:19 UTC (rev 96223)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.framework.vfs.bundle;
+
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
+
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.plugins.vfs.VirtualFileURLConnection;
+
+/**
+ * Bundle url stream handler.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class Handler extends URLStreamHandler
+{
+ protected URLConnection openConnection(URL u) throws IOException
+ {
+ VirtualFile file = VFS.getRoot(u);
+ return new VirtualFileURLConnection(u, file);
+ }
+}
\ No newline at end of file
More information about the jboss-osgi-commits
mailing list