[jboss-cvs] JBossAS SVN: r59416 - in projects/osgi/trunk/core: . src/main/org/jboss/osgi/core src/main/org/jboss/osgi/core/platform src/main/org/jboss/osgi/core/platform/plugin src/main/org/jboss/osgi/core/platform/spi
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Jan 8 07:44:59 EST 2007
Author: alesj
Date: 2007-01-08 07:44:54 -0500 (Mon, 08 Jan 2007)
New Revision: 59416
Added:
projects/osgi/trunk/core/src/main/org/jboss/osgi/core/platform/
projects/osgi/trunk/core/src/main/org/jboss/osgi/core/platform/plugin/
projects/osgi/trunk/core/src/main/org/jboss/osgi/core/platform/plugin/AbstractBundleAdapter.java
projects/osgi/trunk/core/src/main/org/jboss/osgi/core/platform/plugin/FelixBundleAdapter.java
projects/osgi/trunk/core/src/main/org/jboss/osgi/core/platform/plugin/FelixPlatform.java
projects/osgi/trunk/core/src/main/org/jboss/osgi/core/platform/plugin/FelixWrapper.java
projects/osgi/trunk/core/src/main/org/jboss/osgi/core/platform/spi/
projects/osgi/trunk/core/src/main/org/jboss/osgi/core/platform/spi/BundleAdapter.java
projects/osgi/trunk/core/src/main/org/jboss/osgi/core/platform/spi/OSGiPlatform.java
Modified:
projects/osgi/trunk/core/core.iml
Log:
osgi platform; felix impl
Modified: projects/osgi/trunk/core/core.iml
===================================================================
--- projects/osgi/trunk/core/core.iml 2007-01-08 12:10:29 UTC (rev 59415)
+++ projects/osgi/trunk/core/core.iml 2007-01-08 12:44:54 UTC (rev 59416)
@@ -86,6 +86,15 @@
</SOURCES>
</library>
</orderEntry>
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/../thirdparty/felix/lib/felix.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
<orderEntryProperties />
</component>
</module>
Added: projects/osgi/trunk/core/src/main/org/jboss/osgi/core/platform/plugin/AbstractBundleAdapter.java
===================================================================
--- projects/osgi/trunk/core/src/main/org/jboss/osgi/core/platform/plugin/AbstractBundleAdapter.java 2007-01-08 12:10:29 UTC (rev 59415)
+++ projects/osgi/trunk/core/src/main/org/jboss/osgi/core/platform/plugin/AbstractBundleAdapter.java 2007-01-08 12:44:54 UTC (rev 59416)
@@ -0,0 +1,52 @@
+/*
+* 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.plugin;
+
+import org.jboss.osgi.core.platform.spi.BundleAdapter;
+import org.osgi.framework.Bundle;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class AbstractBundleAdapter implements BundleAdapter
+{
+ protected Bundle bundle;
+
+ protected AbstractBundleAdapter(Bundle bundle)
+ {
+ if (bundle == null)
+ {
+ throw new IllegalArgumentException("Bundle cannot be null.");
+ }
+ this.bundle = bundle;
+ }
+
+ public Long getBundleId()
+ {
+ return bundle.getBundleId();
+ }
+
+ public Bundle getUnderlyingBundle()
+ {
+ return bundle;
+ }
+}
Added: projects/osgi/trunk/core/src/main/org/jboss/osgi/core/platform/plugin/FelixBundleAdapter.java
===================================================================
--- projects/osgi/trunk/core/src/main/org/jboss/osgi/core/platform/plugin/FelixBundleAdapter.java 2007-01-08 12:10:29 UTC (rev 59415)
+++ projects/osgi/trunk/core/src/main/org/jboss/osgi/core/platform/plugin/FelixBundleAdapter.java 2007-01-08 12:44:54 UTC (rev 59416)
@@ -0,0 +1,52 @@
+/*
+* 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.plugin;
+
+import java.lang.reflect.Method;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class FelixBundleAdapter extends AbstractBundleAdapter
+{
+ private BundleContext bundleContext;
+
+ public FelixBundleAdapter(Bundle bundle)
+ {
+ super(bundle);
+ }
+
+ public BundleContext getBundleContext() throws Exception
+ {
+ if (bundleContext == null)
+ {
+ Class bundleClass = bundle.getClass();
+ Method getContext = bundleClass.getDeclaredMethod("getContext");
+ getContext.setAccessible(true);
+ bundleContext = (BundleContext) getContext.invoke(bundle);
+ }
+ return bundleContext;
+ }
+}
Added: projects/osgi/trunk/core/src/main/org/jboss/osgi/core/platform/plugin/FelixPlatform.java
===================================================================
--- projects/osgi/trunk/core/src/main/org/jboss/osgi/core/platform/plugin/FelixPlatform.java 2007-01-08 12:10:29 UTC (rev 59415)
+++ projects/osgi/trunk/core/src/main/org/jboss/osgi/core/platform/plugin/FelixPlatform.java 2007-01-08 12:44:54 UTC (rev 59416)
@@ -0,0 +1,86 @@
+/*
+* 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.plugin;
+
+import java.io.InputStream;
+import java.util.Properties;
+
+import org.jboss.osgi.core.platform.spi.BundleAdapter;
+import org.jboss.osgi.core.platform.spi.OSGiPlatform;
+import org.osgi.framework.Bundle;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class FelixPlatform implements OSGiPlatform
+{
+ private FelixWrapper felix;
+
+ protected Properties getConfigProperties()
+ {
+ // todo
+ return new Properties();
+ }
+
+ private void check()
+ {
+ if (felix == null || felix.getStatus() == FelixWrapper.STOPPING_STATUS)
+ throw new IllegalArgumentException("Felix platform already stopped.");
+ }
+
+ public void start() throws Exception
+ {
+ if (felix == null)
+ {
+ felix = new FelixWrapper();
+ }
+ felix.start(getConfigProperties());
+ }
+
+ public void stop() throws Exception
+ {
+ if (felix != null)
+ {
+ felix.shutdown();
+ }
+ }
+
+ public BundleAdapter installBundle(String location, InputStream is) throws Exception
+ {
+ check();
+ Bundle bundle = felix.installBundle(location, is);
+ return new FelixBundleAdapter(bundle);
+ }
+
+ public void updateBundle(Long bundleId, InputStream is) throws Exception
+ {
+ check();
+ felix.updateBundle(bundleId, is);
+ }
+
+ public void uninstallBundle(Long bundleId) throws Exception
+ {
+ check();
+ felix.uninstallBundle(bundleId);
+ }
+
+}
Added: projects/osgi/trunk/core/src/main/org/jboss/osgi/core/platform/plugin/FelixWrapper.java
===================================================================
--- projects/osgi/trunk/core/src/main/org/jboss/osgi/core/platform/plugin/FelixWrapper.java 2007-01-08 12:10:29 UTC (rev 59415)
+++ projects/osgi/trunk/core/src/main/org/jboss/osgi/core/platform/plugin/FelixWrapper.java 2007-01-08 12:44:54 UTC (rev 59416)
@@ -0,0 +1,129 @@
+/*
+* 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.plugin;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.io.InputStream;
+
+import org.apache.felix.framework.Felix;
+import org.apache.felix.framework.util.MutablePropertyResolverImpl;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class FelixWrapper extends Felix
+{
+ private static Logger log = Logger.getLogger(FelixWrapper.class);
+
+ private Felix felix;
+ private Map<Long, Bundle> installedBundles;
+
+ public FelixWrapper()
+ {
+ felix = new Felix();
+ installedBundles = new HashMap<Long, Bundle>();
+ }
+
+ public void start(Map properties)
+ {
+ felix.start(new MutablePropertyResolverImpl(properties), null);
+ }
+
+ public void stop()
+ {
+ installedBundles.clear();
+ installedBundles = null;
+ felix.shutdown();
+ felix = null;
+ }
+
+ public Bundle installBundle(String location, InputStream is) throws BundleException
+ {
+ if (log.isTraceEnabled())
+ {
+ log.trace("Installing bundle from location: " + location);
+ }
+ Bundle bundle = super.installBundle(location, is);
+ long bundleId = bundle.getBundleId();
+ if (log.isTraceEnabled())
+ {
+ log.trace("Installed bundle with id: " + bundleId);
+ }
+ installedBundles.put(bundleId, bundle);
+ return bundle;
+ }
+
+ // todo - see if the same bundle can be used even after update
+ public void updateBundle(Long bundleId, InputStream inputStream) throws BundleException
+ {
+ Bundle bundle = installedBundles.get(bundleId);
+ if (bundle != null)
+ {
+ if (log.isTraceEnabled())
+ {
+ log.trace("Updating bundle with id: " + bundleId);
+ }
+ if (inputStream != null)
+ {
+ bundle.update(inputStream);
+ }
+ else
+ {
+ bundle.update();
+ }
+ if (log.isTraceEnabled())
+ {
+ log.trace("Bundle with id: " + bundleId + " updated.");
+ }
+ }
+ else
+ {
+ throw new BundleException("No such bundle to update, id: " + bundleId);
+ }
+ }
+
+ public void uninstallBundle(Long bundleId) throws BundleException
+ {
+ Bundle bundle = installedBundles.get(bundleId);
+ if (bundle != null)
+ {
+ if (log.isTraceEnabled())
+ {
+ log.trace("Uninstalling bundle with id: " + bundleId);
+ }
+ bundle.uninstall();
+ if (log.isTraceEnabled())
+ {
+ log.trace("Bundle with id: " + bundleId + " unistalled.");
+ }
+ }
+ else
+ {
+ log.warn("No such bundle to uninstall, id: " + bundleId);
+ }
+ }
+
+}
Added: projects/osgi/trunk/core/src/main/org/jboss/osgi/core/platform/spi/BundleAdapter.java
===================================================================
--- projects/osgi/trunk/core/src/main/org/jboss/osgi/core/platform/spi/BundleAdapter.java 2007-01-08 12:10:29 UTC (rev 59415)
+++ projects/osgi/trunk/core/src/main/org/jboss/osgi/core/platform/spi/BundleAdapter.java 2007-01-08 12:44:54 UTC (rev 59416)
@@ -0,0 +1,56 @@
+/*
+* 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;
+import org.osgi.framework.Bundle;
+
+/**
+ * Additional bundle access points
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface BundleAdapter
+{
+ /**
+ * Maybe use just bundle Id.
+ * @return adapter's bundle id
+ */
+ Long getBundleId();
+
+ /**
+ * Get the bundle of this adapter.
+ * @return Bundle adapter's underlying bundle
+ */
+ Bundle getUnderlyingBundle();
+
+ /**
+ * Abstraction if getting the bundle
+ * Different platform have different way of getting the BC.
+ * Sometimes there is a 'hack-ish' way of getting this.
+ *
+ * @return bundle's context
+ * @throws Exception exception if cannot access bundle context
+ */
+ BundleContext getBundleContext() throws Exception;
+
+}
Added: projects/osgi/trunk/core/src/main/org/jboss/osgi/core/platform/spi/OSGiPlatform.java
===================================================================
--- projects/osgi/trunk/core/src/main/org/jboss/osgi/core/platform/spi/OSGiPlatform.java 2007-01-08 12:10:29 UTC (rev 59415)
+++ projects/osgi/trunk/core/src/main/org/jboss/osgi/core/platform/spi/OSGiPlatform.java 2007-01-08 12:44:54 UTC (rev 59416)
@@ -0,0 +1,74 @@
+/*
+* 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 java.io.InputStream;
+
+/**
+ * Common OSGi platform contract - platform lifecycle + bundle handling
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface OSGiPlatform
+{
+ /**
+ * Start platform
+ *
+ * @throws Exception
+ */
+ void start() throws Exception;
+
+ /**
+ * Stop platform
+ *
+ * @throws Exception
+ */
+ void stop() throws Exception;
+
+ /**
+ * Install bundle with location or input stream
+ *
+ * @param location
+ * @param is
+ * @return installed bundle's adapter
+ * @throws Exception
+ */
+ BundleAdapter installBundle(String location, InputStream is) throws Exception;
+
+ /**
+ * Update bundle
+ *
+ * @param bundleId id of bundle to update
+ * @param is optional different bundle input stream
+ * @throws Exception
+ */
+ void updateBundle(Long bundleId, InputStream is) throws Exception;
+
+ /**
+ * Uninstall bundle
+ *
+ * @param bundleId id of bundle to uninstall
+ * @throws Exception
+ */
+ void uninstallBundle(Long bundleId) throws Exception;
+
+}
More information about the jboss-cvs-commits
mailing list