[jboss-cvs] JBossAS SVN: r59435 - in projects/osgi/trunk: core/src/main/org/jboss/osgi/core/platform/spi deployment/src/main/org/jboss/osgi deployment/src/main/org/jboss/osgi/deployers deployment/src/main/org/jboss/osgi/metadata/plugins deployment/src/main/org/jboss/osgi/metadata/spi
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jan 9 09:01:42 EST 2007
Author: alesj
Date: 2007-01-09 09:01:31 -0500 (Tue, 09 Jan 2007)
New Revision: 59435
Added:
projects/osgi/trunk/core/src/main/org/jboss/osgi/core/platform/spi/BundleContextHolder.java
projects/osgi/trunk/deployment/src/main/org/jboss/osgi/deployers/
projects/osgi/trunk/deployment/src/main/org/jboss/osgi/deployers/BundleActivatorDeployer.java
projects/osgi/trunk/deployment/src/main/org/jboss/osgi/deployers/BundleClassLoaderDeployer.java
projects/osgi/trunk/deployment/src/main/org/jboss/osgi/deployers/BundleLifecycleDeployer.java
projects/osgi/trunk/deployment/src/main/org/jboss/osgi/deployers/OSGiKernelRegistryPlugin.java
projects/osgi/trunk/deployment/src/main/org/jboss/osgi/deployers/OSGiPluginDeployer.java
projects/osgi/trunk/deployment/src/main/org/jboss/osgi/metadata/plugins/AbstractBundleActivatorMetadata.java
projects/osgi/trunk/deployment/src/main/org/jboss/osgi/metadata/spi/BundleActivatorMetaData.java
Log:
OSGi deployers - initial code
Added: projects/osgi/trunk/core/src/main/org/jboss/osgi/core/platform/spi/BundleContextHolder.java
===================================================================
--- projects/osgi/trunk/core/src/main/org/jboss/osgi/core/platform/spi/BundleContextHolder.java 2007-01-09 13:37:11 UTC (rev 59434)
+++ projects/osgi/trunk/core/src/main/org/jboss/osgi/core/platform/spi/BundleContextHolder.java 2007-01-09 14:01:31 UTC (rev 59435)
@@ -0,0 +1,41 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.core.platform.spi;
+
+import org.osgi.framework.BundleContext;
+
+/**
+ * Simple markup interface.
+ * Simplifies injection.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface BundleContextHolder
+{
+ /**
+ * Use BundleContext for different service / reference
+ * registry, lookup, etc.
+ *
+ * @return instance's bundle context
+ */
+ BundleContext getBundleContext();
+}
Added: projects/osgi/trunk/deployment/src/main/org/jboss/osgi/deployers/BundleActivatorDeployer.java
===================================================================
--- projects/osgi/trunk/deployment/src/main/org/jboss/osgi/deployers/BundleActivatorDeployer.java 2007-01-09 13:37:11 UTC (rev 59434)
+++ projects/osgi/trunk/deployment/src/main/org/jboss/osgi/deployers/BundleActivatorDeployer.java 2007-01-09 14:01:31 UTC (rev 59435)
@@ -0,0 +1,100 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.deployers;
+
+import java.util.Set;
+
+import org.jboss.beans.metadata.plugins.BeanMetaDataBuilder;
+import org.jboss.deployers.plugins.deployer.AbstractSimpleDeployer;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentUnit;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.osgi.core.platform.spi.BundleAdapter;
+import org.jboss.osgi.metadata.spi.BundleActivatorMetaData;
+import org.jboss.util.id.GUID;
+
+/**
+ * Install each BundleActivatorMetaData.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class BundleActivatorDeployer extends AbstractSimpleDeployer
+{
+ /**
+ * The kernel controller
+ */
+ private final KernelController controller;
+
+ /**
+ * The GUID, used to create unique activator names
+ */
+ private GUID guid;
+
+ /**
+ * Create a new OSGiPluginDeployer.
+ *
+ * @param kernel the kernel
+ * @throws IllegalArgumentException for a null kernel
+ */
+ public BundleActivatorDeployer(Kernel kernel)
+ {
+ if (kernel == null)
+ throw new IllegalArgumentException("Null kernel");
+ controller = kernel.getController();
+ guid = new GUID();
+ setRelativeOrder(REAL_DEPLOYER - 2); // before osgi_plugin and beans, if activators add some additional OSGi info
+ }
+
+ public void deploy(DeploymentUnit unit) throws DeploymentException
+ {
+ BundleAdapter bundleAdapter = unit.getAttachment(BundleAdapter.class);
+ if (bundleAdapter != null)
+ {
+ Set<? extends BundleActivatorMetaData> activators = unit.getAllMetaData(BundleActivatorMetaData.class);
+ for (BundleActivatorMetaData bamd : activators)
+ {
+ registerBundleActivator(bamd, bundleAdapter);
+ }
+ }
+ }
+
+ private void registerBundleActivator(BundleActivatorMetaData bamd, BundleAdapter bundleAdapter) throws DeploymentException
+ {
+ try
+ {
+ // bundle activator + start, stop
+ BeanMetaDataBuilder builder = new BeanMetaDataBuilder(
+ guid.getUID().toString(),
+ bamd.getActivatorClass()
+ );
+ builder.addStartParameter("org.osgi.framework.BundleContext", bundleAdapter.getBundleContext());
+ builder.addStopParameter("org.osgi.framework.BundleContext", bundleAdapter.getBundleContext());
+ controller.install(builder.getBeanMetaData());
+ }
+ catch (Throwable throwable)
+ {
+ throw DeploymentException.rethrowAsDeploymentException("Unable to register BundleActivator.", throwable);
+ }
+ }
+
+}
Added: projects/osgi/trunk/deployment/src/main/org/jboss/osgi/deployers/BundleClassLoaderDeployer.java
===================================================================
--- projects/osgi/trunk/deployment/src/main/org/jboss/osgi/deployers/BundleClassLoaderDeployer.java 2007-01-09 13:37:11 UTC (rev 59434)
+++ projects/osgi/trunk/deployment/src/main/org/jboss/osgi/deployers/BundleClassLoaderDeployer.java 2007-01-09 14:01:31 UTC (rev 59435)
@@ -0,0 +1,47 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.deployers;
+
+import org.jboss.deployers.plugins.deployers.helpers.AbstractTopLevelClassLoaderDeployer;
+import org.jboss.deployers.spi.structure.DeploymentContext;
+import org.jboss.osgi.core.platform.spi.BundleAdapter;
+
+/**
+ * Creates classloader from Bundle, BundleContext.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class BundleClassLoaderDeployer extends AbstractTopLevelClassLoaderDeployer
+{
+
+ public ClassLoader createTopLevelClassLoader(DeploymentContext context) throws Exception
+ {
+ BundleAdapter bundleAdapter = context.getTransientAttachments().getAttachment(BundleAdapter.class);
+ if (bundleAdapter != null)
+ {
+ // TODO
+ return null;
+ }
+ return context.getClassLoader();
+ }
+
+}
Added: projects/osgi/trunk/deployment/src/main/org/jboss/osgi/deployers/BundleLifecycleDeployer.java
===================================================================
--- projects/osgi/trunk/deployment/src/main/org/jboss/osgi/deployers/BundleLifecycleDeployer.java 2007-01-09 13:37:11 UTC (rev 59434)
+++ projects/osgi/trunk/deployment/src/main/org/jboss/osgi/deployers/BundleLifecycleDeployer.java 2007-01-09 14:01:31 UTC (rev 59435)
@@ -0,0 +1,40 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.deployers;
+
+import org.jboss.osgi.core.platform.spi.OSGiPlatform;
+
+/**
+ * TODO - handle manifest, jar, BundleContext (ClassLoader), BundleActivatorMetaData, ...
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class BundleLifecycleDeployer // extends AbstractXXXDeployer
+{
+ private OSGiPlatform platform;
+
+ public BundleLifecycleDeployer(OSGiPlatform platform)
+ {
+ this.platform = platform;
+ }
+
+}
Added: projects/osgi/trunk/deployment/src/main/org/jboss/osgi/deployers/OSGiKernelRegistryPlugin.java
===================================================================
--- projects/osgi/trunk/deployment/src/main/org/jboss/osgi/deployers/OSGiKernelRegistryPlugin.java 2007-01-09 13:37:11 UTC (rev 59434)
+++ projects/osgi/trunk/deployment/src/main/org/jboss/osgi/deployers/OSGiKernelRegistryPlugin.java 2007-01-09 14:01:31 UTC (rev 59435)
@@ -0,0 +1,85 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.deployers;
+
+import org.jboss.kernel.spi.registry.KernelRegistryPlugin;
+import org.jboss.kernel.spi.registry.KernelRegistryEntry;
+import org.jboss.kernel.plugins.registry.AbstractKernelRegistryEntry;
+import org.jboss.osgi.core.platform.spi.BundleContextHolder;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * OSGi reference lookup via BundleContext;
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class OSGiKernelRegistryPlugin implements KernelRegistryPlugin, BundleContextHolder
+{
+ private BundleContext bundleContext;
+
+ public OSGiKernelRegistryPlugin(BundleContext bundleContext)
+ {
+ this.bundleContext = bundleContext;
+ }
+
+ /**
+ * Simple plugin to register our services via BC.
+ * No need for two different beans to plug-in to OSGi framework.
+ *
+ * @return current BundleContext
+ */
+ public BundleContext getBundleContext()
+ {
+ return bundleContext;
+ }
+
+ /**
+ * We provide extra KernelRegistryPlugin, which handles OSGi specific lookup
+ *
+ * @param name
+ * @return KREntry to OSGi service registered in OSGi platform
+ */
+ public KernelRegistryEntry getEntry(Object name)
+ {
+ Object target = null;
+ if (name instanceof ServiceReference)
+ {
+ ServiceReference ref = (ServiceReference) name;
+ target = bundleContext.getService(ref);
+ }
+ else if (name instanceof String)
+ {
+ ServiceReference ref = bundleContext.getServiceReference(name.toString());
+ if (ref != null)
+ {
+ target = bundleContext.getService(ref);
+ }
+ }
+ if (target != null)
+ {
+ return new AbstractKernelRegistryEntry(target);
+ }
+ return null;
+ }
+
+}
Added: projects/osgi/trunk/deployment/src/main/org/jboss/osgi/deployers/OSGiPluginDeployer.java
===================================================================
--- projects/osgi/trunk/deployment/src/main/org/jboss/osgi/deployers/OSGiPluginDeployer.java 2007-01-09 13:37:11 UTC (rev 59434)
+++ projects/osgi/trunk/deployment/src/main/org/jboss/osgi/deployers/OSGiPluginDeployer.java 2007-01-09 14:01:31 UTC (rev 59435)
@@ -0,0 +1,105 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.deployers;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.beans.metadata.plugins.BeanMetaDataBuilder;
+import org.jboss.deployers.plugins.deployer.AbstractSimpleDeployer;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentUnit;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.osgi.core.platform.spi.BundleAdapter;
+
+/**
+ * Installs OSGiKernelRegistryPlugin into KernelController.
+ * Adds OSGiServiceRegistryFactory into KernelController.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class OSGiPluginDeployer extends AbstractSimpleDeployer
+{
+ /**
+ * The kernel controller
+ */
+ private final KernelController controller;
+
+ /**
+ * Watch for new BundleContexts
+ */
+ private Set<Long> usedBundleAdapters;
+
+ /**
+ * Create a new OSGiPluginDeployer.
+ *
+ * @param kernel the kernel
+ * @throws IllegalArgumentException for a null kernel
+ */
+ public OSGiPluginDeployer(Kernel kernel)
+ {
+ if (kernel == null)
+ throw new IllegalArgumentException("Null kernel");
+ controller = kernel.getController();
+ usedBundleAdapters = new HashSet<Long>();
+ setRelativeOrder(REAL_DEPLOYER - 1); // before bean deployer
+ }
+
+ public void deploy(DeploymentUnit unit) throws DeploymentException
+ {
+ BundleAdapter bundleAdapter = unit.getAttachment(BundleAdapter.class);
+ if (bundleAdapter != null)
+ {
+ if (usedBundleAdapters.contains(bundleAdapter.getBundleId()) == false)
+ {
+ usedBundleAdapters.add(bundleAdapter.getBundleId());
+ registerOSGiPlugins(unit.getName(), bundleAdapter);
+ }
+ }
+ }
+
+ private void registerOSGiPlugins(String unitName, BundleAdapter bundleAdapter) throws DeploymentException
+ {
+ try
+ {
+ // reference lookup + BC holder
+ BeanMetaDataBuilder builder = new BeanMetaDataBuilder(
+ unitName + "_OSGiKernelRegistryPlugin",
+ OSGiKernelRegistryPlugin.class.getName()
+ );
+ builder.addConstructorParameter("org.osgi.framework.BundleContext", bundleAdapter.getBundleContext());
+ controller.install(builder.getBeanMetaData());
+ }
+ catch (Throwable throwable)
+ {
+ throw DeploymentException.rethrowAsDeploymentException("Unable to register OSGiPlugins.", throwable);
+ }
+ }
+
+ public void stop()
+ {
+ usedBundleAdapters.clear();
+ usedBundleAdapters = null;
+ }
+
+}
Added: projects/osgi/trunk/deployment/src/main/org/jboss/osgi/metadata/plugins/AbstractBundleActivatorMetadata.java
===================================================================
--- projects/osgi/trunk/deployment/src/main/org/jboss/osgi/metadata/plugins/AbstractBundleActivatorMetadata.java 2007-01-09 13:37:11 UTC (rev 59434)
+++ projects/osgi/trunk/deployment/src/main/org/jboss/osgi/metadata/plugins/AbstractBundleActivatorMetadata.java 2007-01-09 14:01:31 UTC (rev 59435)
@@ -0,0 +1,42 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.metadata.plugins;
+
+import org.jboss.osgi.metadata.spi.BundleActivatorMetaData;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class AbstractBundleActivatorMetaData implements BundleActivatorMetaData
+{
+ private String className;
+
+ public AbstractBundleActivatorMetaData(String activatorClassName)
+ {
+ this.className = activatorClassName;
+ }
+
+ public String getActivatorClass()
+ {
+ return className;
+ }
+}
Added: projects/osgi/trunk/deployment/src/main/org/jboss/osgi/metadata/spi/BundleActivatorMetaData.java
===================================================================
--- projects/osgi/trunk/deployment/src/main/org/jboss/osgi/metadata/spi/BundleActivatorMetaData.java 2007-01-09 13:37:11 UTC (rev 59434)
+++ projects/osgi/trunk/deployment/src/main/org/jboss/osgi/metadata/spi/BundleActivatorMetaData.java 2007-01-09 14:01:31 UTC (rev 59435)
@@ -0,0 +1,37 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.metadata.spi;
+
+/**
+ * MetaData for Manifest defined Bundle-Activator.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface BundleActivatorMetaData
+{
+ /**
+ * Get BundleActivator impl class name.
+ *
+ * @return activator class name
+ */
+ String getActivatorClass();
+}
More information about the jboss-cvs-commits
mailing list