[jboss-osgi-commits] JBoss-OSGI SVN: r99648 - in projects/jboss-osgi: projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework and 11 other directories.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Wed Jan 20 04:27:44 EST 2010


Author: thomas.diesler at jboss.com
Date: 2010-01-20 04:27:43 -0500 (Wed, 20 Jan 2010)
New Revision: 99648

Added:
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/GenericServiceReferenceWrapper.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/ServiceManagerPluginImpl.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins/ServiceManagerPlugin.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/servicemix/
Removed:
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/GenericServiceReferenceWrapper.java
Modified:
   projects/jboss-osgi/projects/runtime/framework/trunk/src/etc/osgitck/jboss-osgi-bootstrap.xml
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/FilterParserAndMatcher.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins/internal/AbstractPlugin.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins/internal/AbstractServicePlugin.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins/internal/AutoInstallPluginImpl.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins/internal/BundleStoragePluginImpl.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins/internal/SystemPackagesPluginImpl.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/service/internal/LifecycleInterceptorServiceImpl.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/service/internal/PackageAdminImpl.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/fragments/FragmentTestCase.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bootstrap/jboss-osgi-bootstrap.xml
   projects/jboss-osgi/trunk/distribution/installer/src/main/resources/jbossas/jboss-beans-jbossmc.xml
   projects/jboss-osgi/trunk/distribution/installer/src/main/resources/runtime/server/conf/jboss-osgi-bootstrap.xml
   projects/jboss-osgi/trunk/reactor/blueprint/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
   projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
   projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
Log:
Externalize ServiceManagerPlugin

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/etc/osgitck/jboss-osgi-bootstrap.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/etc/osgitck/jboss-osgi-bootstrap.xml	2010-01-20 09:22:33 UTC (rev 99647)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/etc/osgitck/jboss-osgi-bootstrap.xml	2010-01-20 09:27:43 UTC (rev 99648)
@@ -57,6 +57,9 @@
   <bean name="OSGiFrameworkEventsPlugin" class="org.jboss.osgi.framework.plugins.internal.FrameworkEventsPluginImpl">
     <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
   </bean>
+  <bean name="OSGiServiceManager" class="org.jboss.osgi.framework.bundle.ServiceManagerPluginImpl">
+    <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
+  </bean>
   <bean name="OSGiStoragePlugin" class="org.jboss.osgi.framework.plugins.internal.BundleStoragePluginImpl">
     <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
   </bean>

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java	2010-01-20 09:22:33 UTC (rev 99647)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java	2010-01-20 09:27:43 UTC (rev 99648)
@@ -32,7 +32,6 @@
 import java.util.Collections;
 import java.util.Dictionary;
 import java.util.Enumeration;
-import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.List;
 import java.util.Locale;
@@ -50,6 +49,7 @@
 import org.jboss.osgi.framework.plugins.BundleStoragePlugin;
 import org.jboss.osgi.framework.plugins.FrameworkEventsPlugin;
 import org.jboss.osgi.framework.plugins.LifecycleInterceptorServicePlugin;
+import org.jboss.osgi.framework.plugins.ServiceManagerPlugin;
 import org.jboss.osgi.framework.util.CaseInsensitiveDictionary;
 import org.jboss.osgi.spi.NotImplementedException;
 import org.jboss.osgi.spi.util.ConstantsHelper;
@@ -433,21 +433,8 @@
    {
       checkInstalled();
 
-      Set<ControllerContext> contexts = getRegisteredContexts();
-      if (contexts.isEmpty())
-         return null;
-
-      OSGiBundleManager manager = getBundleManager();
-      Set<ServiceReference> result = new HashSet<ServiceReference>();
-      for (ControllerContext context : contexts)
-      {
-         ServiceReference ref = manager.getServiceReferenceForContext(context);
-         if (ref != null)
-            result.add(ref);
-      }
-      if (result.isEmpty())
-         return null;
-      return result.toArray(new ServiceReference[result.size()]);
+      ServiceManagerPlugin plugin = getBundleManager().getPlugin(ServiceManagerPlugin.class);
+      return plugin.getRegisteredServices(this);
    }
 
    /**
@@ -484,52 +471,37 @@
 
    public ServiceReference[] getServicesInUse()
    {
-      Set<ControllerContext> contexts = getUsedContexts(this);
-      if (contexts == null || contexts.isEmpty())
-         return null;
-
-      OSGiBundleManager manager = getBundleManager();
-      List<ServiceReference> references = new ArrayList<ServiceReference>();
-      for (ControllerContext context : contexts)
-      {
-         ServiceReference ref = manager.getServiceReferenceForContext(context);
-         if (ref != null)
-            references.add(ref);
-      }
-
-      if (references.isEmpty())
-         return null;
-      return references.toArray(new ServiceReference[references.size()]);
+      checkInstalled();
+      ServiceManagerPlugin plugin = getBundleManager().getPlugin(ServiceManagerPlugin.class);
+      return plugin.getServicesInUse(this);
    }
 
    public ServiceReference[] getAllServiceReferences(String clazz, String filter) throws InvalidSyntaxException
    {
       checkValidBundleContext();
-      return getBundleManager().getServiceReferences(this, clazz, filter, false);
+      ServiceManagerPlugin plugin = getBundleManager().getPlugin(ServiceManagerPlugin.class);
+      return plugin.getAllServiceReferences(this, clazz, filter);
    }
 
    public Object getService(ServiceReference reference)
    {
       checkValidBundleContext();
-
-      if (reference == null)
-         throw new IllegalArgumentException("Null reference");
-
-      return getBundleManager().getService(this, reference);
+      ServiceManagerPlugin plugin = getBundleManager().getPlugin(ServiceManagerPlugin.class);
+      return plugin.getService(this, reference);
    }
 
    public ServiceReference getServiceReference(String clazz)
    {
       checkValidBundleContext();
-      if (clazz == null)
-         throw new IllegalArgumentException("Null clazz");
-      return getBundleManager().getServiceReference(this, clazz);
+      ServiceManagerPlugin plugin = getBundleManager().getPlugin(ServiceManagerPlugin.class);
+      return plugin.getServiceReference(this, clazz);
    }
 
    public ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException
    {
       checkValidBundleContext();
-      return getBundleManager().getServiceReferences(this, clazz, filter, true);
+      ServiceManagerPlugin plugin = getBundleManager().getPlugin(ServiceManagerPlugin.class);
+      return plugin.getServiceReferences(this, clazz, filter);
    }
 
    @SuppressWarnings({ "rawtypes" })
@@ -544,16 +516,28 @@
    public ServiceRegistration registerService(String[] clazzes, Object service, Dictionary properties)
    {
       checkValidBundleContext();
-
-      OSGiServiceState serviceState = getBundleManager().registerService(this, clazzes, service, properties);
+      ServiceManagerPlugin plugin = getBundleManager().getPlugin(ServiceManagerPlugin.class);
+      OSGiServiceState serviceState = (OSGiServiceState)plugin.registerService(this, clazzes, service, properties);
       afterServiceRegistration(serviceState);
       return serviceState.getRegistration();
    }
 
+   void unregisterService(OSGiServiceState serviceState)
+   {
+      beforeServiceUnregistration(serviceState);
+      ServiceManagerPlugin plugin = getBundleManager().getPlugin(ServiceManagerPlugin.class);
+      plugin.unregisterService(serviceState);
+   }
+
+   public boolean ungetService(ServiceReference reference)
+   {
+      checkValidBundleContext();
+      ServiceManagerPlugin plugin = getBundleManager().getPlugin(ServiceManagerPlugin.class);
+      return plugin.ungetService(this, reference);
+   }
+
    /**
     * After service registration callback.
-    *
-    * @param service the service
     */
    protected void afterServiceRegistration(OSGiServiceState service)
    {
@@ -561,40 +545,11 @@
 
    /**
     * Before service unregistration callback.
-    *
-    * @param service the service
     */
    protected void beforeServiceUnregistration(OSGiServiceState service)
    {
    }
-
-   /**
-    * Unregister a service
-    * 
-    * @param serviceState the service state
-    */
-   void unregisterService(OSGiServiceState serviceState)
-   {
-      beforeServiceUnregistration(serviceState);
-      getBundleManager().unregisterService(serviceState);
-   }
-
-   public boolean ungetService(ServiceReference reference)
-   {
-      if (reference == null)
-         throw new IllegalArgumentException("Null reference");
-
-      // Check if the service is still in use by this bundle
-      ControllerContextHandle handle = (ControllerContextHandle)reference;
-      ControllerContext context = handle.getContext();
-      if (OSGiBundleManager.isUnregistered(context))
-         return false;
-
-      checkValidBundleContext();
-
-      return ungetContext(context);
-   }
-
+   
    boolean ungetContext(ControllerContext context)
    {
       return getBundleManager().ungetContext(this, context);
@@ -710,7 +665,7 @@
     * @param className the class name
     * @return the source or null if no source
     */
-   Object getSource(String className)
+   public Object getSource(String className)
    {
       // [TODO] some more efficient way than using the class?
       try

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/FilterParserAndMatcher.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/FilterParserAndMatcher.java	2010-01-20 09:22:33 UTC (rev 99647)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/FilterParserAndMatcher.java	2010-01-20 09:27:43 UTC (rev 99648)
@@ -57,6 +57,7 @@
       return QualifierContent.getContent("filter");
    }
 
+   @SuppressWarnings("rawtypes")
    public boolean matches(ControllerContext context, Set<Object> suppliedQualifiers, Filter filter)
    {
       MetaData metaData = context.getScopeInfo().getMetaData();

Deleted: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/GenericServiceReferenceWrapper.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/GenericServiceReferenceWrapper.java	2010-01-20 09:22:33 UTC (rev 99647)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/GenericServiceReferenceWrapper.java	2010-01-20 09:27:43 UTC (rev 99648)
@@ -1,135 +0,0 @@
-/*
-* 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 java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.jboss.dependency.spi.ControllerContext;
-import org.jboss.dependency.spi.tracker.ContextTracker;
-import org.jboss.dependency.spi.tracker.ContextTracking;
-import org.osgi.framework.Bundle;
-
-/**
- * GenericServiceReferenceWrapper.
- *
- * @author <a href="ales.justin at jboss.org">Ales Justin</a>
- */
-class GenericServiceReferenceWrapper extends ControllerContextHandle
-{
-   private ControllerContext context;
-   private AbstractBundleState bundleState;
-
-   public GenericServiceReferenceWrapper(ControllerContext context, AbstractBundleState bundleState)
-   {
-      if (context == null)
-         throw new IllegalArgumentException("Null context");
-      if (bundleState == null)
-         throw new IllegalArgumentException("Null bundle state");
-
-      this.context = context;
-      this.bundleState = bundleState;
-   }
-
-   ControllerContext getContext()
-   {
-      return context;
-   }
-
-   public Object getProperty(String key)
-   {
-      return MDRUtils.getProperty(context, key, Object.class);
-   }
-
-   public String[] getPropertyKeys()
-   {
-      Dictionary<String, Object> dictionary = MDRUtils.getProperties(context);
-      String[] keys = new String[dictionary.size()];
-      int i = 0;
-      Enumeration<String> e = dictionary.keys();
-      while (e.hasMoreElements())
-         keys[i++] = e.nextElement();
-      return keys;
-   }
-
-   public Bundle getBundle()
-   {
-      if (OSGiBundleManager.isUnregistered(context))
-         return null;
-      
-      return bundleState.getBundleInternal();
-   }
-
-   public Bundle[] getUsingBundles()
-   {
-      if (context instanceof ContextTracking)
-      {
-         ContextTracking tracking = (ContextTracking)context;
-         ContextTracker ct = tracking.getContextTracker();
-         if (ct == null)
-            return null;
-
-         OSGiBundleManager manager = bundleState.getBundleManager();
-         Set<Object> users = ct.getUsers(context);
-         Set<Bundle> bundles = new HashSet<Bundle>();
-         for (Object user : users)
-         {
-            AbstractBundleState abs = manager.getBundleForUser(user);
-            bundles.add(abs.getBundleInternal());
-         }
-         if (bundles.isEmpty() == false)
-            return bundles.toArray(new Bundle[bundles.size()]);
-      }
-      return null;
-   }
-
-   public boolean isAssignableTo(Bundle bundle, String className)
-   {
-      return MDRUtils.isAssignableTo(context, bundleState, bundle, className); 
-   }
-
-   public int compareTo(Object obj)
-   {
-      return MDRUtils.compareTo(context, obj);
-   }
-
-   public int hashCode()
-   {
-      return context.hashCode();
-   }
-
-   public boolean equals(Object obj)
-   {
-      if (obj instanceof GenericServiceReferenceWrapper == false)
-         return false;
-
-      GenericServiceReferenceWrapper other = (GenericServiceReferenceWrapper)obj;
-      return context == other.context;
-   }
-
-   public String toString()
-   {
-      return context.toString();
-   }
-}
\ No newline at end of file

Copied: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/GenericServiceReferenceWrapper.java (from rev 99640, projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/GenericServiceReferenceWrapper.java)
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/GenericServiceReferenceWrapper.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/GenericServiceReferenceWrapper.java	2010-01-20 09:27:43 UTC (rev 99648)
@@ -0,0 +1,135 @@
+/*
+* 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 java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.tracker.ContextTracker;
+import org.jboss.dependency.spi.tracker.ContextTracking;
+import org.osgi.framework.Bundle;
+
+/**
+ * GenericServiceReferenceWrapper.
+ *
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
+ */
+class GenericServiceReferenceWrapper extends ControllerContextHandle
+{
+   private ControllerContext context;
+   private AbstractBundleState bundleState;
+
+   public GenericServiceReferenceWrapper(ControllerContext context, AbstractBundleState bundleState)
+   {
+      if (context == null)
+         throw new IllegalArgumentException("Null context");
+      if (bundleState == null)
+         throw new IllegalArgumentException("Null bundle state");
+
+      this.context = context;
+      this.bundleState = bundleState;
+   }
+
+   ControllerContext getContext()
+   {
+      return context;
+   }
+
+   public Object getProperty(String key)
+   {
+      return MDRUtils.getProperty(context, key, Object.class);
+   }
+
+   public String[] getPropertyKeys()
+   {
+      Dictionary<String, Object> dictionary = MDRUtils.getProperties(context);
+      String[] keys = new String[dictionary.size()];
+      int i = 0;
+      Enumeration<String> e = dictionary.keys();
+      while (e.hasMoreElements())
+         keys[i++] = e.nextElement();
+      return keys;
+   }
+
+   public Bundle getBundle()
+   {
+      if (OSGiBundleManager.isUnregistered(context))
+         return null;
+      
+      return bundleState.getBundleInternal();
+   }
+
+   public Bundle[] getUsingBundles()
+   {
+      if (context instanceof ContextTracking)
+      {
+         ContextTracking tracking = (ContextTracking)context;
+         ContextTracker ct = tracking.getContextTracker();
+         if (ct == null)
+            return null;
+
+         OSGiBundleManager manager = bundleState.getBundleManager();
+         Set<Object> users = ct.getUsers(context);
+         Set<Bundle> bundles = new HashSet<Bundle>();
+         for (Object user : users)
+         {
+            AbstractBundleState abs = manager.getBundleForUser(user);
+            bundles.add(abs.getBundleInternal());
+         }
+         if (bundles.isEmpty() == false)
+            return bundles.toArray(new Bundle[bundles.size()]);
+      }
+      return null;
+   }
+
+   public boolean isAssignableTo(Bundle bundle, String className)
+   {
+      return MDRUtils.isAssignableTo(context, bundleState, bundle, className); 
+   }
+
+   public int compareTo(Object obj)
+   {
+      return MDRUtils.compareTo(context, obj);
+   }
+
+   public int hashCode()
+   {
+      return context.hashCode();
+   }
+
+   public boolean equals(Object obj)
+   {
+      if (obj instanceof GenericServiceReferenceWrapper == false)
+         return false;
+
+      GenericServiceReferenceWrapper other = (GenericServiceReferenceWrapper)obj;
+      return context == other.context;
+   }
+
+   public String toString()
+   {
+      return context.toString();
+   }
+}
\ No newline at end of file

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java	2010-01-20 09:22:33 UTC (rev 99647)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java	2010-01-20 09:27:43 UTC (rev 99648)
@@ -34,7 +34,6 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Dictionary;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Locale;
@@ -52,7 +51,6 @@
 import org.jboss.dependency.spi.Controller;
 import org.jboss.dependency.spi.ControllerContext;
 import org.jboss.dependency.spi.ControllerState;
-import org.jboss.dependency.spi.tracker.ContextTracker;
 import org.jboss.deployers.client.spi.DeployerClient;
 import org.jboss.deployers.client.spi.IncompleteDeploymentException;
 import org.jboss.deployers.client.spi.IncompleteDeployments;
@@ -67,16 +65,7 @@
 import org.jboss.deployers.vfs.spi.client.VFSDeployment;
 import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
 import org.jboss.kernel.Kernel;
-import org.jboss.kernel.spi.dependency.KernelController;
-import org.jboss.kernel.spi.qualifier.QualifierMatchers;
 import org.jboss.logging.Logger;
-import org.jboss.metadata.plugins.loader.memory.MemoryMetaDataLoader;
-import org.jboss.metadata.spi.MutableMetaData;
-import org.jboss.metadata.spi.repository.MutableMetaDataRepository;
-import org.jboss.metadata.spi.retrieval.MetaDataRetrieval;
-import org.jboss.metadata.spi.retrieval.MetaDataRetrievalFactory;
-import org.jboss.metadata.spi.scope.CommonLevels;
-import org.jboss.metadata.spi.scope.ScopeKey;
 import org.jboss.osgi.deployment.deployer.Deployment;
 import org.jboss.osgi.deployment.deployer.DeploymentFactory;
 import org.jboss.osgi.framework.deployers.OSGiBundleActivatorDeployer;
@@ -90,7 +79,6 @@
 import org.jboss.osgi.framework.plugins.Plugin;
 import org.jboss.osgi.framework.plugins.ResolverPlugin;
 import org.jboss.osgi.framework.plugins.ServicePlugin;
-import org.jboss.osgi.framework.util.NoFilter;
 import org.jboss.osgi.framework.util.URLHelper;
 import org.jboss.osgi.spi.util.BundleInfo;
 import org.jboss.util.platform.Java;
@@ -102,12 +90,7 @@
 import org.osgi.framework.BundleEvent;
 import org.osgi.framework.BundleException;
 import org.osgi.framework.Constants;
-import org.osgi.framework.Filter;
 import org.osgi.framework.FrameworkEvent;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceEvent;
-import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.framework.Version;
 import org.osgi.service.packageadmin.PackageAdmin;
@@ -149,12 +132,8 @@
    private DeployerClient deployerClient;
    /** The deployment structure */
    private MainDeployerStructure deployerStructure;
-   /** The deployment registry */
+      /** The deployment registry */
    private DeploymentRegistry registry;
-   /** The previous context tracker */
-   private ContextTracker previousTracker;
-   /** The instance metadata factory */
-   private MetaDataRetrievalFactory factory;
    /** The executor */
    private Executor executor;
    /** The system bundle */
@@ -242,205 +221,14 @@
       // Create the system Bundle
       systemBundle = new OSGiSystemState();
       addBundle(systemBundle);
-
-      applyMDRUsage(true);
    }
 
    public void stop()
    {
-      applyMDRUsage(false);
+      // nothing to do
    }
 
    /**
-    * Apply OSGi's MDR usage:
-    * - add/remove system bundle as default context tracker
-    * - add/remove instance metadata retrieval factory 
-    *
-    * @param register do we register or unregister
-    */
-   protected void applyMDRUsage(boolean register)
-   {
-      MutableMetaDataRepository repository = kernel.getMetaDataRepository().getMetaDataRepository();
-      MetaDataRetrieval retrieval = repository.getMetaDataRetrieval(ScopeKey.DEFAULT_SCOPE);
-      if (register && retrieval == null)
-      {
-         retrieval = new MemoryMetaDataLoader(ScopeKey.DEFAULT_SCOPE);
-         repository.addMetaDataRetrieval(retrieval);
-      }
-      if (retrieval != null && retrieval instanceof MutableMetaData)
-      {
-         MutableMetaData mmd = (MutableMetaData)retrieval;
-         if (register)
-         {
-            previousTracker = mmd.addMetaData(systemBundle, ContextTracker.class);
-         }
-         else
-         {
-            if (previousTracker == null)
-            {
-               mmd.removeMetaData(ContextTracker.class);
-               if (retrieval.isEmpty())
-                  repository.removeMetaDataRetrieval(retrieval.getScope());
-            }
-            else
-            {
-               mmd.addMetaData(previousTracker, ContextTracker.class);
-            }
-         }
-      }
-
-      // osgi ldap filter parsing and matching
-      FilterParserAndMatcher fpm = FilterParserAndMatcher.INSTANCE;
-      QualifierMatchers matchers = QualifierMatchers.getInstance();
-
-      if (register)
-      {
-         matchers.addParser(fpm);
-         matchers.addMatcher(fpm);
-
-         MetaDataRetrievalFactory mdrFactory = factory;
-         if (mdrFactory == null)
-         {
-            Controller controller = kernel.getController();
-            InstanceMetaDataRetrievalFactory imdrf = new InstanceMetaDataRetrievalFactory(controller);
-            imdrf.addFactory(new OSGiServiceStateDictionaryFactory());
-            imdrf.addFactory(new KernelDictionaryFactory(kernel.getConfigurator()));
-            // TODO - JMX?
-            mdrFactory = imdrf;
-         }
-         repository.addMetaDataRetrievalFactory(CommonLevels.INSTANCE, mdrFactory);
-      }
-      else
-      {
-         repository.removeMetaDataRetrievalFactory(CommonLevels.INSTANCE);
-
-         matchers.removeParser(fpm.getHandledContent());
-         matchers.removeMatcher(fpm.getHandledType());
-      }
-   }
-
-   /**
-    * Set instance metadata factory.
-    *
-    * @param factory the instance metadata factory
-    */
-   public void setInstanceMetaDataFactory(MetaDataRetrievalFactory factory)
-   {
-      this.factory = factory;
-   }
-
-   /**
-    * Put context to deployment mapping.
-    *
-    * @param context the context
-    * @param unit the deployment
-    * @return previous mapping value
-    */
-   DeploymentUnit putContext(ControllerContext context, DeploymentUnit unit)
-   {
-      return registry.putContext(context, unit);
-   }
-
-   /**
-    * Remove context to deployment mapping.
-    *
-    * @param context the context
-    * @param unit the deployment
-    * @return is previous mapping value same as unit param
-    */
-   DeploymentUnit removeContext(ControllerContext context, DeploymentUnit unit)
-   {
-      return registry.removeContext(context, unit);
-   }
-
-   /**
-    * Get bundle for user tracker.
-    *
-    * @param user the user tracker object
-    * @return bundle state
-    */
-   AbstractBundleState getBundleForUser(Object user)
-   {
-      if (user instanceof AbstractBundleState)
-         return (AbstractBundleState)user;
-      else if (user instanceof ControllerContext)
-         return getBundleForContext((ControllerContext)user);
-      else
-         throw new IllegalArgumentException("Unknown tracker type: " + user);
-   }
-
-   /**
-    * Get bundle for context.
-    *
-    * @param context the context
-    * @return bundle state
-    */
-   AbstractBundleState getBundleForContext(ControllerContext context)
-   {
-      if (context instanceof OSGiServiceState)
-      {
-         OSGiServiceState service = (OSGiServiceState)context;
-         return service.getBundleState();
-      }
-
-      DeploymentUnit unit = registry.getDeployment(context);
-      if (unit != null)
-      {
-         synchronized (unit)
-         {
-            OSGiBundleState bundleState = unit.getAttachment(OSGiBundleState.class);
-            if (bundleState == null)
-            {
-               OSGiMetaData osgiMetaData = unit.getAttachment(OSGiMetaData.class);
-               if (osgiMetaData == null)
-               {
-                  Manifest manifest = unit.getAttachment(Manifest.class);
-                  // [TODO] we need a mechanism to construct an OSGiMetaData from an easier factory
-                  if (manifest == null)
-                     manifest = new Manifest();
-                  // [TODO] populate some bundle information
-                  Attributes attributes = manifest.getMainAttributes();
-                  attributes.put(new Name(Constants.BUNDLE_SYMBOLICNAME), unit.getName());
-                  osgiMetaData = new AbstractOSGiMetaData(manifest);
-                  unit.addAttachment(OSGiMetaData.class, osgiMetaData);
-               }
-
-               try
-               {
-                  bundleState = (OSGiBundleState)addDeployment(unit);
-                  bundleState.startInternal();
-               }
-               catch (Throwable t)
-               {
-                  throw new RuntimeException("Cannot dynamically add generic bundle: " + unit, t);
-               }
-            }
-            return bundleState;
-         }
-      }
-
-      return systemBundle;
-   }
-
-   /**
-    * Get service reference for context.
-    *
-    * @param context the context
-    * @return service reference
-    */
-   ServiceReference getServiceReferenceForContext(ControllerContext context)
-   {
-      if (context instanceof OSGiServiceState)
-      {
-         OSGiServiceState service = (OSGiServiceState)context;
-         return service.hasPermission() ? service.getReferenceInternal() : null;
-      }
-
-      AbstractBundleState bundleState = getBundleForContext(context);
-      return new GenericServiceReferenceWrapper(context, bundleState);
-   }
-
-   /**
     * Get the kernel
     *
     * @return the kernel
@@ -1519,7 +1307,7 @@
     * @param clazz the class
     * @return class or null
     */
-   Class<?> loadClass(Bundle bundle, String clazz)
+   Class<?> loadClassFailsafe(Bundle bundle, String clazz)
    {
       try
       {
@@ -1532,284 +1320,6 @@
    }
 
    /**
-    * Do we have a permission to use context.
-    *
-    * @param context the context
-    * @return true if allowed to use context, false otherwise
-    */
-   private boolean hasPermission(ControllerContext context)
-   {
-      // TODO - make thisa generic, w/o casting
-      if (context instanceof OSGiServiceState)
-      {
-         OSGiServiceState serviceState = (OSGiServiceState)context;
-         return serviceState.hasPermission();
-      }
-      return true;
-   }
-
-   /**
-    * Get services
-    * 
-    * @param bundle the referencing bundle
-    * @param clazz any class
-    * @param filter any filter
-    * @param checkAssignable whether to check isAssignable
-    * @return the services
-    */
-   Collection<ServiceReference> getServices(AbstractBundleState bundle, String clazz, Filter filter, boolean checkAssignable)
-   {
-      Set<ControllerContext> contexts;
-      KernelController controller = kernel.getController();
-
-      // Don't check assignabilty for the system bundle
-      boolean isSystemBundle = (bundle.getBundleId() == 0);
-      if (isSystemBundle)
-         checkAssignable = false;
-
-      // TODO - a bit slow for system bundle
-      if (clazz != null && isSystemBundle == false)
-      {
-         Class<?> type = loadClass(bundle, clazz);
-         if (type == null)
-            return null; // or check all?
-
-         contexts = controller.getContexts(type, ControllerState.INSTALLED);
-      }
-      else
-      {
-         contexts = controller.getContextsByState(ControllerState.INSTALLED);
-      }
-
-      if (contexts == null || contexts.isEmpty())
-         return null;
-
-      if (filter == null)
-         filter = NoFilter.INSTANCE;
-
-      List<ControllerContext> sorted = new ArrayList<ControllerContext>(contexts);
-      Collections.sort(sorted, ContextComparator.INSTANCE); // Sort by the spec, should bubble up
-      Collection<ServiceReference> result = new ArrayList<ServiceReference>();
-      for (ControllerContext context : sorted)
-      {
-         // re-check?? -- we already only get INSTALLED 
-         if (isUnregistered(context) == false)
-         {
-            ServiceReference ref = getServiceReferenceForContext(context);
-            if (filter.match(ref) && hasPermission(context))
-            {
-               if (clazz == null || isSystemBundle == false || MDRUtils.matchClass(context, clazz))
-               {
-                  // Check the assignability
-                  if (checkAssignable == false || MDRUtils.isAssignableTo(context, bundle))
-                     result.add(ref);
-               }
-            }
-         }
-      }
-      return result;
-   }
-
-   /**
-    * Get service reference
-    * 
-    * @param bundle the referencing bundle
-    * @param clazz any class
-    * @return the reference
-    */
-   ServiceReference getServiceReference(AbstractBundleState bundle, String clazz)
-   {
-      Collection<ServiceReference> services = getServices(bundle, clazz, null, true);
-      if (services == null || services.isEmpty())
-         return null;
-
-      return services.iterator().next();
-   }
-
-   /**
-    * Get service references
-    * 
-    * @param bundle the referencing bundle
-    * @param clazz any class
-    * @param filter any filter
-    * @param checkAssignable whether to check isAssignable
-    * @return the services
-    */
-   ServiceReference[] getServiceReferences(AbstractBundleState bundle, String clazz, Filter filter, boolean checkAssignable)
-   {
-      Collection<ServiceReference> services = getServices(bundle, clazz, filter, checkAssignable);
-      if (services == null || services.isEmpty())
-         return null;
-
-      return services.toArray(new ServiceReference[services.size()]);
-   }
-
-   /**
-    * Get service references
-    * 
-    * @param bundle the referencing bundle
-    * @param clazz any class
-    * @param filterStr any filter
-    * @param checkAssignable whether to check isAssignable
-    * @return the services
-    * @throws InvalidSyntaxException when the filter is invalid
-    */
-   ServiceReference[] getServiceReferences(AbstractBundleState bundle, String clazz, String filterStr, boolean checkAssignable) throws InvalidSyntaxException
-   {
-      Filter filter = NoFilter.INSTANCE;
-      if (filterStr != null)
-         filter = FrameworkUtil.createFilter(filterStr);
-
-      return getServiceReferences(bundle, clazz, filter, checkAssignable);
-   }
-
-   /**
-    * Register a service
-    * 
-    * @param bundleState the bundle
-    * @param clazzes the classes to implement
-    * @param service the service
-    * @param properties the properties
-    * @return the service state
-    */
-   @SuppressWarnings("rawtypes")
-   OSGiServiceState registerService(AbstractBundleState bundleState, String[] clazzes, Object service, Dictionary properties)
-   {
-      OSGiServiceState result = new OSGiServiceState(bundleState, clazzes, service, properties);
-      result.internalRegister();
-      try
-      {
-         Controller controller = kernel.getController();
-         controller.install(result);
-      }
-      catch (Throwable t)
-      {
-         fireError(bundleState, "installing service to MC in", t);
-         throw new RuntimeException(t);
-      }
-
-      FrameworkEventsPlugin plugin = getPlugin(FrameworkEventsPlugin.class);
-      plugin.fireServiceEvent(bundleState, ServiceEvent.REGISTERED, result);
-
-      return result;
-   }
-
-   /**
-    * Get registered contexts for bundle.
-    *
-    * @param bundleState the owning bundle
-    * @return registered contexts
-    */
-   Set<ControllerContext> getRegisteredContext(AbstractDeployedBundleState bundleState)
-   {
-      DeploymentUnit unit = bundleState.getDeploymentUnit();
-      return registry.getContexts(unit);
-   }
-
-   /**
-    * Unregister a service
-    * 
-    * @param serviceState the service state
-    */
-   void unregisterService(OSGiServiceState serviceState)
-   {
-      Controller controller = kernel.getController();
-      controller.uninstall(serviceState.getName());
-
-      serviceState.internalUnregister();
-
-      FrameworkEventsPlugin plugin = getPlugin(FrameworkEventsPlugin.class);
-      plugin.fireServiceEvent(serviceState.getBundleState(), ServiceEvent.UNREGISTERING, serviceState);
-   }
-
-   /**
-    * Unregister contexts.
-    *
-    * @param bundleState the stopping bundle
-    */
-   void unregisterContexts(AbstractDeployedBundleState bundleState)
-   {
-      DeploymentUnit unit = bundleState.getDeploymentUnit();
-      Set<ControllerContext> contexts = registry.getContexts(unit);
-      for (ControllerContext context : contexts)
-      {
-         unregisterContext(context);
-      }
-   }
-
-   /**
-    * Unregister context.
-    *
-    * @param context the context
-    */
-   private static void unregisterContext(ControllerContext context)
-   {
-      if (context instanceof ServiceRegistration)
-      {
-         ServiceRegistration service = (ServiceRegistration)context;
-         service.unregister();
-      }
-   }
-
-   /**
-    * Get a service
-    * 
-    * @param bundleState the bundle that requests the service
-    * @param reference the service reference
-    * @return the service
-    */
-   Object getService(AbstractBundleState bundleState, ServiceReference reference)
-   {
-      ControllerContextHandle handle = (ControllerContextHandle)reference;
-      ControllerContext context = handle.getContext();
-      if (isUnregistered(context)) // we're probably not installed anymore
-         return null;
-
-      return bundleState.addContextInUse(context);
-   }
-
-   /**
-    * Is the context undergisted.
-    *
-    * @param context the context
-    * @return true if the context is unregisted, false otherwise
-    */
-   static boolean isUnregistered(ControllerContext context)
-   {
-      Controller controller = context.getController();
-      return controller == null || controller.getStates().isBeforeState(context.getState(), ControllerState.INSTALLED);
-   }
-
-   /**
-    * Unget a service
-    * 
-    * @param bundleState the bundle state
-    * @param reference the service reference
-    * @return true when the service is still in use by the bundle
-    */
-   boolean ungetService(AbstractBundleState bundleState, ServiceReference reference)
-   {
-      if (reference == null)
-         throw new IllegalArgumentException("Null reference");
-
-      ControllerContextHandle serviceReference = (ControllerContextHandle)reference;
-      ControllerContext context = serviceReference.getContext();
-      return ungetContext(bundleState, context);
-   }
-
-   /**
-    * Unget a context
-    * 
-    * @param bundleState the bundle state
-    * @param context the context
-    * @return true when the context is still in use by the bundle
-    */
-   boolean ungetContext(AbstractBundleState bundleState, ControllerContext context)
-   {
-      return bundleState.removeContextInUse(context);
-   }
-
-   /**
     * Get the executor.
     * 
     * @return the executor.
@@ -2071,6 +1581,164 @@
       }
    }
 
+   /**
+    * Put context to deployment mapping.
+    *
+    * @param context the context
+    * @param unit the deployment
+    * @return previous mapping value
+    */
+   DeploymentUnit putContext(ControllerContext context, DeploymentUnit unit)
+   {
+      return registry.putContext(context, unit);
+   }
+
+   /**
+    * Remove context to deployment mapping.
+    *
+    * @param context the context
+    * @param unit the deployment
+    * @return is previous mapping value same as unit param
+    */
+   DeploymentUnit removeContext(ControllerContext context, DeploymentUnit unit)
+   {
+      return registry.removeContext(context, unit);
+   }
+
+   /**
+    * Get registered contexts for bundle.
+    *
+    * @param bundleState the owning bundle
+    * @return registered contexts
+    */
+   Set<ControllerContext> getRegisteredContext(AbstractDeployedBundleState bundleState)
+   {
+      DeploymentUnit unit = bundleState.getDeploymentUnit();
+      return registry.getContexts(unit);
+   }
+
+   /**
+    * Is the context undergisted.
+    *
+    * @param context the context
+    * @return true if the context is unregisted, false otherwise
+    */
+   public static boolean isUnregistered(ControllerContext context)
+   {
+      Controller controller = context.getController();
+      return controller == null || controller.getStates().isBeforeState(context.getState(), ControllerState.INSTALLED);
+   }
+
+   /**
+    * Unregister contexts.
+    *
+    * @param bundleState the stopping bundle
+    */
+   void unregisterContexts(AbstractDeployedBundleState bundleState)
+   {
+      DeploymentUnit unit = bundleState.getDeploymentUnit();
+      Set<ControllerContext> contexts = registry.getContexts(unit);
+      for (ControllerContext context : contexts)
+      {
+         unregisterContext(context);
+      }
+   }
+
+   /**
+    * Get bundle for user tracker.
+    *
+    * @param user the user tracker object
+    * @return bundle state
+    */
+   AbstractBundleState getBundleForUser(Object user)
+   {
+      if (user instanceof AbstractBundleState)
+         return (AbstractBundleState)user;
+      else if (user instanceof ControllerContext)
+         return getBundleForContext((ControllerContext)user);
+      else
+         throw new IllegalArgumentException("Unknown tracker type: " + user);
+   }
+
+   /**
+    * Unget a context
+    * 
+    * @param bundleState the bundle state
+    * @param context the context
+    * @return true when the context is still in use by the bundle
+    */
+   boolean ungetContext(AbstractBundleState bundleState, ControllerContext context)
+   {
+      return bundleState.removeContextInUse(context);
+   }
+
+   /**
+    * Unregister context.
+    *
+    * @param context the context
+    */
+   private static void unregisterContext(ControllerContext context)
+   {
+      if (context instanceof ServiceRegistration)
+      {
+         ServiceRegistration service = (ServiceRegistration)context;
+         service.unregister();
+      }
+   }
+
+   /**
+    * Get bundle for context.
+    *
+    * @param context the context
+    * @return bundle state
+    */
+   public AbstractBundleState getBundleForContext(ControllerContext context)
+   {
+      if (context instanceof OSGiServiceState)
+      {
+         OSGiServiceState service = (OSGiServiceState)context;
+         return service.getBundleState();
+      }
+
+      DeploymentUnit unit = registry.getDeployment(context);
+      if (unit != null)
+      {
+         synchronized (unit)
+         {
+            OSGiBundleState bundleState = unit.getAttachment(OSGiBundleState.class);
+            if (bundleState == null)
+            {
+               OSGiMetaData osgiMetaData = unit.getAttachment(OSGiMetaData.class);
+               if (osgiMetaData == null)
+               {
+                  Manifest manifest = unit.getAttachment(Manifest.class);
+                  // [TODO] we need a mechanism to construct an OSGiMetaData from an easier factory
+                  if (manifest == null)
+                     manifest = new Manifest();
+                  // [TODO] populate some bundle information
+                  Attributes attributes = manifest.getMainAttributes();
+                  attributes.put(new Name(Constants.BUNDLE_SYMBOLICNAME), unit.getName());
+                  osgiMetaData = new AbstractOSGiMetaData(manifest);
+                  unit.addAttachment(OSGiMetaData.class, osgiMetaData);
+               }
+
+               try
+               {
+                  bundleState = (OSGiBundleState)addDeployment(unit);
+                  bundleState.startInternal();
+               }
+               catch (Throwable t)
+               {
+                  throw new RuntimeException("Cannot dynamically add generic bundle: " + unit, t);
+               }
+            }
+            return bundleState;
+         }
+      }
+
+      return systemBundle;
+   }
+
    private URL getLocationURL(String location) throws BundleException
    {
       // Try location as URL

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java	2010-01-20 09:22:33 UTC (rev 99647)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java	2010-01-20 09:27:43 UTC (rev 99648)
@@ -234,7 +234,7 @@
       {
          className = clazzes[0];
          OSGiBundleManager manager = bundleState.getBundleManager();
-         clazz = manager.loadClass(bundleState, className);
+         clazz = manager.loadClassFailsafe(bundleState, className);
       }
 
       ScopeInfo info = OSGiScopeInfo.createScopeInfo(getName(), className, clazz, this);

Added: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/ServiceManagerPluginImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/ServiceManagerPluginImpl.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/ServiceManagerPluginImpl.java	2010-01-20 09:27:43 UTC (rev 99648)
@@ -0,0 +1,395 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.framework.bundle;
+
+//$Id$
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.tracker.ContextTracker;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.kernel.spi.qualifier.QualifierMatchers;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.plugins.loader.memory.MemoryMetaDataLoader;
+import org.jboss.metadata.spi.MutableMetaData;
+import org.jboss.metadata.spi.repository.MutableMetaDataRepository;
+import org.jboss.metadata.spi.retrieval.MetaDataRetrieval;
+import org.jboss.metadata.spi.retrieval.MetaDataRetrievalFactory;
+import org.jboss.metadata.spi.scope.CommonLevels;
+import org.jboss.metadata.spi.scope.ScopeKey;
+import org.jboss.osgi.framework.plugins.FrameworkEventsPlugin;
+import org.jboss.osgi.framework.plugins.ServiceManagerPlugin;
+import org.jboss.osgi.framework.plugins.internal.AbstractPlugin;
+import org.jboss.osgi.framework.util.NoFilter;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * A plugin that manages OSGi services
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 20-Jan-2010
+ */
+public class ServiceManagerPluginImpl extends AbstractPlugin implements ServiceManagerPlugin
+{
+   // Provide logging
+   final Logger log = Logger.getLogger(ServiceManagerPluginImpl.class);
+
+   /** The kernel */
+   private Kernel kernel;
+   /** The previous context tracker */
+   private ContextTracker previousTracker;
+   
+   public ServiceManagerPluginImpl(OSGiBundleManager bundleManager)
+   {
+      super(bundleManager);
+   }
+
+   public void start()
+   {
+      kernel = getBundleManager().getKernel();
+      applyMDRUsage(true);
+   }
+
+   public void stop()
+   {
+      applyMDRUsage(false);
+   }
+
+   public ServiceReference[] getRegisteredServices(AbstractBundleState bundleState)
+   {
+      Set<ControllerContext> contexts = bundleState.getRegisteredContexts();
+      if (contexts.isEmpty())
+         return null;
+
+      Set<ServiceReference> result = new HashSet<ServiceReference>();
+      for (ControllerContext context : contexts)
+      {
+         ServiceReference ref = getServiceReferenceForContext(context);
+         if (ref != null)
+            result.add(ref);
+      }
+      if (result.isEmpty())
+         return null;
+      
+      return result.toArray(new ServiceReference[result.size()]);
+   }
+
+   public ServiceReference[] getServicesInUse(AbstractBundleState bundleState)
+   {
+      Set<ControllerContext> contexts = bundleState.getUsedContexts(bundleState);
+      if (contexts == null || contexts.isEmpty())
+         return null;
+
+      List<ServiceReference> references = new ArrayList<ServiceReference>();
+      for (ControllerContext context : contexts)
+      {
+         ServiceReference ref = getServiceReferenceForContext(context);
+         if (ref != null)
+            references.add(ref);
+      }
+
+      if (references.isEmpty())
+         return null;
+      
+      return references.toArray(new ServiceReference[references.size()]);
+   }
+
+   public ServiceReference[] getAllServiceReferences(AbstractBundleState bundle, String clazz, String filterStr) throws InvalidSyntaxException
+   {
+      Filter filter = NoFilter.INSTANCE;
+      if (filterStr != null)
+         filter = FrameworkUtil.createFilter(filterStr);
+
+      Collection<ServiceReference> services = getServices(bundle, clazz, filter, false);
+      if (services == null || services.isEmpty())
+         return null;
+
+      return services.toArray(new ServiceReference[services.size()]);
+   }
+
+   /**
+    * Get a service
+    * 
+    * @param bundleState the bundle that requests the service
+    * @param reference the service reference
+    * @return the service
+    */
+   public Object getService(AbstractBundleState bundleState, ServiceReference reference)
+   {
+      if (reference == null)
+         throw new IllegalArgumentException("Null reference");
+      
+      ControllerContextHandle handle = (ControllerContextHandle)reference;
+      ControllerContext context = handle.getContext();
+      if (OSGiBundleManager.isUnregistered(context)) // we're probably not installed anymore
+         return null;
+
+      return bundleState.addContextInUse(context);
+   }
+
+   public ServiceReference getServiceReference(AbstractBundleState bundle, String clazz)
+   {
+      if (clazz == null)
+         throw new IllegalArgumentException("Null clazz");
+      
+      Collection<ServiceReference> services = getServices(bundle, clazz, null, true);
+      if (services == null || services.isEmpty())
+         return null;
+
+      return services.iterator().next();
+   }
+
+   public ServiceReference[] getServiceReferences(AbstractBundleState bundle, String clazz, String filterStr) throws InvalidSyntaxException
+   {
+      Filter filter = NoFilter.INSTANCE;
+      if (filterStr != null)
+         filter = FrameworkUtil.createFilter(filterStr);
+
+      Collection<ServiceReference> services = getServices(bundle, clazz, filter, true);
+      if (services == null || services.isEmpty())
+         return null;
+
+      return services.toArray(new ServiceReference[services.size()]);
+   }
+
+   @SuppressWarnings("rawtypes")
+   public OSGiServiceState registerService(AbstractBundleState bundleState, String[] clazzes, Object service, Dictionary properties)
+   {
+      OSGiServiceState result = new OSGiServiceState(bundleState, clazzes, service, properties);
+      result.internalRegister();
+      try
+      {
+         Controller controller = kernel.getController();
+         controller.install(result);
+      }
+      catch (Throwable t)
+      {
+         getBundleManager().fireError(bundleState, "installing service to MC in", t);
+         throw new RuntimeException(t);
+      }
+
+      FrameworkEventsPlugin plugin = getPlugin(FrameworkEventsPlugin.class);
+      plugin.fireServiceEvent(bundleState, ServiceEvent.REGISTERED, result);
+
+      return result;
+   }
+
+   public void unregisterService(OSGiServiceState serviceState)
+   {
+      AbstractBundleState bundleState = serviceState.getBundleState();
+      
+      Controller controller = kernel.getController();
+      controller.uninstall(serviceState.getName());
+
+      serviceState.internalUnregister();
+
+      FrameworkEventsPlugin plugin = getPlugin(FrameworkEventsPlugin.class);
+      plugin.fireServiceEvent(bundleState, ServiceEvent.UNREGISTERING, serviceState);
+   }
+
+   public boolean ungetService(AbstractBundleState bundleState, ServiceReference reference)
+   {
+      if (reference == null)
+         throw new IllegalArgumentException("Null reference");
+
+      ControllerContextHandle serviceReference = (ControllerContextHandle)reference;
+      ControllerContext context = serviceReference.getContext();
+      if (OSGiBundleManager.isUnregistered(context))
+         return false;
+      
+      return getBundleManager().ungetContext(bundleState, context);
+   }
+
+   /**
+    * Apply OSGi's MDR usage:
+    * - add/remove system bundle as default context tracker
+    * - add/remove instance metadata retrieval factory 
+    *
+    * @param register do we register or unregister
+    */
+   private void applyMDRUsage(boolean register)
+   {
+      MutableMetaDataRepository repository = kernel.getMetaDataRepository().getMetaDataRepository();
+      MetaDataRetrieval retrieval = repository.getMetaDataRetrieval(ScopeKey.DEFAULT_SCOPE);
+      if (register && retrieval == null)
+      {
+         retrieval = new MemoryMetaDataLoader(ScopeKey.DEFAULT_SCOPE);
+         repository.addMetaDataRetrieval(retrieval);
+      }
+      if (retrieval != null && retrieval instanceof MutableMetaData)
+      {
+         MutableMetaData mmd = (MutableMetaData)retrieval;
+         if (register)
+         {
+            OSGiSystemState systemBundle = getBundleManager().getSystemBundle();
+            previousTracker = mmd.addMetaData(systemBundle, ContextTracker.class);
+         }
+         else
+         {
+            if (previousTracker == null)
+            {
+               mmd.removeMetaData(ContextTracker.class);
+               if (retrieval.isEmpty())
+                  repository.removeMetaDataRetrieval(retrieval.getScope());
+            }
+            else
+            {
+               mmd.addMetaData(previousTracker, ContextTracker.class);
+            }
+         }
+      }
+
+      // osgi ldap filter parsing and matching
+      FilterParserAndMatcher fpm = FilterParserAndMatcher.INSTANCE;
+      QualifierMatchers matchers = QualifierMatchers.getInstance();
+
+      if (register)
+      {
+         matchers.addParser(fpm);
+         matchers.addMatcher(fpm);
+
+         MetaDataRetrievalFactory mdrFactory = getMetaDataRetrievalFactory();
+         repository.addMetaDataRetrievalFactory(CommonLevels.INSTANCE, mdrFactory);
+      }
+      else
+      {
+         repository.removeMetaDataRetrievalFactory(CommonLevels.INSTANCE);
+
+         matchers.removeParser(fpm.getHandledContent());
+         matchers.removeMatcher(fpm.getHandledType());
+      }
+   }
+
+   private MetaDataRetrievalFactory getMetaDataRetrievalFactory()
+   {
+      MetaDataRetrievalFactory mdrFactory;
+      Controller controller = kernel.getController();
+      InstanceMetaDataRetrievalFactory imdrf = new InstanceMetaDataRetrievalFactory(controller);
+      imdrf.addFactory(new OSGiServiceStateDictionaryFactory());
+      imdrf.addFactory(new KernelDictionaryFactory(kernel.getConfigurator()));
+      // TODO - JMX?
+      mdrFactory = imdrf;
+      return mdrFactory;
+   }
+
+   private Collection<ServiceReference> getServices(AbstractBundleState bundle, String clazz, Filter filter, boolean checkAssignable)
+   {
+      Set<ControllerContext> contexts;
+      KernelController controller = kernel.getController();
+
+      // Don't check assignabilty for the system bundle
+      boolean isSystemBundle = (bundle.getBundleId() == 0);
+      if (isSystemBundle)
+         checkAssignable = false;
+
+      // TODO - a bit slow for system bundle
+      if (clazz != null && isSystemBundle == false)
+      {
+         Class<?> type = getBundleManager().loadClassFailsafe(bundle, clazz);
+         if (type == null)
+            return null; // or check all?
+
+         contexts = controller.getContexts(type, ControllerState.INSTALLED);
+      }
+      else
+      {
+         contexts = controller.getContextsByState(ControllerState.INSTALLED);
+      }
+
+      if (contexts == null || contexts.isEmpty())
+         return null;
+
+      if (filter == null)
+         filter = NoFilter.INSTANCE;
+
+      List<ControllerContext> sorted = new ArrayList<ControllerContext>(contexts);
+      Collections.sort(sorted, ContextComparator.INSTANCE); // Sort by the spec, should bubble up
+      Collection<ServiceReference> result = new ArrayList<ServiceReference>();
+      for (ControllerContext context : sorted)
+      {
+         // re-check?? -- we already only get INSTALLED 
+         if (OSGiBundleManager.isUnregistered(context) == false)
+         {
+            ServiceReference ref = getServiceReferenceForContext(context);
+            if (filter.match(ref) && hasPermission(context))
+            {
+               if (clazz == null || isSystemBundle == false || MDRUtils.matchClass(context, clazz))
+               {
+                  // Check the assignability
+                  if (checkAssignable == false || MDRUtils.isAssignableTo(context, bundle))
+                     result.add(ref);
+               }
+            }
+         }
+      }
+      return result;
+   }
+
+   /**
+    * Get service reference for context.
+    *
+    * @param context the context
+    * @return service reference
+    */
+   private ServiceReference getServiceReferenceForContext(ControllerContext context)
+   {
+      if (context instanceof OSGiServiceState)
+      {
+         OSGiServiceState service = (OSGiServiceState)context;
+         return service.hasPermission() ? service.getReferenceInternal() : null;
+      }
+
+      AbstractBundleState bundleState = getBundleManager().getBundleForContext(context);
+      return new GenericServiceReferenceWrapper(context, bundleState);
+   }
+
+   /**
+    * Do we have a permission to use context.
+    *
+    * @param context the context
+    * @return true if allowed to use context, false otherwise
+    */
+   private boolean hasPermission(ControllerContext context)
+   {
+      // TODO - make thisa generic, w/o casting
+      if (context instanceof OSGiServiceState)
+      {
+         OSGiServiceState serviceState = (OSGiServiceState)context;
+         return serviceState.hasPermission();
+      }
+      return true;
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/ServiceManagerPluginImpl.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins/ServiceManagerPlugin.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins/ServiceManagerPlugin.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins/ServiceManagerPlugin.java	2010-01-20 09:27:43 UTC (rev 99648)
@@ -0,0 +1,143 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.framework.plugins;
+
+import java.util.Dictionary;
+
+import org.jboss.osgi.framework.bundle.AbstractBundleState;
+import org.jboss.osgi.framework.bundle.OSGiServiceState;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * A plugin that manages OSGi services
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 20-Jan-2010
+ */
+public interface ServiceManagerPlugin extends Plugin
+{
+   /**
+    * Returns this bundle's <code>ServiceReference</code> list for all
+    * services it has registered or <code>null</code> if this bundle has no
+    * registered services.
+    * 
+    * @return An array of <code>ServiceReference</code> objects or <code>null</code>.
+    */
+   ServiceReference[] getRegisteredServices(AbstractBundleState bundleState);
+
+   /**
+    * Returns this bundle's <code>ServiceReference</code> list for all
+    * services it is using or returns <code>null</code> if this bundle is not
+    * using any services. A bundle is considered to be using a service if its
+    * use count for that service is greater than zero.
+    * 
+    * 
+    * @return An array of <code>ServiceReference</code> objects or <code>null</code>.
+    * @throws IllegalStateException If this bundle has been uninstalled.
+    */
+   ServiceReference[] getServicesInUse(AbstractBundleState bundleState);
+
+   /**
+    * Returns an array of <code>ServiceReference</code> objects. The returned
+    * array of <code>ServiceReference</code> objects contains services that
+    * were registered under the specified class and match the specified filter
+    * expression.
+    * 
+    * @param clazz The class name with which the service was registered or <code>null</code> for all services.
+    * @param filter The filter expression or <code>null</code> for all services.
+    * @return An array of <code>ServiceReference</code> objects or <code>null</code> 
+    *    if no services are registered which satisfy the  search.
+    */
+   ServiceReference[] getAllServiceReferences(AbstractBundleState bundleState, String clazz, String filter) throws InvalidSyntaxException;
+
+   /**
+    * Returns an array of <code>ServiceReference</code> objects. The returned
+    * array of <code>ServiceReference</code> objects contains services that
+    * were registered under the specified class, match the specified filter
+    * expression, and the packages for the class names under which the services
+    * were registered match the context bundle's packages as defined in
+    * {@link ServiceReference#isAssignableTo(Bundle, String)}.
+    * 
+    * 
+    * @param clazz The class name with which the service was registered or <code>null</code> for all services.
+    * @param filter The filter expression or <code>null</code> for all services.
+    */
+   ServiceReference[] getServiceReferences(AbstractBundleState bundleState, String clazz, String filter) throws InvalidSyntaxException;
+
+   /**
+    * Returns a <code>ServiceReference</code> object for a service that
+    * implements and was registered under the specified class.
+    * 
+    * @param clazz The class name with which the service was registered.
+    * @return A <code>ServiceReference</code> object, or <code>null</code>
+    */
+   ServiceReference getServiceReference(AbstractBundleState bundleState, String clazz);
+
+   /**
+    * Returns the service object referenced by the specified
+    * <code>ServiceReference</code> object.
+    * 
+    * @param reference A reference to the service.
+    * @return A service object for the service associated with <code>reference</code> or <code>null</code>
+    */
+   Object getService(AbstractBundleState bundleState, ServiceReference reference);
+
+   /**
+    * Releases the service object referenced by the specified
+    * <code>ServiceReference</code> object. If the context bundle's use count
+    * for the service is zero, this method returns <code>false</code>.
+    * Otherwise, the context bundle's use count for the service is decremented
+    * by one.
+    * 
+    * @param reference A reference to the service to be released.
+    * @return <code>false</code> if the context bundle's use count for the service is zero or if the service has been unregistered; 
+    *    <code>true</code> otherwise.
+    */
+   boolean ungetService(AbstractBundleState bundleState, ServiceReference reference);
+
+   /**
+    * Registers the specified service object with the specified properties under the specified class names 
+    * into the Framework. A <code>ServiceRegistration</code> object is returned. The <code>ServiceRegistration</code> 
+    * object is for the private use of the bundle registering the service and should not be shared with other
+    * bundles. The registering bundle is defined to be the context bundle.
+    * 
+    * @param clazzes The class names under which the service can be located.
+    * @param service The service object or a <code>ServiceFactory</code> object.
+    * @param properties The properties for this service. 
+    * @return A <code>ServiceRegistration</code> object for use by the bundle registering the service 
+    */
+   @SuppressWarnings("rawtypes")
+   ServiceRegistration registerService(AbstractBundleState bundleState, String[] clazzes, Object service, Dictionary properties);
+
+   /**
+    * Unregisters a service. Remove a <code>ServiceRegistration</code> object
+    * from the Framework service registry. All <code>ServiceReference</code>
+    * objects associated with this <code>ServiceRegistration</code> object
+    * can no longer be used to interact with the service once unregistration is
+    * complete.
+    * 
+    */
+   void unregisterService(OSGiServiceState serviceState);
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins/ServiceManagerPlugin.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins/internal/AbstractPlugin.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins/internal/AbstractPlugin.java	2010-01-20 09:22:33 UTC (rev 99647)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins/internal/AbstractPlugin.java	2010-01-20 09:27:43 UTC (rev 99648)
@@ -34,7 +34,7 @@
  */
 public abstract class AbstractPlugin implements Plugin
 {
-   protected OSGiBundleManager bundleManager;
+   private OSGiBundleManager bundleManager;
 
    public AbstractPlugin(OSGiBundleManager bundleManager)
    {

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins/internal/AbstractServicePlugin.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins/internal/AbstractServicePlugin.java	2010-01-20 09:22:33 UTC (rev 99647)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins/internal/AbstractServicePlugin.java	2010-01-20 09:27:43 UTC (rev 99648)
@@ -42,6 +42,6 @@
 
    public BundleContext getSystemContext()
    {
-      return bundleManager.getSystemContext();
+      return getBundleManager().getSystemContext();
    }
 }
\ No newline at end of file

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins/internal/AutoInstallPluginImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins/internal/AutoInstallPluginImpl.java	2010-01-20 09:22:33 UTC (rev 99647)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins/internal/AutoInstallPluginImpl.java	2010-01-20 09:27:43 UTC (rev 99648)
@@ -78,7 +78,7 @@
       for (URL bundleURL : autoInstall)
       {
          
-         Bundle bundle = bundleManager.installBundle(bundleURL);
+         Bundle bundle = getBundleManager().installBundle(bundleURL);
          autoBundles.put(bundleURL, bundle);
       }
    }

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins/internal/BundleStoragePluginImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins/internal/BundleStoragePluginImpl.java	2010-01-20 09:22:33 UTC (rev 99647)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins/internal/BundleStoragePluginImpl.java	2010-01-20 09:27:43 UTC (rev 99648)
@@ -81,7 +81,7 @@
    {
       if (storageArea == null)
       {
-         String dirName = bundleManager.getProperty(Constants.FRAMEWORK_STORAGE);
+         String dirName = getBundleManager().getProperty(Constants.FRAMEWORK_STORAGE);
          if (dirName == null)
          {
             try

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins/internal/SystemPackagesPluginImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins/internal/SystemPackagesPluginImpl.java	2010-01-20 09:22:33 UTC (rev 99647)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins/internal/SystemPackagesPluginImpl.java	2010-01-20 09:27:43 UTC (rev 99648)
@@ -55,7 +55,7 @@
    
    public void start()
    {
-      String systemPackages = bundleManager.getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES);
+      String systemPackages = getBundleManager().getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES);
       if (systemPackages != null)
       {
          allPackages.addAll(packagesAsList(systemPackages));
@@ -110,10 +110,10 @@
          allPackages.add("org.osgi.service.packageadmin");
          
          String asString = packagesAsString(allPackages);
-         bundleManager.setProperty(Constants.FRAMEWORK_SYSTEMPACKAGES, asString);
+         getBundleManager().setProperty(Constants.FRAMEWORK_SYSTEMPACKAGES, asString);
       }
       
-      String extraPackages = bundleManager.getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA);
+      String extraPackages = getBundleManager().getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA);
       if (extraPackages != null)
       {
          allPackages.addAll(packagesAsList(extraPackages));

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/service/internal/LifecycleInterceptorServiceImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/service/internal/LifecycleInterceptorServiceImpl.java	2010-01-20 09:22:33 UTC (rev 99647)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/service/internal/LifecycleInterceptorServiceImpl.java	2010-01-20 09:27:43 UTC (rev 99648)
@@ -66,7 +66,7 @@
          protected InvocationContext getInvocationContext(Bundle bundle)
          {
             long bundleId = bundle.getBundleId();
-            AbstractDeployedBundleState bundleState = (AbstractDeployedBundleState)bundleManager.getBundleById(bundleId);
+            AbstractDeployedBundleState bundleState = (AbstractDeployedBundleState)getBundleManager().getBundleById(bundleId);
             if (bundle == null)
                throw new IllegalStateException("Cannot obtain bundle for: " + bundle);
 

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/service/internal/PackageAdminImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/service/internal/PackageAdminImpl.java	2010-01-20 09:22:33 UTC (rev 99647)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/service/internal/PackageAdminImpl.java	2010-01-20 09:27:43 UTC (rev 99648)
@@ -133,7 +133,7 @@
 
    public ExportedPackage[] getExportedPackages(Bundle bundle)
    {
-      AbstractBundleState abstractBundleState = bundleManager.getBundleState(bundle);
+      AbstractBundleState abstractBundleState = getBundleManager().getBundleState(bundle);
 
       // [TODO] exported packages for the system bundle 
       if (abstractBundleState instanceof OSGiBundleState == false)
@@ -195,7 +195,7 @@
       List<Bundle> unresolvedBundles = new ArrayList<Bundle>();
       if (bundleArr == null)
       {
-         for (Bundle bundle : bundleManager.getBundles(Bundle.INSTALLED))
+         for (Bundle bundle : getBundleManager().getBundles(Bundle.INSTALLED))
          {
             AbstractBundleState bundleState = AbstractBundleState.assertBundleState(bundle);
             if (bundleState.isFragment() == false)
@@ -217,7 +217,7 @@
       List<OSGiBundleState> resolvableBundles = new ArrayList<OSGiBundleState>();
 
       // Check if the external resolver plugin is available
-      Resolver bundleResolver = bundleManager.getOptionalPlugin(ResolverPlugin.class);
+      Resolver bundleResolver = getBundleManager().getOptionalPlugin(ResolverPlugin.class);
       if (bundleResolver != null)
       {
          // Resolve the bundles through the resolver
@@ -245,7 +245,7 @@
             OSGiBundleState bundleState = it.next();
             try
             {
-               boolean bundleResolved = bundleManager.resolveBundle(bundleState, false);
+               boolean bundleResolved = getBundleManager().resolveBundle(bundleState, false);
                if (bundleResolved)
                {
                   it.remove();
@@ -267,7 +267,7 @@
          {
             try
             {
-               bundleManager.resolveBundle(bundleState, true);
+               getBundleManager().resolveBundle(bundleState, true);
             }
             catch (Exception ex)
             {

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/fragments/FragmentTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/fragments/FragmentTestCase.java	2010-01-20 09:22:33 UTC (rev 99647)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/fragments/FragmentTestCase.java	2010-01-20 09:27:43 UTC (rev 99648)
@@ -36,7 +36,6 @@
 import org.jboss.test.osgi.fragments.subA.SubBeanA;
 import org.junit.After;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bootstrap/jboss-osgi-bootstrap.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bootstrap/jboss-osgi-bootstrap.xml	2010-01-20 09:22:33 UTC (rev 99647)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bootstrap/jboss-osgi-bootstrap.xml	2010-01-20 09:27:43 UTC (rev 99648)
@@ -50,6 +50,9 @@
   <bean name="OSGiFrameworkEventsPlugin" class="org.jboss.osgi.framework.plugins.internal.FrameworkEventsPluginImpl">
     <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
   </bean>
+  <bean name="OSGiServiceManager" class="org.jboss.osgi.framework.bundle.ServiceManagerPluginImpl">
+    <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
+  </bean>
   <bean name="OSGiStoragePlugin" class="org.jboss.osgi.framework.plugins.internal.BundleStoragePluginImpl">
     <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
   </bean>

Modified: projects/jboss-osgi/trunk/distribution/installer/src/main/resources/jbossas/jboss-beans-jbossmc.xml
===================================================================
--- projects/jboss-osgi/trunk/distribution/installer/src/main/resources/jbossas/jboss-beans-jbossmc.xml	2010-01-20 09:22:33 UTC (rev 99647)
+++ projects/jboss-osgi/trunk/distribution/installer/src/main/resources/jbossas/jboss-beans-jbossmc.xml	2010-01-20 09:27:43 UTC (rev 99648)
@@ -103,12 +103,15 @@
   <bean name="OSGiFrameworkEventsPlugin" class="org.jboss.osgi.framework.plugins.internal.FrameworkEventsPluginImpl">
     <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
   </bean>
-  <bean name="OSGiSystemPackages" class="org.jboss.osgi.framework.plugins.internal.SystemPackagesPluginImpl">
+  <bean name="OSGiServiceManager" class="org.jboss.osgi.framework.bundle.ServiceManagerPluginImpl">
     <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
   </bean>
   <bean name="OSGiStoragePlugin" class="org.jboss.osgi.framework.plugins.internal.BundleStoragePluginImpl">
     <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
   </bean>
+  <bean name="OSGiSystemPackages" class="org.jboss.osgi.framework.plugins.internal.SystemPackagesPluginImpl">
+    <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
+  </bean>
 
   <!-- 
   ********************************

Modified: projects/jboss-osgi/trunk/distribution/installer/src/main/resources/runtime/server/conf/jboss-osgi-bootstrap.xml
===================================================================
--- projects/jboss-osgi/trunk/distribution/installer/src/main/resources/runtime/server/conf/jboss-osgi-bootstrap.xml	2010-01-20 09:22:33 UTC (rev 99647)
+++ projects/jboss-osgi/trunk/distribution/installer/src/main/resources/runtime/server/conf/jboss-osgi-bootstrap.xml	2010-01-20 09:27:43 UTC (rev 99648)
@@ -94,6 +94,9 @@
   <bean name="OSGiFrameworkEventsPlugin" class="org.jboss.osgi.framework.plugins.internal.FrameworkEventsPluginImpl">
     <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
   </bean>
+  <bean name="OSGiServiceManager" class="org.jboss.osgi.framework.bundle.ServiceManagerPluginImpl">
+    <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
+  </bean>
   <bean name="OSGiStoragePlugin" class="org.jboss.osgi.framework.plugins.internal.BundleStoragePluginImpl">
     <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
   </bean>

Modified: projects/jboss-osgi/trunk/reactor/blueprint/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
===================================================================
--- projects/jboss-osgi/trunk/reactor/blueprint/src/test/resources/META-INF/jboss-osgi-bootstrap.xml	2010-01-20 09:22:33 UTC (rev 99647)
+++ projects/jboss-osgi/trunk/reactor/blueprint/src/test/resources/META-INF/jboss-osgi-bootstrap.xml	2010-01-20 09:27:43 UTC (rev 99648)
@@ -77,6 +77,9 @@
   <bean name="OSGiFrameworkEventsPlugin" class="org.jboss.osgi.framework.plugins.internal.FrameworkEventsPluginImpl">
     <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
   </bean>
+  <bean name="OSGiServiceManager" class="org.jboss.osgi.framework.bundle.ServiceManagerPluginImpl">
+    <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
+  </bean>
   <bean name="OSGiStoragePlugin" class="org.jboss.osgi.framework.plugins.internal.BundleStoragePluginImpl">
     <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
   </bean>

Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml	2010-01-20 09:22:33 UTC (rev 99647)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml	2010-01-20 09:27:43 UTC (rev 99648)
@@ -77,6 +77,9 @@
   <bean name="OSGiFrameworkEventsPlugin" class="org.jboss.osgi.framework.plugins.internal.FrameworkEventsPluginImpl">
     <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
   </bean>
+  <bean name="OSGiServiceManager" class="org.jboss.osgi.framework.bundle.ServiceManagerPluginImpl">
+    <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
+  </bean>
   <bean name="OSGiStoragePlugin" class="org.jboss.osgi.framework.plugins.internal.BundleStoragePluginImpl">
     <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
   </bean>

Modified: projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/META-INF/jboss-osgi-bootstrap.xml	2010-01-20 09:22:33 UTC (rev 99647)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/META-INF/jboss-osgi-bootstrap.xml	2010-01-20 09:27:43 UTC (rev 99648)
@@ -76,6 +76,9 @@
   <bean name="OSGiFrameworkEventsPlugin" class="org.jboss.osgi.framework.plugins.internal.FrameworkEventsPluginImpl">
     <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
   </bean>
+  <bean name="OSGiServiceManager" class="org.jboss.osgi.framework.bundle.ServiceManagerPluginImpl">
+    <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
+  </bean>
   <bean name="OSGiStoragePlugin" class="org.jboss.osgi.framework.plugins.internal.BundleStoragePluginImpl">
     <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
   </bean>



More information about the jboss-osgi-commits mailing list