[jboss-osgi-commits] JBoss-OSGI SVN: r95736 - in projects/jboss-osgi: trunk/distribution/installer/src/main/resources/installer and 6 other directories.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Thu Oct 29 05:20:51 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-10-29 05:20:49 -0400 (Thu, 29 Oct 2009)
New Revision: 95736

Added:
   projects/jboss-osgi/trunk/reactor/jmx/src/main/java/org/jboss/osgi/jmx/internal/ManagedFrameworkImpl.java
Modified:
   projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedBundle.java
   projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedFramework.java
   projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedFrameworkMBean.java
   projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedServiceReference.java
   projects/jboss-osgi/trunk/distribution/installer/src/main/resources/installer/install-definition.xml
   projects/jboss-osgi/trunk/distribution/installer/src/main/resources/jbossas/jboss-beans-equinox.xml
   projects/jboss-osgi/trunk/distribution/installer/src/main/resources/jbossas/jboss-beans-felix.xml
   projects/jboss-osgi/trunk/distribution/installer/src/main/resources/jbossas/jboss-beans-jbossmc.xml
   projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/SystemDeployerService.java
   projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/WebXMLVerifierInterceptor.java
   projects/jboss-osgi/trunk/reactor/jmx/pom.xml
   projects/jboss-osgi/trunk/reactor/jmx/src/main/java/org/jboss/osgi/jmx/internal/JMXConnectorService.java
   projects/jboss-osgi/trunk/reactor/jmx/src/main/java/org/jboss/osgi/jmx/internal/JMXServiceActivator.java
   projects/jboss-osgi/trunk/reactor/jmx/src/main/java/org/jboss/osgi/jmx/internal/MBeanServerService.java
   projects/jboss-osgi/trunk/reactor/jmx/src/main/java/org/jboss/osgi/jmx/internal/ManagedBundleServiceImpl.java
   projects/jboss-osgi/trunk/reactor/testing/src/main/java/org/jboss/osgi/testing/internal/RemotePackageAdmin.java
Log:
[JBOSGI-125] Add ManagedFramework service

Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedBundle.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedBundle.java	2009-10-29 09:14:39 UTC (rev 95735)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedBundle.java	2009-10-29 09:20:49 UTC (rev 95736)
@@ -23,13 +23,14 @@
 
 //$Id$
 
+import static org.jboss.osgi.spi.OSGiConstants.DOMAIN_NAME;
+
 import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.Hashtable;
 
 import javax.management.ObjectName;
 
-import org.jboss.osgi.spi.OSGiConstants;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleException;
 import org.osgi.framework.Version;
@@ -42,19 +43,33 @@
  */
 public class ManagedBundle implements ManagedBundleMBean
 {
+   public static final String PROPERTY_ID = "id";
+   public static final String PROPERTY_SYMBOLIC_NAME = "sname";
+   public static final String PROPERTY_VERSION = "version";
+
    private Bundle bundle;
    private ObjectName oname;
 
    public ManagedBundle(Bundle bundle)
    {
       this.bundle = bundle;
-      
+      this.oname = getObjectName(bundle);
+   }
+
+   public static ObjectName getObjectName(Bundle bundle)
+   {
       long id = bundle.getBundleId();
-      String name = bundle.getSymbolicName();
+      String symbolicName = bundle.getSymbolicName();
       Version version = bundle.getVersion();
-      this.oname = ObjectNameFactory.create(OSGiConstants.DOMAIN_NAME + ":id=" + id + ",bundle=" + name + ",version=" + version);
+      return getObjectName(id, symbolicName, version);
    }
 
+   public static ObjectName getObjectName(long id, String sname, Version version)
+   {
+      String oname = DOMAIN_NAME + ":" + PROPERTY_ID + "=" + id + "," + PROPERTY_SYMBOLIC_NAME + "=" + sname + "," + PROPERTY_VERSION + "=" + version;
+      return ObjectNameFactory.create(oname);
+   }
+
    public ObjectName getObjectName()
    {
       return oname;
@@ -86,7 +101,7 @@
       Hashtable<String, String> retHeaders = new Hashtable<String, String>();
       Dictionary bundleHeaders = bundle.getHeaders();
       Enumeration keys = bundleHeaders.keys();
-      while(keys.hasMoreElements())
+      while (keys.hasMoreElements())
       {
          String key = (String)keys.nextElement();
          String value = (String)bundleHeaders.get(key);
@@ -94,7 +109,7 @@
       }
       return retHeaders;
    }
-   
+
    public void start() throws BundleException
    {
       bundle.start();

Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedFramework.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedFramework.java	2009-10-29 09:14:39 UTC (rev 95735)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedFramework.java	2009-10-29 09:20:49 UTC (rev 95736)
@@ -23,217 +23,49 @@
 
 //$Id$
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
 import java.util.Set;
 
-import javax.management.JMException;
-import javax.management.MBeanServer;
 import javax.management.ObjectName;
-import javax.management.QueryExp;
 
-import org.jboss.osgi.spi.OSGiConstants;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.packageadmin.PackageAdmin;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 /**
  * The managed view of an OSGi Framework
  * 
  * @author thomas.diesler at jboss.com
  * @since 04-Mar-2009
  */
-public class ManagedFramework implements ManagedFrameworkMBean
+public interface ManagedFramework
 {
-   // Provide logging
-   final Logger log = LoggerFactory.getLogger(ManagedFramework.class);
-
-   private MBeanServer mbeanServer;
-   private BundleContext bundleContext;
-
-   public ManagedFramework(BundleContext bundleContext, MBeanServer mbeanServer)
-   {
-      if (bundleContext == null)
-         throw new IllegalArgumentException("Null BundleContext");
-      this.bundleContext = bundleContext;
-      
-      if (mbeanServer == null)
-         throw new IllegalArgumentException("Null MBeanServer");
-      this.mbeanServer = mbeanServer;
-      
-      if (bundleContext.getBundle().getBundleId() != 0)
-         throw new IllegalArgumentException ("Not the system bundle context: " + bundleContext);
-   }
-
-   public BundleContext getBundleContext()
-   {
-      return bundleContext;
-   }
-
-   @SuppressWarnings("unchecked")
-   public ObjectName getBundle(String symbolicName, String version)
-   {
-      ObjectName oname = null;
-
-      ObjectName pattern = ObjectNameFactory.create(OSGiConstants.DOMAIN_NAME + ":bundle=" + symbolicName + ",*");
-      Set<ObjectName> names = mbeanServer.queryNames(pattern, null);
-
-      if (names.size() > 0)
-      {
-         // [TODO] Support bundle version 
-         if (names.size() > 1)
-            throw new IllegalArgumentException("Multiple bundles found: " + names);
-
-         oname = names.iterator().next();
-      }
-
-      return oname;
-   }
-
-   @SuppressWarnings("unchecked")
-   public ObjectName getBundle(long bundleId)
-   {
-      ObjectName oname = null;
-
-      ObjectName pattern = ObjectNameFactory.create(OSGiConstants.DOMAIN_NAME + ":id=" + bundleId + ",*");
-      Set<ObjectName> names = mbeanServer.queryNames(pattern, null);
-
-      if (names.size() > 0)
-         oname = names.iterator().next();
-
-      return oname;
-   }
-
-   @SuppressWarnings("unchecked")
-   public Set<ObjectName> getBundles()
-   {
-      // [JBAS-6571] JMX filtering does not work with wildcards
-      // ObjectName pattern = ObjectNameFactory.create(Constants.DOMAIN_NAME + ":bundle=*,*");
-      // Set<ObjectName> names = mbeanServer.queryNames(pattern, null);
-
-      ObjectName pattern = ObjectNameFactory.create(OSGiConstants.DOMAIN_NAME + ":*");
-      Set<ObjectName> names = mbeanServer.queryNames(pattern, new IsBundleQueryExp());
-      return names;
-   }
-
-   public ManagedServiceReference getServiceReference(String clazz)
-   {
-      ServiceReference sref = getBundleContext().getServiceReference(clazz);
-      if (sref == null)
-         return null;
-
-      Map<String, Object> props = new HashMap<String, Object>();
-      for (String key : sref.getPropertyKeys())
-      {
-         props.put(key, sref.getProperty(key));
-      }
-      
-      return new ManagedServiceReference(props);
-   }
-
-   public ManagedServiceReference[] getServiceReferences(String clazz, String filter)
-   {
-      List<ManagedServiceReference> foundRefs = new ArrayList<ManagedServiceReference>();
-      
-      ServiceReference[] srefs;
-      try
-      {
-         srefs = getBundleContext().getServiceReferences(clazz, filter);
-      }
-      catch (InvalidSyntaxException e)
-      {
-         throw new IllegalArgumentException("Invalid filter syntax: " + filter);
-      }
-      
-      if (srefs != null)
-      {
-         for (ServiceReference sref : srefs)
-         {
-            Map<String, Object> props = new HashMap<String, Object>();
-            for (String key : sref.getPropertyKeys())
-               props.put(key, sref.getProperty(key));
-
-            foundRefs.add(new ManagedServiceReference(props));
-         }
-      }
-
-      ManagedServiceReference[] manrefs = null;
-      if (foundRefs.size() > 0)
-         manrefs = foundRefs.toArray(new ManagedServiceReference[foundRefs.size()]);
-
-      return manrefs;
-   }
-
-   public void refreshPackages(String[] symbolicNames)
-   {
-      ServiceReference sref = getBundleContext().getServiceReference(PackageAdmin.class.getName());
-      if (sref != null)
-      {
-         PackageAdmin service = (PackageAdmin)getBundleContext().getService(sref);
-
-         Bundle[] bundles = null;
-         if (symbolicNames != null)
-         {
-            List<String> nameList = Arrays.asList(symbolicNames);
-            Set<Bundle> bundleSet = new HashSet<Bundle>();
-            for (Bundle bundle : getBundleContext().getBundles())
-            {
-               if (nameList.contains(bundle.getSymbolicName()))
-                  bundleSet.add(bundle);
-            }
-            bundles = new Bundle[bundleSet.size()];
-            bundleSet.toArray(bundles);
-         }
-         service.refreshPackages(bundles);
-      }
-   }
-
-   public void start()
-   {
-      try
-      {
-         if (mbeanServer != null)
-            mbeanServer.registerMBean(this, ManagedFrameworkMBean.MBEAN_MANAGED_FRAMEWORK);
-      }
-      catch (JMException ex)
-      {
-         log.warn("Cannot register: " + ManagedFrameworkMBean.MBEAN_MANAGED_FRAMEWORK);
-      }
-   }
-
-   public void stop()
-   {
-      try
-      {
-         if (mbeanServer != null && mbeanServer.isRegistered(MBEAN_MANAGED_FRAMEWORK))
-            mbeanServer.unregisterMBean(ManagedFrameworkMBean.MBEAN_MANAGED_FRAMEWORK);
-      }
-      catch (JMException ex)
-      {
-         log.warn("Cannot register: " + ManagedFrameworkMBean.MBEAN_MANAGED_FRAMEWORK);
-      }
-   }
-
-   // Accept names like "jboss.osgi:bundle=*"
-   static class IsBundleQueryExp implements QueryExp
-   {
-      private static final long serialVersionUID = 1L;
-
-      public boolean apply(ObjectName name)
-      {
-         return name.getKeyProperty("bundle") != null;
-      }
-
-      public void setMBeanServer(MBeanServer server)
-      {
-      }
-   }
+   /**
+    * Get the list of all installed bundles
+    */
+   Set<ObjectName> getBundles();
+   
+   /**
+    * Get the installed bundle 
+    */
+   ObjectName getBundle(String symbolicName, String version);
+   
+   /**
+    * Get the installed bundle 
+    */
+   ObjectName getBundle(long bundleId);
+   
+   /**
+    * Returns a ServiceReference object for a service that implements and was registered 
+    * under the specified class.
+    */
+   ManagedServiceReference getServiceReference(String clazz);
+   
+   /**
+    * Returns an array of ManagedServiceReference objects. 
+    * The returned array of ManagedServiceReference objects contains services 
+    * that were registered under the specified class, match the specified filter criteria, 
+    * and the packages for the class names under which the services were registered.
+    */
+   ManagedServiceReference[] getServiceReferences(String clazz, String filter);
+   
+   /**
+    * Refresh packages through the PackageAdmin service
+    */
+   void refreshPackages(ObjectName[] bundles);
 }
\ No newline at end of file

Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedFrameworkMBean.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedFrameworkMBean.java	2009-10-29 09:14:39 UTC (rev 95735)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedFrameworkMBean.java	2009-10-29 09:20:49 UTC (rev 95736)
@@ -23,8 +23,6 @@
 
 //$Id$
 
-import java.util.Set;
-
 import javax.management.ObjectName;
 
 /**
@@ -33,42 +31,9 @@
  * @author thomas.diesler at jboss.com
  * @since 04-Mar-2009
  */
-public interface ManagedFrameworkMBean
+public interface ManagedFrameworkMBean extends ManagedFramework
 {
    /** The default object name: jboss.osgi:service=ManagedFramework */
    ObjectName MBEAN_MANAGED_FRAMEWORK = ObjectNameFactory.create("jboss.osgi:service=ManagedFramework");
 
-   /**
-    * Get the list of all installed bundles
-    */
-   Set<ObjectName> getBundles();
-   
-   /**
-    * Get the installed bundle 
-    */
-   ObjectName getBundle(String symbolicName, String version);
-   
-   /**
-    * Get the installed bundle 
-    */
-   ObjectName getBundle(long bundleId);
-   
-   /**
-    * Returns a ServiceReference object for a service that implements and was registered 
-    * under the specified class.
-    */
-   ManagedServiceReference getServiceReference(String clazz);
-   
-   /**
-    * Returns an array of ManagedServiceReference objects. 
-    * The returned array of ManagedServiceReference objects contains services 
-    * that were registered under the specified class, match the specified filter criteria, 
-    * and the packages for the class names under which the services were registered.
-    */
-   ManagedServiceReference[] getServiceReferences(String clazz, String filter);
-   
-   /**
-    * Refresh packages through the PackageAdmin service
-    */
-   void refreshPackages(String[] symbolicNames);
 }
\ No newline at end of file

Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedServiceReference.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedServiceReference.java	2009-10-29 09:14:39 UTC (rev 95735)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedServiceReference.java	2009-10-29 09:20:49 UTC (rev 95736)
@@ -39,7 +39,7 @@
    
    private Map<String, Object> props;
    
-   ManagedServiceReference(Map<String, Object> props)
+   public ManagedServiceReference(Map<String, Object> props)
    {
       this.props = props;
    }

Modified: projects/jboss-osgi/trunk/distribution/installer/src/main/resources/installer/install-definition.xml
===================================================================
--- projects/jboss-osgi/trunk/distribution/installer/src/main/resources/installer/install-definition.xml	2009-10-29 09:14:39 UTC (rev 95735)
+++ projects/jboss-osgi/trunk/distribution/installer/src/main/resources/installer/install-definition.xml	2009-10-29 09:20:49 UTC (rev 95736)
@@ -145,6 +145,7 @@
         <include name="jboss-osgi-jaxb-sources.jar" />
         <include name="jboss-osgi-jmx-sources.jar" />
         <include name="jboss-osgi-jndi-sources.jar" />
+        <include name="jboss-osgi-jta-sources.jar" />
         <include name="jboss-osgi-microcontainer-sources.jar" />
         <include name="jboss-osgi-runtime-equinox-sources.jar" />
         <include name="jboss-osgi-runtime-felix-sources.jar" />
@@ -238,6 +239,7 @@
         <include name="jboss-osgi-apache-xerces.jar" />
         <include name="jboss-osgi-blueprint.jar" />
         <include name="jboss-osgi-jaxb.jar" />
+        <include name="jboss-osgi-jta.jar" />
         <include name="jboss-osgi-xml-binding.jar" />
       </fileset>
 

Modified: projects/jboss-osgi/trunk/distribution/installer/src/main/resources/jbossas/jboss-beans-equinox.xml
===================================================================
--- projects/jboss-osgi/trunk/distribution/installer/src/main/resources/jbossas/jboss-beans-equinox.xml	2009-10-29 09:14:39 UTC (rev 95735)
+++ projects/jboss-osgi/trunk/distribution/installer/src/main/resources/jbossas/jboss-beans-equinox.xml	2009-10-29 09:20:49 UTC (rev 95736)
@@ -77,7 +77,7 @@
   </bean>
 
   <!-- The Framework Management -->
-  <bean name="jboss.osgi:service=ManagedFramework" class="org.jboss.osgi.spi.management.ManagedFramework">
+  <bean name="jboss.osgi:service=ManagedFramework" class="org.jboss.osgi.spi.management.ManagedFrameworkImpl">
     <constructor>
       <parameter><inject bean="jboss.osgi:service=Framework" property="bundleContext"/></parameter>
       <parameter><inject bean="JMXKernel" property="mbeanServer"/></parameter>

Modified: projects/jboss-osgi/trunk/distribution/installer/src/main/resources/jbossas/jboss-beans-felix.xml
===================================================================
--- projects/jboss-osgi/trunk/distribution/installer/src/main/resources/jbossas/jboss-beans-felix.xml	2009-10-29 09:14:39 UTC (rev 95735)
+++ projects/jboss-osgi/trunk/distribution/installer/src/main/resources/jbossas/jboss-beans-felix.xml	2009-10-29 09:20:49 UTC (rev 95736)
@@ -100,7 +100,7 @@
   </bean>
 
   <!-- The Framework Management -->
-  <bean name="jboss.osgi:service=ManagedFramework" class="org.jboss.osgi.spi.management.ManagedFramework">
+  <bean name="jboss.osgi:service=ManagedFramework" class="org.jboss.osgi.spi.management.ManagedFrameworkImpl">
     <constructor>
       <parameter><inject bean="jboss.osgi:service=Framework" property="bundleContext"/></parameter>
       <parameter><inject bean="JMXKernel" property="mbeanServer"/></parameter>

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	2009-10-29 09:14:39 UTC (rev 95735)
+++ projects/jboss-osgi/trunk/distribution/installer/src/main/resources/jbossas/jboss-beans-jbossmc.xml	2009-10-29 09:20:49 UTC (rev 95736)
@@ -200,7 +200,7 @@
     <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
   </bean>
 
-  <bean name="OSGiManagedFramework" class="org.jboss.osgi.spi.management.ManagedFramework">
+  <bean name="OSGiManagedFramework" class="org.jboss.osgi.spi.management.ManagedFrameworkImpl">
     <constructor>
       <parameter><inject bean="OSGiBundleManager" property="bundleContext"/></parameter>
       <parameter><inject bean="JMXKernel" property="mbeanServer"/></parameter>

Modified: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/SystemDeployerService.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/SystemDeployerService.java	2009-10-29 09:14:39 UTC (rev 95735)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/SystemDeployerService.java	2009-10-29 09:20:49 UTC (rev 95736)
@@ -34,11 +34,10 @@
 import javax.management.MBeanServer;
 import javax.management.StandardMBean;
 
-import org.jboss.osgi.deployment.deployer.DeployerService;
 import org.jboss.osgi.deployment.deployer.AbstractDeployerService;
+import org.jboss.osgi.deployment.deployer.DeployerService;
 import org.jboss.osgi.deployment.deployer.Deployment;
 import org.jboss.osgi.deployment.deployer.DeploymentRegistryService;
-import org.jboss.osgi.spi.management.ManagedBundleService;
 import org.jboss.osgi.spi.util.ExportedPackageHelper;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -107,8 +106,6 @@
             String location = dep.getLocation().toExternalForm();
             Bundle bundle = context.installBundle(location);
 
-            registerManagedBundle(bundle);
-            
             bundleMap.put(dep, bundle);
             if (dep.isAutoStart())
                resolvableBundles.add(bundle);
@@ -183,7 +180,6 @@
             
             registry.unregisterDeployment(dep);
 
-            unregisterManagedBundle(bundle);
             bundle.uninstall();
          }
          else
@@ -234,34 +230,6 @@
       return bundle;
    }
 
-   private void registerManagedBundle(Bundle bundle)
-   {
-      ServiceReference sref = context.getServiceReference(ManagedBundleService.class.getName());
-      if (sref != null)
-      {
-         ManagedBundleService service = (ManagedBundleService)context.getService(sref);
-         service.register(bundle);
-      }
-      else
-      {
-         log.debug( "No ManagedBundleService. Cannot register managed bundle: " + bundle);
-      }
-   }
-
-   private void unregisterManagedBundle(Bundle bundle)
-   {
-      ServiceReference sref = context.getServiceReference(ManagedBundleService.class.getName());
-      if (sref != null)
-      {
-         ManagedBundleService service = (ManagedBundleService)context.getService(sref);
-         service.unregister(bundle);
-      }
-      else
-      {
-         log.debug( "No ManagedBundleService. Cannot unregister managed bundle: " + bundle);
-      }
-   }
-
    private DeploymentRegistryService getDeploymentRegistry()
    {
       ServiceReference sref = context.getServiceReference(DeploymentRegistryService.class.getName());

Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/WebXMLVerifierInterceptor.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/WebXMLVerifierInterceptor.java	2009-10-29 09:14:39 UTC (rev 95735)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/WebXMLVerifierInterceptor.java	2009-10-29 09:20:49 UTC (rev 95736)
@@ -48,13 +48,15 @@
             VirtualFile root = context.getRoot();
             VirtualFile webXML = root.getChild("/WEB-INF/web.xml");
             if (root.getName().endsWith(".war") && webXML == null)
-            {
                throw new LifecycleInterceptorException("Cannot obtain web.xml from: " + root.toURL());
-            }
          }
+         catch (RuntimeException rte)
+         {
+            throw rte;
+         }
          catch (Exception ex)
          {
-            throw new LifecycleInterceptorException("Cannot parse web.xml", ex);
+            throw new LifecycleInterceptorException("Cannot check for web.xml", ex);
          }
       }
    }

Modified: projects/jboss-osgi/trunk/reactor/jmx/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/reactor/jmx/pom.xml	2009-10-29 09:14:39 UTC (rev 95735)
+++ projects/jboss-osgi/trunk/reactor/jmx/pom.xml	2009-10-29 09:20:49 UTC (rev 95736)
@@ -86,8 +86,12 @@
               <!-- osgi --> 
               org.osgi.framework;version=1.4,
               org.osgi.service.log,
+              org.osgi.service.packageadmin,
               org.osgi.util.tracker,
               
+              <!-- logging -->
+              org.slf4j,
+              
               <!-- FIXME optional -->
               org.jboss.osgi.jndi, 
               org.jboss.net.sockets,

Modified: projects/jboss-osgi/trunk/reactor/jmx/src/main/java/org/jboss/osgi/jmx/internal/JMXConnectorService.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/jmx/src/main/java/org/jboss/osgi/jmx/internal/JMXConnectorService.java	2009-10-29 09:14:39 UTC (rev 95735)
+++ projects/jboss-osgi/trunk/reactor/jmx/src/main/java/org/jboss/osgi/jmx/internal/JMXConnectorService.java	2009-10-29 09:20:49 UTC (rev 95736)
@@ -37,9 +37,9 @@
 import javax.management.remote.JMXServiceURL;
 
 import org.jboss.net.sockets.DefaultSocketFactory;
-import org.jboss.osgi.common.log.LogServiceTracker;
 import org.osgi.framework.BundleContext;
-import org.osgi.service.log.LogService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * A Service Activator that registers an MBeanServer
@@ -49,7 +49,9 @@
  */
 public class JMXConnectorService
 {
-   private LogService log;
+   // Provide logging
+   private Logger log = LoggerFactory.getLogger(JMXConnectorService.class);
+   
    private JMXServiceURL serviceURL;
    private JMXConnectorServer jmxConnectorServer;
    private boolean shutdownRegistry;
@@ -57,18 +59,16 @@
 
    public JMXConnectorService(BundleContext context, MBeanServer mbeanServer, String host, int rmiPort) throws IOException
    {
-      log = new LogServiceTracker(context);
-
       // check to see if registry already created
       rmiRegistry = LocateRegistry.getRegistry(host, rmiPort);
       try
       {
          rmiRegistry.list();
-         log.log(LogService.LOG_DEBUG, "RMI registry running at host=" + host + ",port=" + rmiPort);
+         log.debug("RMI registry running at host=" + host + ",port=" + rmiPort);
       }
       catch (RemoteException e)
       {
-         log.log(LogService.LOG_DEBUG, "No RMI registry running at host=" + host + ",port=" + rmiPort + ".  Will create one.");
+         log.debug("No RMI registry running at host=" + host + ",port=" + rmiPort + ".  Will create one.");
          rmiRegistry = LocateRegistry.createRegistry(rmiPort, null, new DefaultSocketFactory(InetAddress.getByName(host)));
          shutdownRegistry = true;
       }
@@ -77,7 +77,7 @@
       serviceURL = getServiceURL(host, rmiPort);
       jmxConnectorServer = JMXConnectorServerFactory.newJMXConnectorServer(serviceURL, null, mbeanServer);
 
-      log.log(LogService.LOG_DEBUG, "JMXConnectorServer created: " + serviceURL);
+      log.debug("JMXConnectorServer created: " + serviceURL);
    }
 
    static JMXServiceURL getServiceURL(String host, int rmiPort)
@@ -102,11 +102,11 @@
 
          jmxConnectorServer.start();
 
-         log.log(LogService.LOG_DEBUG, "JMXConnectorServer started: " + serviceURL);
+         log.debug("JMXConnectorServer started: " + serviceURL);
       }
       catch (IOException ex)
       {
-         log.log(LogService.LOG_ERROR, "Cannot start JMXConnectorServer", ex);
+         log.error("Cannot start JMXConnectorServer", ex);
       }
       finally
       {
@@ -126,15 +126,15 @@
          // Shutdown the registry if this service created it
          if (shutdownRegistry == true)
          {
-            log.log(LogService.LOG_DEBUG, "Shutdown RMI registry");
+            log.debug("Shutdown RMI registry");
             UnicastRemoteObject.unexportObject(rmiRegistry, true);
          }
 
-         log.log(LogService.LOG_DEBUG, "JMXConnectorServer stopped");
+         log.debug("JMXConnectorServer stopped");
       }
       catch (IOException ex)
       {
-         log.log(LogService.LOG_WARNING, "Cannot stop JMXConnectorServer", ex);
+         log.warn("Cannot stop JMXConnectorServer", ex);
       }
       finally
       {

Modified: projects/jboss-osgi/trunk/reactor/jmx/src/main/java/org/jboss/osgi/jmx/internal/JMXServiceActivator.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/jmx/src/main/java/org/jboss/osgi/jmx/internal/JMXServiceActivator.java	2009-10-29 09:14:39 UTC (rev 95735)
+++ projects/jboss-osgi/trunk/reactor/jmx/src/main/java/org/jboss/osgi/jmx/internal/JMXServiceActivator.java	2009-10-29 09:20:49 UTC (rev 95736)
@@ -37,15 +37,14 @@
 import javax.naming.Reference;
 import javax.naming.StringRefAddr;
 
-import org.jboss.osgi.common.log.LogServiceTracker;
 import org.jboss.osgi.spi.management.ManagedBundleService;
 import org.jboss.osgi.spi.management.ManagedFramework;
-import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
-import org.osgi.service.log.LogService;
 import org.osgi.util.tracker.ServiceTracker;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * A BundleActivator for the MBeanServer related services
@@ -55,20 +54,18 @@
  */
 public class JMXServiceActivator implements BundleActivator
 {
+   // Provide logging
+   private Logger log = LoggerFactory.getLogger(JMXServiceActivator.class);
+   
    private JMXConnectorService jmxConnector;
    private String jmxHost;
    private String jmxRmiPort;
    private String rmiAdaptorPath;
    private MBeanServer mbeanServer;
-   private ManagedFramework managedFramework;
-   private ManagedBundleService managedBundleService;
+   private ManagedFrameworkImpl managedFramework;
 
-   private LogService log;
-
    public void start(BundleContext context)
    {
-      log = new LogServiceTracker(context);
-
       // Register the MBeanServer 
       MBeanServerService service = new MBeanServerService(context);
       mbeanServer = service.registerMBeanServer();
@@ -76,18 +73,14 @@
       // Get the system BundleContext
       BundleContext sysContext = context.getBundle(0).getBundleContext();
 
-      // Register the ManagedBundleService 
-      managedBundleService = new ManagedBundleServiceImpl(sysContext, mbeanServer);
-      context.registerService(ManagedBundleService.class.getName(), managedBundleService, null);
-      log.log(LogService.LOG_DEBUG, "ManagedBundleService registered");
-
       // Register the ManagedFramework 
-      managedFramework = new ManagedFramework(sysContext, mbeanServer);
+      managedFramework = new ManagedFrameworkImpl(sysContext, mbeanServer);
+      context.registerService(ManagedFramework.class.getName(), managedFramework, null);
       managedFramework.start();
 
-      // Register all ManagedBundles 
-      for (Bundle bundle : context.getBundles())
-         managedBundleService.register(bundle);
+      // Register the ManagedBundleService 
+      ManagedBundleService managedBundleService = new ManagedBundleServiceImpl(sysContext, mbeanServer);
+      context.registerService(ManagedBundleService.class.getName(), managedBundleService, null);
 
       jmxHost = context.getProperty(REMOTE_JMX_HOST);
       if (jmxHost == null)
@@ -108,10 +101,6 @@
 
    public void stop(BundleContext context)
    {
-      // Unregister all ManagedBundles 
-      for (Bundle bundle : context.getBundles())
-         managedBundleService.unregister(bundle);
-
       // Unregister the managed framework
       managedFramework.stop();
 
@@ -149,7 +138,7 @@
          catch (IOException ex)
          {
             // Assume that the JMXConnector is already running if we cannot start it 
-            log.log(LogService.LOG_DEBUG, "Assume JMXConnectorServer already running on: " + serviceURL);
+            log.debug("Assume JMXConnectorServer already running on: " + serviceURL);
          }
 
          try
@@ -168,11 +157,11 @@
                iniCtx.bind(rmiAdaptorPath, ref);
                rmiAdaptorBound = true;
 
-               log.log(LogService.LOG_INFO, "MBeanServerConnection bound to: " + rmiAdaptorPath);
+               log.info("MBeanServerConnection bound to: " + rmiAdaptorPath);
             }
             catch (NamingException ex)
             {
-               log.log(LogService.LOG_ERROR, "Cannot bind RMIAdaptor", ex);
+               log.error("Cannot bind RMIAdaptor", ex);
             }
          }
          return iniCtx;
@@ -196,11 +185,11 @@
             try
             {
                iniCtx.unbind(rmiAdaptorPath);
-               log.log(LogService.LOG_INFO, "MBeanServerConnection unbound from: " + rmiAdaptorPath);
+               log.info("MBeanServerConnection unbound from: " + rmiAdaptorPath);
             }
             catch (NamingException ex)
             {
-               log.log(LogService.LOG_ERROR, "Cannot unbind RMIAdaptor", ex);
+               log.error("Cannot unbind RMIAdaptor", ex);
             }
          }
 

Modified: projects/jboss-osgi/trunk/reactor/jmx/src/main/java/org/jboss/osgi/jmx/internal/MBeanServerService.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/jmx/src/main/java/org/jboss/osgi/jmx/internal/MBeanServerService.java	2009-10-29 09:14:39 UTC (rev 95735)
+++ projects/jboss-osgi/trunk/reactor/jmx/src/main/java/org/jboss/osgi/jmx/internal/MBeanServerService.java	2009-10-29 09:20:49 UTC (rev 95736)
@@ -28,10 +28,10 @@
 import javax.management.MBeanServer;
 import javax.management.MBeanServerFactory;
 
-import org.jboss.osgi.common.log.LogServiceTracker;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
-import org.osgi.service.log.LogService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * A service that registers an MBeanServer
@@ -41,12 +41,13 @@
  */
 public class MBeanServerService
 {
+   // Provide logging
+   private Logger log = LoggerFactory.getLogger(MBeanServerService.class);
+
    private BundleContext context;
-   private LogService log;
 
    public MBeanServerService(BundleContext context)
    {
-      log = new LogServiceTracker(context);
       this.context = context;
    }
 
@@ -60,30 +61,30 @@
       if (sref != null)
       {
          mbeanServer = (MBeanServer)context.getService(sref);
-         log.log(LogService.LOG_DEBUG, "Found MBeanServer fom service: " + mbeanServer.getDefaultDomain());
+         log.debug("Found MBeanServer fom service: " + mbeanServer.getDefaultDomain());
          return mbeanServer;
       }
 
       ArrayList<MBeanServer> serverArr = MBeanServerFactory.findMBeanServer(null);
       if (serverArr.size() > 1)
-         log.log(LogService.LOG_WARNING, "Multiple MBeanServer instances: " + serverArr);
+         log.warn("Multiple MBeanServer instances: " + serverArr);
 
       if (serverArr.size() > 0)
       {
          mbeanServer = serverArr.get(0);
-         log.log(LogService.LOG_DEBUG, "Found MBeanServer: " + mbeanServer.getDefaultDomain());
+         log.debug("Found MBeanServer: " + mbeanServer.getDefaultDomain());
       }
 
       if (mbeanServer == null)
       {
-         log.log(LogService.LOG_DEBUG, "No MBeanServer, create one ...");
+         log.debug("No MBeanServer, create one ...");
          mbeanServer = MBeanServerFactory.createMBeanServer();
       }
 
       // Register the MBeanServer 
       context.registerService(MBeanServer.class.getName(), mbeanServer, null);
-      log.log(LogService.LOG_DEBUG, "MBeanServer registered");
-      
+      log.debug("MBeanServer registered");
+
       return mbeanServer;
    }
 }
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/reactor/jmx/src/main/java/org/jboss/osgi/jmx/internal/ManagedBundleServiceImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/jmx/src/main/java/org/jboss/osgi/jmx/internal/ManagedBundleServiceImpl.java	2009-10-29 09:14:39 UTC (rev 95735)
+++ projects/jboss-osgi/trunk/reactor/jmx/src/main/java/org/jboss/osgi/jmx/internal/ManagedBundleServiceImpl.java	2009-10-29 09:20:49 UTC (rev 95736)
@@ -27,12 +27,14 @@
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
 
-import org.jboss.osgi.common.log.LogServiceTracker;
 import org.jboss.osgi.spi.management.ManagedBundle;
 import org.jboss.osgi.spi.management.ManagedBundleService;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
-import org.osgi.service.log.LogService;
+import org.osgi.framework.BundleEvent;
+import org.osgi.util.tracker.BundleTracker;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * A service that registers an MBeanServer
@@ -42,13 +44,18 @@
  */
 public class ManagedBundleServiceImpl implements ManagedBundleService
 {
-   private LogService log;
+   // Provide logging
+   private Logger log = LoggerFactory.getLogger(ManagedBundleServiceImpl.class);
+   
    private MBeanServer mbeanServer;
-   
+
    public ManagedBundleServiceImpl(BundleContext context, MBeanServer mbeanServer)
    {
-      this.log = new LogServiceTracker(context);
       this.mbeanServer = mbeanServer;
+
+      // Start tracking bundles
+      ManagedBundleTracker bundleTracker = new ManagedBundleTracker(context);
+      bundleTracker.open();
    }
 
    public ManagedBundle register(Bundle bundle)
@@ -57,18 +64,18 @@
       {
          ManagedBundle mb = new ManagedBundle(bundle);
          ObjectName oname = mb.getObjectName();
-         
+
          if (mbeanServer.isRegistered(oname) == false)
          {
-            log.log(LogService.LOG_DEBUG, "Register managed bundle: " + oname);
+            log.debug("Register managed bundle: " + oname);
             mbeanServer.registerMBean(mb, oname);
          }
-         
+
          return mb;
       }
       catch (JMException ex)
       {
-         log.log(LogService.LOG_ERROR, "Cannot register managed bundle", ex);
+         log.error("Cannot register managed bundle", ex);
          return null;
       }
    }
@@ -79,15 +86,38 @@
       {
          ManagedBundle mb = new ManagedBundle(bundle);
          ObjectName oname = mb.getObjectName();
-         
-         log.log(LogService.LOG_DEBUG, "Unregister managed bundle: " + oname);
+
+         log.debug("Unregister managed bundle: " + oname);
          if (mbeanServer.isRegistered(oname))
             mbeanServer.unregisterMBean(oname);
-         
+
       }
       catch (JMException ex)
       {
-         log.log(LogService.LOG_ERROR, "Cannot register managed bundle", ex);
+         log.error("Cannot register managed bundle", ex);
       }
    }
+
+   class ManagedBundleTracker extends BundleTracker
+   {
+      ManagedBundleTracker(BundleContext context)
+      {
+         super(context, Bundle.INSTALLED | Bundle.RESOLVED | Bundle.ACTIVE | Bundle.UNINSTALLED, null);
+      }
+
+      @Override
+      public Object addingBundle(Bundle bundle, BundleEvent event)
+      {
+         Object retObject = super.addingBundle(bundle, event);
+         register(bundle);
+         return retObject;
+      }
+
+      @Override
+      public void removedBundle(Bundle bundle, BundleEvent event, Object object)
+      {
+         unregister(bundle);
+         super.removedBundle(bundle, event, object);
+      }
+   }
 }
\ No newline at end of file

Copied: projects/jboss-osgi/trunk/reactor/jmx/src/main/java/org/jboss/osgi/jmx/internal/ManagedFrameworkImpl.java (from rev 95390, projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedFramework.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/jmx/src/main/java/org/jboss/osgi/jmx/internal/ManagedFrameworkImpl.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/jmx/src/main/java/org/jboss/osgi/jmx/internal/ManagedFrameworkImpl.java	2009-10-29 09:20:49 UTC (rev 95736)
@@ -0,0 +1,251 @@
+/*
+ * 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.jmx.internal;
+
+//$Id$
+
+import static org.jboss.osgi.spi.OSGiConstants.DOMAIN_NAME;
+import static org.jboss.osgi.spi.management.ManagedBundle.PROPERTY_SYMBOLIC_NAME;
+import static org.jboss.osgi.spi.management.ManagedBundle.PROPERTY_ID;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.management.JMException;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.management.QueryExp;
+import javax.management.StandardMBean;
+
+import org.jboss.osgi.spi.management.ManagedFrameworkMBean;
+import org.jboss.osgi.spi.management.ManagedServiceReference;
+import org.jboss.osgi.spi.management.ObjectNameFactory;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.packageadmin.PackageAdmin;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The managed view of an OSGi Framework
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 04-Mar-2009
+ */
+public class ManagedFrameworkImpl implements ManagedFrameworkMBean
+{
+   // Provide logging
+   final Logger log = LoggerFactory.getLogger(ManagedFrameworkImpl.class);
+
+   private MBeanServer mbeanServer;
+   private BundleContext bundleContext;
+
+   public ManagedFrameworkImpl(BundleContext bundleContext, MBeanServer mbeanServer)
+   {
+      if (bundleContext == null)
+         throw new IllegalArgumentException("Null BundleContext");
+      this.bundleContext = bundleContext;
+
+      if (mbeanServer == null)
+         throw new IllegalArgumentException("Null MBeanServer");
+      this.mbeanServer = mbeanServer;
+
+      if (bundleContext.getBundle().getBundleId() != 0)
+         throw new IllegalArgumentException("Not the system bundle context: " + bundleContext);
+   }
+
+   public BundleContext getBundleContext()
+   {
+      return bundleContext;
+   }
+
+   @SuppressWarnings("unchecked")
+   public ObjectName getBundle(String symbolicName, String version)
+   {
+      ObjectName oname = null;
+
+      ObjectName pattern = ObjectNameFactory.create(DOMAIN_NAME + ":" + PROPERTY_SYMBOLIC_NAME + "=" + symbolicName + ",*");
+      Set<ObjectName> names = mbeanServer.queryNames(pattern, null);
+
+      if (names.size() > 0)
+      {
+         // [TODO] Support bundle version 
+         if (names.size() > 1)
+            throw new IllegalArgumentException("Multiple bundles found: " + names);
+
+         oname = names.iterator().next();
+      }
+
+      return oname;
+   }
+
+   @SuppressWarnings("unchecked")
+   public ObjectName getBundle(long bundleId)
+   {
+      ObjectName oname = null;
+
+      ObjectName pattern = ObjectNameFactory.create(DOMAIN_NAME + ":" + PROPERTY_ID + "=" + bundleId + ",*");
+      Set<ObjectName> names = mbeanServer.queryNames(pattern, null);
+
+      if (names.size() > 0)
+         oname = names.iterator().next();
+
+      return oname;
+   }
+
+   @SuppressWarnings("unchecked")
+   public Set<ObjectName> getBundles()
+   {
+      // [JBAS-6571] JMX filtering does not work with wildcards
+      // ObjectName pattern = ObjectNameFactory.create(Constants.DOMAIN_NAME + ":sname=*,*");
+      // Set<ObjectName> names = mbeanServer.queryNames(pattern, null);
+
+      ObjectName pattern = ObjectNameFactory.create(DOMAIN_NAME + ":*");
+      Set<ObjectName> names = mbeanServer.queryNames(pattern, new IsBundleQueryExp());
+      return names;
+   }
+
+   public ManagedServiceReference getServiceReference(String clazz)
+   {
+      ServiceReference sref = getBundleContext().getServiceReference(clazz);
+      if (sref == null)
+         return null;
+
+      Map<String, Object> props = new HashMap<String, Object>();
+      for (String key : sref.getPropertyKeys())
+      {
+         props.put(key, sref.getProperty(key));
+      }
+
+      return new ManagedServiceReference(props);
+   }
+
+   public ManagedServiceReference[] getServiceReferences(String clazz, String filter)
+   {
+      List<ManagedServiceReference> foundRefs = new ArrayList<ManagedServiceReference>();
+
+      ServiceReference[] srefs;
+      try
+      {
+         srefs = getBundleContext().getServiceReferences(clazz, filter);
+      }
+      catch (InvalidSyntaxException e)
+      {
+         throw new IllegalArgumentException("Invalid filter syntax: " + filter);
+      }
+
+      if (srefs != null)
+      {
+         for (ServiceReference sref : srefs)
+         {
+            Map<String, Object> props = new HashMap<String, Object>();
+            for (String key : sref.getPropertyKeys())
+               props.put(key, sref.getProperty(key));
+
+            foundRefs.add(new ManagedServiceReference(props));
+         }
+      }
+
+      ManagedServiceReference[] manrefs = null;
+      if (foundRefs.size() > 0)
+         manrefs = foundRefs.toArray(new ManagedServiceReference[foundRefs.size()]);
+
+      return manrefs;
+   }
+
+   public void refreshPackages(ObjectName[] objectNames)
+   {
+      ServiceReference sref = getBundleContext().getServiceReference(PackageAdmin.class.getName());
+      if (sref != null)
+      {
+         PackageAdmin service = (PackageAdmin)getBundleContext().getService(sref);
+
+         Bundle[] bundleArr = null;
+         if (objectNames != null)
+         {
+            List<String> symbolicNames = new ArrayList<String>();
+            for (ObjectName oname : objectNames)
+               symbolicNames.add(oname.getKeyProperty(PROPERTY_SYMBOLIC_NAME));
+
+            Set<Bundle> bundleSet = new HashSet<Bundle>();
+            for (Bundle bundle : getBundleContext().getBundles())
+            {
+               if (symbolicNames.contains(bundle.getSymbolicName()))
+                  bundleSet.add(bundle);
+            }
+            bundleArr = new Bundle[bundleSet.size()];
+            bundleSet.toArray(bundleArr);
+         }
+         service.refreshPackages(bundleArr);
+      }
+   }
+
+   public void start()
+   {
+      try
+      {
+         if (mbeanServer != null)
+         {
+            StandardMBean mbean = new StandardMBean(this, ManagedFrameworkMBean.class);
+            mbeanServer.registerMBean(mbean, ManagedFrameworkMBean.MBEAN_MANAGED_FRAMEWORK);
+         }
+      }
+      catch (JMException ex)
+      {
+         log.warn("Cannot register: " + ManagedFrameworkMBean.MBEAN_MANAGED_FRAMEWORK);
+      }
+   }
+
+   public void stop()
+   {
+      try
+      {
+         if (mbeanServer != null && mbeanServer.isRegistered(MBEAN_MANAGED_FRAMEWORK))
+            mbeanServer.unregisterMBean(ManagedFrameworkMBean.MBEAN_MANAGED_FRAMEWORK);
+      }
+      catch (JMException ex)
+      {
+         log.warn("Cannot register: " + ManagedFrameworkMBean.MBEAN_MANAGED_FRAMEWORK);
+      }
+   }
+
+   // Accept names like "jboss.osgi:id=*"
+   static class IsBundleQueryExp implements QueryExp
+   {
+      private static final long serialVersionUID = 1L;
+
+      public boolean apply(ObjectName name)
+      {
+         return name.getKeyProperty("bundle") != null;
+      }
+
+      public void setMBeanServer(MBeanServer server)
+      {
+      }
+   }
+}
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/reactor/testing/src/main/java/org/jboss/osgi/testing/internal/RemotePackageAdmin.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/testing/src/main/java/org/jboss/osgi/testing/internal/RemotePackageAdmin.java	2009-10-29 09:14:39 UTC (rev 95735)
+++ projects/jboss-osgi/trunk/reactor/testing/src/main/java/org/jboss/osgi/testing/internal/RemotePackageAdmin.java	2009-10-29 09:20:49 UTC (rev 95736)
@@ -21,11 +21,15 @@
  */
 package org.jboss.osgi.testing.internal;
 
+import javax.management.ObjectName;
+
 import org.jboss.osgi.spi.management.MBeanProxy;
 import org.jboss.osgi.spi.management.MBeanProxyException;
+import org.jboss.osgi.spi.management.ManagedBundle;
 import org.jboss.osgi.spi.management.ManagedFrameworkMBean;
 import org.jboss.osgi.testing.OSGiBundle;
 import org.jboss.osgi.testing.OSGiPackageAdmin;
+import org.osgi.framework.Version;
 
 /**
  * A remote implementation of the {@link OSGiPackageAdmin}
@@ -44,13 +48,17 @@
 
    public void refreshPackages(OSGiBundle[] bundles)
    {
-      String[] bundleArr = null;
+      ObjectName[] bundleArr = null;
       if (bundles != null)
       {
-         bundleArr = new String[bundles.length];
+         bundleArr = new ObjectName[bundles.length];
          for (int i=0; i < bundles.length; i++)
          {
-            bundleArr[i] = bundles[i].getSymbolicName();
+            OSGiBundle bundle = bundles[i];
+            long id = bundle.getBundleId();
+            String symbolicName = bundle.getSymbolicName();
+            Version version = bundle.getVersion();
+            bundleArr[i] = ManagedBundle.getObjectName(id, symbolicName, version);
          }
       }
       try



More information about the jboss-osgi-commits mailing list