[jboss-cvs] JBossAS SVN: r87165 - in projects/jboss-osgi/trunk: runtime/felix/src/main/resources and 18 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Apr 11 15:41:31 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-04-11 15:41:30 -0400 (Sat, 11 Apr 2009)
New Revision: 87165

Added:
   projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/service/log/
   projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/service/log/LogEntryCache.java
   projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/service/log/LogEntryFilter.java
   projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/service/log/SystemLogService.java
   projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/service/mc/
   projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/service/mc/MicrocontainerService.java
   projects/jboss-osgi/trunk/testsuite/scripts/assembly-thirdparty-bundles.xml
   projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/example/
   projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/example/log/
   projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/example/log/LogServiceTestCase.java
   projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/example/log/bundleA/
   projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/example/log/bundleA/ServiceA.java
   projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/example/log/bundleA/ServiceActivator.java
   projects/jboss-osgi/trunk/testsuite/src/test/resources/example/
   projects/jboss-osgi/trunk/testsuite/src/test/resources/example/log/
   projects/jboss-osgi/trunk/testsuite/src/test/resources/example/log/example-log-bundleA.bnd
Removed:
   projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/service/MicrocontainerService.java
Modified:
   projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleRealDeployer.java
   projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleStartStopDeployer.java
   projects/jboss-osgi/trunk/runtime/felix/src/main/resources/jboss-osgi-beans.xml
   projects/jboss-osgi/trunk/runtime/spi/pom.xml
   projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/Constants.java
   projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/framework/OSGiStateFormat.java
   projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/junit/OSGiTest.java
   projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/junit/OSGiTestHelper.java
   projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedBundle.java
   projects/jboss-osgi/trunk/testsuite/pom.xml
   projects/jboss-osgi/trunk/testsuite/scripts/antrun-test-jars.xml
   projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/service/microcontainer/bundle/MBeanTestService.java
Log:
[JBOSGI-60] Initial LogService example

Modified: projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleRealDeployer.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleRealDeployer.java	2009-04-11 14:37:30 UTC (rev 87164)
+++ projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleRealDeployer.java	2009-04-11 19:41:30 UTC (rev 87165)
@@ -30,7 +30,7 @@
 import org.jboss.deployers.spi.deployer.DeploymentStages;
 import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.osgi.spi.framework.OSGiStateFormat;
+import org.jboss.osgi.spi.Constants;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
@@ -96,7 +96,7 @@
                Bundle bundle = systemContext.installBundle(bundleUri.toString());
                unit.addAttachment(Bundle.class, bundle);
                
-               String state = OSGiStateFormat.formatBundleState(bundle.getState());
+               String state = Constants.bundleState(bundle.getState());
                log.info("Installed: " + bundle + state);
             }
          }
@@ -116,7 +116,7 @@
          try
          {
             bundle.uninstall();
-            String state = OSGiStateFormat.formatBundleState(bundle.getState());
+            String state = Constants.bundleState(bundle.getState());
             log.info("Uninstalled: " + bundle + state);
          }
          catch (BundleException ex)

Modified: projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleStartStopDeployer.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleStartStopDeployer.java	2009-04-11 14:37:30 UTC (rev 87164)
+++ projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleStartStopDeployer.java	2009-04-11 19:41:30 UTC (rev 87165)
@@ -31,7 +31,6 @@
 import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.osgi.spi.Constants;
-import org.jboss.osgi.spi.framework.OSGiStateFormat;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
@@ -85,7 +84,7 @@
          
          unresolvedBundles.remove(bundle);
 
-         String state = OSGiStateFormat.formatBundleState(bundle.getState());
+         String state = Constants.bundleState(bundle.getState());
          log.info("Stoped: " + bundle + state);
       }
       catch (BundleException e)
@@ -99,7 +98,7 @@
       try
       {
          bundle.start();
-         String state = OSGiStateFormat.formatBundleState(bundle.getState());
+         String state = Constants.bundleState(bundle.getState());
          log.info("Started: " + bundle + state);
       }
       catch (BundleException e)
@@ -139,7 +138,7 @@
             try
             {
                auxBundle.start();
-               String state = OSGiStateFormat.formatBundleState(bundle.getState());
+               String state = Constants.bundleState(bundle.getState());
                log.info("Started: " + bundle + state);
             }
             catch (BundleException e)

Modified: projects/jboss-osgi/trunk/runtime/felix/src/main/resources/jboss-osgi-beans.xml
===================================================================
--- projects/jboss-osgi/trunk/runtime/felix/src/main/resources/jboss-osgi-beans.xml	2009-04-11 14:37:30 UTC (rev 87164)
+++ projects/jboss-osgi/trunk/runtime/felix/src/main/resources/jboss-osgi-beans.xml	2009-04-11 19:41:30 UTC (rev 87165)
@@ -11,7 +11,9 @@
     <entry>
       <key>org.osgi.framework.system.packages</key>
       <value>
+        org.jboss.osgi.service.log,
         org.osgi.framework; version=1.4,
+        org.osgi.service.log; version=1.3,
         org.osgi.util.tracker
       </value>
     </entry>

Modified: projects/jboss-osgi/trunk/runtime/spi/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/runtime/spi/pom.xml	2009-04-11 14:37:30 UTC (rev 87164)
+++ projects/jboss-osgi/trunk/runtime/spi/pom.xml	2009-04-11 19:41:30 UTC (rev 87165)
@@ -24,6 +24,11 @@
       <scope>provided</scope>
     </dependency>
     <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.compendium</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
       <groupId>org.jboss.deployers</groupId>
       <artifactId>jboss-deployers-client-spi</artifactId>
     </dependency>

Deleted: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/service/MicrocontainerService.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/service/MicrocontainerService.java	2009-04-11 14:37:30 UTC (rev 87164)
+++ projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/service/MicrocontainerService.java	2009-04-11 19:41:30 UTC (rev 87165)
@@ -1,85 +0,0 @@
-/*
- * 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.service;
-
-//$Id$
-
-import javax.management.MBeanServer;
-
-import org.jboss.dependency.spi.ControllerContext;
-import org.jboss.kernel.Kernel;
-import org.osgi.framework.BundleContext;
-
-/**
- * An OSGi Service the gives access to the Kernel and MBeanServer.
- * 
- * @author thomas.diesler at jboss.com
- * @since 23-Jan-2009
- */
-public class MicrocontainerService
-{
-  private BundleContext systemContext;
-  private MBeanServer mbeanServer;
-  private Kernel kernel;
-
-  /**
-   *  Register this bean as an OSGi service
-   */
-  public void create()
-  {
-    systemContext.registerService(MicrocontainerService.class.getName(), this, null);
-  }
-  
-  public void setSystemContext(BundleContext bundleContext)
-  {
-    this.systemContext = bundleContext;
-  }
-
-  public void setKernel(Kernel kernel)
-  {
-    this.kernel = kernel;
-  }
-
-  public Kernel getKernel()
-  {
-    return kernel;
-  }
-
-  public MBeanServer getMbeanServer()
-  {
-    return mbeanServer;
-  }
-
-  public void setMbeanServer(MBeanServer server)
-  {
-    this.mbeanServer = server;
-  }
-
-  public Object getRegisteredBean(String beanName)
-  {
-    if (kernel == null)
-      throw new IllegalArgumentException("Kernel cannot be null");
-
-    ControllerContext context = kernel.getController().getInstalledContext(beanName);
-    return context.getTarget();
-  }
-}
\ No newline at end of file

Added: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/service/log/LogEntryCache.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/service/log/LogEntryCache.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/service/log/LogEntryCache.java	2009-04-11 19:41:30 UTC (rev 87165)
@@ -0,0 +1,199 @@
+/*
+ * 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.service.log;
+
+//$Id$
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.jboss.osgi.spi.Constants;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogEntry;
+import org.osgi.service.log.LogListener;
+
+/**
+ * A LogListener that caches LogEntry objects for later retrieval.
+ * 
+ * The entries can be filtered with a list of {@link LogEntryFilter} instances. 
+ * A log entry is cached if it matches at least one of the registered filters.
+ * If there is no filter registered entries are cached unconditionally.  
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 09-Apr-2009
+ */
+public class LogEntryCache implements LogListener
+{
+   private List<LogEntry> entries = new ArrayList<LogEntry>();
+   private List<LogEntryFilter> filters = new ArrayList<LogEntryFilter>();
+   
+   /**
+    * Create a LogEntryCache with a single associated filter
+    */
+   public LogEntryCache(LogEntryFilter filter)
+   {
+      filters.add(filter);
+   }
+
+   /**
+    * Create a LogEntryCache with no associated filters
+    */
+   public LogEntryCache()
+   {
+   }
+   
+   /**
+    * Add a LogEntryFilter
+    */
+   public void addFilter(LogEntryFilter filter)
+   {
+      filters.add(filter);
+   }
+
+   /**
+    * Clear the list of cached entries.
+    */
+   public void clear()
+   {
+      // entries.clear() would need synchronization
+      entries = new ArrayList<LogEntry>();
+   }
+
+   /**
+    * Clear the list of registered filters.
+    */
+   public void clearFilters()
+   {
+      // filters.clear() would need synchronization
+      filters = new ArrayList<LogEntryFilter>();
+   }
+   
+   /**
+    * Get the list of cached entries
+    */
+   public List<LogEntry> getLog()
+   {
+      return new ArrayList<LogEntry>(entries);
+   }
+   
+   /**
+    * Listener method called for each LogEntry object created. 
+    */
+   public void logged(LogEntry entry)
+   {
+      // Replace entry with a unified wrapper
+      entry = new LogEntryWrapper(entry);
+      
+      if (filters.size() == 0)
+      {
+         entries.add(entry);
+         return;
+      }
+
+      // Add the entry if if matches at least one filter
+      for (LogEntryFilter filter : filters)
+      {
+         if (match(filter, entry))
+         {
+            entries.add(entry);
+            break;
+         }
+      }
+   }
+
+   private boolean match(LogEntryFilter filter, LogEntry entry)
+   {
+      boolean match = entry.getLevel() <= filter.getLevel();
+      
+      if (match && filter.getBundleRegex() != null)
+      {
+         String entryBnd = entry.getBundle().getSymbolicName();
+         String filterRegex = filter.getBundleRegex();
+         match = entryBnd.matches(filterRegex);
+      }
+         
+      if (match && filter.getMessageRegex() != null)
+      {
+         String entryMsg = entry.getMessage();
+         String filterRegex = filter.getMessageRegex();
+         match = entryMsg.matches(filterRegex);
+      }
+         
+      return match;
+   }
+   
+   class LogEntryWrapper implements LogEntry
+   {
+      private LogEntry delegate;
+
+      
+      public LogEntryWrapper(LogEntry entry)
+      {
+         this.delegate = entry;
+      }
+
+      public Bundle getBundle()
+      {
+         return delegate.getBundle();
+      }
+
+      public Throwable getException()
+      {
+         return delegate.getException();
+      }
+
+      public int getLevel()
+      {
+         return delegate.getLevel();
+      }
+
+      public String getMessage()
+      {
+         return delegate.getMessage();
+      }
+
+      public ServiceReference getServiceReference()
+      {
+         return delegate.getServiceReference();
+      }
+
+      public long getTime()
+      {
+         return delegate.getTime();
+      }
+
+      @Override
+      public String toString()
+      {
+         String time = new SimpleDateFormat("dd-MMM-yyyy HH:mm.ss.SSS").format(new Date(getTime()));
+         String level = " " + Constants.logLevel(getLevel());
+         String sref = getServiceReference() != null ? ",sref=" + getServiceReference().getBundle().getSymbolicName() : "";
+         String bundle = ",bnd=" + getBundle().getSymbolicName();
+         String msg = ",msg=" + getMessage();
+         String ex = getException() != null ? ",ex=" + getException().toString() : "";
+         return "[" + time + level + bundle + sref + msg + ex + "]";
+      }
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/service/log/LogEntryCache.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/service/log/LogEntryFilter.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/service/log/LogEntryFilter.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/service/log/LogEntryFilter.java	2009-04-11 19:41:30 UTC (rev 87165)
@@ -0,0 +1,97 @@
+/*
+ * 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.service.log;
+
+//$Id$
+
+
+/**
+ * A LogEntry filter that can be used with the LogEntryCache  
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 09-Apr-2009
+ */
+public class LogEntryFilter
+{
+   private int level;
+   private String bndRegex;
+   private String msgRegex;
+   
+   /**
+    * Create a LogEntryFilter with the associated criteria.
+    *  
+    * @param bndRegex A regex that matches a Bundle's SymbolicName
+    * @param level The maximum log level accepted by this filter
+    * @param msgRegex A regex that matches the log message
+    */
+   public LogEntryFilter(String bndRegex, int level, String msgRegex)
+   {
+      this.bndRegex = bndRegex;
+      this.msgRegex = msgRegex;
+      this.level = level;
+   }
+   
+   /**
+    * Create a LogEntryFilter with the associated criteria.
+    *  
+    * @param bndRegex A regex that matches a Bundle's SymbolicName
+    * @param level The maximum log level accepted by this filter
+    */
+   public LogEntryFilter(String bndRegex, int level)
+   {
+      this(bndRegex, level, null);
+   }
+   
+   /**
+    * Create a LogEntryFilter with the associated criteria.
+    *  
+    * @param bndRegex A regex that matches a Bundle's SymbolicName
+    */
+   public LogEntryFilter(String bndRegex)
+   {
+      this(bndRegex, Integer.MAX_VALUE, null);
+   }
+   
+   /**
+    * Get the Bundle Symbolic-Name regex.
+    */
+   public String getBundleRegex()
+   {
+      return bndRegex;
+   }
+
+   /**
+    * Get the log message regex.
+    */
+   public String getMessageRegex()
+   {
+      return msgRegex;
+   }
+
+   /**
+    * Get the log entry maximum log level.
+    */
+   public int getLevel()
+   {
+      return level;
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/service/log/LogEntryFilter.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/service/log/SystemLogService.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/service/log/SystemLogService.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/service/log/SystemLogService.java	2009-04-11 19:41:30 UTC (rev 87165)
@@ -0,0 +1,75 @@
+/*
+ * 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.service.log;
+
+//$Id$
+
+import org.jboss.osgi.spi.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
+
+/**
+ * A basic LogService that writes to System.out
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 11-Apr-2009
+ */
+public class SystemLogService implements LogService
+{
+   public void log(int level, String message)
+   {
+      logInternal(null, level, message, null);
+   }
+
+   public void log(int level, String message, Throwable exception)
+   {
+      logInternal(null, level, message, exception);
+   }
+
+   public void log(ServiceReference sr, int level, String message)
+   {
+      logInternal(sr, level, message, null);
+   }
+
+   public void log(ServiceReference sr, int level, String message, Throwable exception)
+   {
+      logInternal(sr, level, message, exception);
+   }
+
+   private void logInternal(ServiceReference sr, int level, String message, Throwable exception)
+   {
+      StringBuffer buf = new StringBuffer();
+      if (sr != null)
+      {
+         String symbolicName = sr.getBundle().getSymbolicName();
+         buf.append(symbolicName + ": ");
+      }
+      
+      buf.append("[" + Constants.logLevel(level) +"] ");
+      
+      buf.append(message);
+      System.out.println(buf);
+      
+      if (exception != null)
+         exception.printStackTrace(System.out);
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/service/log/SystemLogService.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Copied: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/service/mc/MicrocontainerService.java (from rev 87161, projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/service/MicrocontainerService.java)
===================================================================
--- projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/service/mc/MicrocontainerService.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/service/mc/MicrocontainerService.java	2009-04-11 19:41:30 UTC (rev 87165)
@@ -0,0 +1,85 @@
+/*
+ * 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.service.mc;
+
+//$Id$
+
+import javax.management.MBeanServer;
+
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.kernel.Kernel;
+import org.osgi.framework.BundleContext;
+
+/**
+ * An OSGi Service the gives access to the Kernel and MBeanServer.
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 23-Jan-2009
+ */
+public class MicrocontainerService
+{
+  private BundleContext systemContext;
+  private MBeanServer mbeanServer;
+  private Kernel kernel;
+
+  /**
+   *  Register this bean as an OSGi service
+   */
+  public void create()
+  {
+    systemContext.registerService(MicrocontainerService.class.getName(), this, null);
+  }
+  
+  public void setSystemContext(BundleContext bundleContext)
+  {
+    this.systemContext = bundleContext;
+  }
+
+  public void setKernel(Kernel kernel)
+  {
+    this.kernel = kernel;
+  }
+
+  public Kernel getKernel()
+  {
+    return kernel;
+  }
+
+  public MBeanServer getMbeanServer()
+  {
+    return mbeanServer;
+  }
+
+  public void setMbeanServer(MBeanServer server)
+  {
+    this.mbeanServer = server;
+  }
+
+  public Object getRegisteredBean(String beanName)
+  {
+    if (kernel == null)
+      throw new IllegalArgumentException("Kernel cannot be null");
+
+    ControllerContext context = kernel.getController().getInstalledContext(beanName);
+    return context.getTarget();
+  }
+}
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/Constants.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/Constants.java	2009-04-11 14:37:30 UTC (rev 87164)
+++ projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/Constants.java	2009-04-11 19:41:30 UTC (rev 87165)
@@ -21,6 +21,9 @@
  */
 package org.jboss.osgi.spi;
 
+import org.osgi.framework.Bundle;
+import org.osgi.service.log.LogService;
+
 // $Id$
 
 /**
@@ -29,7 +32,7 @@
  * @author thomas.diesler at jboss.com
  * @since 04-Mar-2009
  */
-public interface Constants 
+public abstract class Constants 
 {
    /** The JBossOSGi domain 'jboss.osgi' */
    final String DOMAIN_NAME = "jboss.osgi";
@@ -41,4 +44,53 @@
     * The default is 'true' 
     */
    final String PROPERTY_DEFERRED_START = "org.jboss.osgi.deferred.start";
+
+   /**
+    * Return the string representation of a bundle state
+    */
+   public static String bundleState(int bundleState)
+   {
+      String retState = "[" + bundleState + "]";
+      
+      if (Bundle.UNINSTALLED == bundleState)
+         retState = "[UNINSTALLED]";
+      else if (Bundle.INSTALLED == bundleState)
+         retState = "[INSTALLED]";
+      else if (Bundle.RESOLVED == bundleState)
+         retState = "[RESOLVED]";
+      else if (Bundle.STARTING == bundleState)
+         retState = "[STARTING]";
+      else if (Bundle.STOPPING == bundleState)
+         retState = "[STOPPING]";
+      else if (Bundle.ACTIVE == bundleState)
+         retState = "[ACTIVE]";
+      
+      return retState;
+   }
+   
+   /**
+    * Return the string representation of a log level
+    */
+   public static String logLevel(int level)
+   {
+      String logLevel;
+      switch (level)
+      {
+         case LogService.LOG_DEBUG:
+            logLevel = "DEBUG";
+            break;
+         case LogService.LOG_INFO:
+            logLevel = "INFO";
+            break;
+         case LogService.LOG_WARNING:
+            logLevel = "WARN";
+            break;
+         case LogService.LOG_ERROR:
+            logLevel = "ERROR";
+            break;
+         default:
+            logLevel = "Level=" + level;
+      }
+      return logLevel;
+   }
 }

Modified: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/framework/OSGiStateFormat.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/framework/OSGiStateFormat.java	2009-04-11 14:37:30 UTC (rev 87164)
+++ projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/framework/OSGiStateFormat.java	2009-04-11 19:41:30 UTC (rev 87165)
@@ -23,7 +23,6 @@
 
 //$Id$
 
-import org.osgi.framework.Bundle;
 
 /**
  * A string format helper for OSGi states
@@ -37,27 +36,4 @@
    private OSGiStateFormat()
    {     
    }
-   
-   /**
-    * Return the string representation of a bundle state
-    */
-   public static String formatBundleState(int bundleState)
-   {
-      String retState = "[" + bundleState + "]";
-      
-      if (Bundle.UNINSTALLED == bundleState)
-         retState = "[UNINSTALLED]";
-      else if (Bundle.INSTALLED == bundleState)
-         retState = "[INSTALLED]";
-      else if (Bundle.RESOLVED == bundleState)
-         retState = "[RESOLVED]";
-      else if (Bundle.STARTING == bundleState)
-         retState = "[STARTING]";
-      else if (Bundle.STOPPING == bundleState)
-         retState = "[STOPPING]";
-      else if (Bundle.ACTIVE == bundleState)
-         retState = "[ACTIVE]";
-      
-      return retState;
-   }
 }
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/junit/OSGiTest.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/junit/OSGiTest.java	2009-04-11 14:37:30 UTC (rev 87164)
+++ projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/junit/OSGiTest.java	2009-04-11 19:41:30 UTC (rev 87165)
@@ -29,6 +29,9 @@
 import org.jboss.osgi.spi.framework.OSGiBootstrap;
 import org.jboss.osgi.spi.framework.OSGiBootstrapProvider;
 import org.jboss.virtual.VFS;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
 
 import junit.framework.TestCase;
 
@@ -116,4 +119,9 @@
    {
       return delegate.getTestArchiveFile(archive).toURI().toURL();
    }
+
+   protected Bundle installBundle(BundleContext sysContext, String bundlePath, boolean start) throws BundleException
+   {
+      return delegate.installBundle(sysContext, bundlePath, start);
+   }
 }

Modified: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/junit/OSGiTestHelper.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/junit/OSGiTestHelper.java	2009-04-11 14:37:30 UTC (rev 87164)
+++ projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/junit/OSGiTestHelper.java	2009-04-11 19:41:30 UTC (rev 87165)
@@ -25,6 +25,10 @@
 import java.net.MalformedURLException;
 import java.net.URL;
 
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+
 /**
  * An OSGi Test Helper
  * 
@@ -33,76 +37,93 @@
  */
 public class OSGiTestHelper
 {
-  private static final String SYSPROP_TEST_RESOURCES_DIRECTORY = "test.resources.directory";
-  private static final String SYSPROP_TEST_ARCHIVE_DIRECTORY = "test.archive.directory";
+   private static final String SYSPROP_TEST_RESOURCES_DIRECTORY = "test.resources.directory";
+   private static final String SYSPROP_TEST_ARCHIVE_DIRECTORY = "test.archive.directory";
 
-  private static String testResourcesDir;
-  private static String testArchiveDir;
+   private static String testResourcesDir;
+   private static String testArchiveDir;
 
-  /** Try to discover the URL for the test resource */
-  public URL getResourceURL(String resource) 
-  {
-    URL resURL = null;
-    try
-    {
-      File resourceFile = getResourceFile(resource);
-      resURL = resourceFile.toURI().toURL();
-    }
-    catch (MalformedURLException e)
-    {
-      // ignore
-    }
-    return resURL;
-  }
+   /** Try to discover the URL for the test resource */
+   public URL getResourceURL(String resource)
+   {
+      URL resURL = null;
+      try
+      {
+         File resourceFile = getResourceFile(resource);
+         resURL = resourceFile.toURI().toURL();
+      }
+      catch (MalformedURLException e)
+      {
+         // ignore
+      }
+      return resURL;
+   }
 
-  /** Try to discover the File for the test resource */
-  public File getResourceFile(String resource)
-  {
-    File file = new File(resource);
-    if (file.exists())
-      return file;
+   /** Try to discover the File for the test resource */
+   public File getResourceFile(String resource)
+   {
+      File file = new File(resource);
+      if (file.exists())
+         return file;
 
-    file = new File(getTestResourcesDir() + "/" + resource);
-    if (file.exists())
-      return file;
+      file = new File(getTestResourcesDir() + "/" + resource);
+      if (file.exists())
+         return file;
 
-    throw new IllegalArgumentException("Cannot obtain '" + getTestResourcesDir() + "/" + resource + "'");
-  }
+      throw new IllegalArgumentException("Cannot obtain '" + getTestResourcesDir() + "/" + resource + "'");
+   }
 
-  public String getTestResourcesDir()
-  {
-    if (testResourcesDir == null)
-      testResourcesDir = System.getProperty(SYSPROP_TEST_RESOURCES_DIRECTORY, "target/test-classes");
+   public String getTestResourcesDir()
+   {
+      if (testResourcesDir == null)
+         testResourcesDir = System.getProperty(SYSPROP_TEST_RESOURCES_DIRECTORY, "target/test-classes");
 
-    return testResourcesDir;
-  }
+      return testResourcesDir;
+   }
 
-  /** Try to discover the URL for the deployment archive */
-  public URL getTestArchiveURL(String archive) throws MalformedURLException
-  {
-    return getTestArchiveFile(archive).toURI().toURL();
-  }
+   /** Try to discover the URL for the deployment archive */
+   public URL getTestArchiveURL(String archive)
+   {
+      try
+      {
+         return getTestArchiveFile(archive).toURI().toURL();
+      }
+      catch (MalformedURLException ex)
+      {
+         throw new IllegalStateException(ex);
+      }
+   }
 
-  /** Try to discover the File for the deployment archive */
-  public File getTestArchiveFile(String archive)
-  {
-    File file = new File(archive);
-    if (file.exists())
-      return file;
-  
-    file = new File(getTestArchiveDir() + "/" + archive);
-    if (file.exists())
-      return file;
-  
-    String notSet = (getTestArchiveDir() == null ? " System property '" + SYSPROP_TEST_ARCHIVE_DIRECTORY + "' not set." : "");
-    throw new IllegalArgumentException("Cannot obtain '" + getTestArchiveDir() + "/" + archive + "'." + notSet);
-  }
+   /** Try to discover the File for the deployment archive */
+   public File getTestArchiveFile(String archive)
+   {
+      File file = new File(archive);
+      if (file.exists())
+         return file;
 
-  public String getTestArchiveDir()
-  {
-    if (testArchiveDir == null)
-      testArchiveDir = System.getProperty(SYSPROP_TEST_ARCHIVE_DIRECTORY, "target/test-libs");
-  
-    return testArchiveDir;
-  }
+      file = new File(getTestArchiveDir() + "/" + archive);
+      if (file.exists())
+         return file;
+
+      String notSet = (getTestArchiveDir() == null ? " System property '" + SYSPROP_TEST_ARCHIVE_DIRECTORY + "' not set." : "");
+      throw new IllegalArgumentException("Cannot obtain '" + getTestArchiveDir() + "/" + archive + "'." + notSet);
+   }
+
+   public String getTestArchiveDir()
+   {
+      if (testArchiveDir == null)
+         testArchiveDir = System.getProperty(SYSPROP_TEST_ARCHIVE_DIRECTORY, "target/test-libs");
+
+      return testArchiveDir;
+   }
+
+   public Bundle installBundle(BundleContext sysContext, String bundlePath, boolean start) throws BundleException
+   {
+      Bundle bundle = sysContext.installBundle(getTestArchiveURL(bundlePath).toExternalForm());
+
+      if (start == true)
+         bundle.start();
+
+      return bundle;
+   }
 }

Modified: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedBundle.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedBundle.java	2009-04-11 14:37:30 UTC (rev 87164)
+++ projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedBundle.java	2009-04-11 19:41:30 UTC (rev 87165)
@@ -27,7 +27,6 @@
 
 import org.jboss.logging.Logger;
 import org.jboss.osgi.spi.Constants;
-import org.jboss.osgi.spi.framework.OSGiStateFormat;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleException;
 
@@ -80,7 +79,7 @@
    {
       bundle.start();
       
-      String state = OSGiStateFormat.formatBundleState(bundle.getState());
+      String state = Constants.bundleState(bundle.getState());
       log.info(bundle.getSymbolicName() + ",state=" + state);
    }
 
@@ -88,7 +87,7 @@
    {
       bundle.stop();
       
-      String state = OSGiStateFormat.formatBundleState(bundle.getState());
+      String state = Constants.bundleState(bundle.getState());
       log.info(bundle.getSymbolicName() + ",state=" + state);
    }
 }
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/testsuite/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/pom.xml	2009-04-11 14:37:30 UTC (rev 87164)
+++ projects/jboss-osgi/trunk/testsuite/pom.xml	2009-04-11 19:41:30 UTC (rev 87165)
@@ -41,6 +41,18 @@
       <artifactId>jboss-aop-mc-int</artifactId>
     </dependency>
 
+    <!-- Provided Dependencies -->
+    <dependency>
+      <groupId>org.apache.felix</groupId>
+      <artifactId>org.apache.felix.log</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.compendium</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    
     <!-- Test Dependencies -->
     <dependency>
       <groupId>junit</groupId>
@@ -59,6 +71,26 @@
     </testResources>
     <plugins>
       <plugin>
+        <artifactId>maven-assembly-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>thirdparty-bundles</id>
+            <phase>test-compile</phase>
+            <goals>
+              <goal>single</goal>
+            </goals>
+            <configuration>
+              <finalName>test-libs</finalName>
+              <ignoreDirFormatExtensions>true</ignoreDirFormatExtensions>
+              <appendAssemblyId>false</appendAssemblyId>
+              <descriptors>
+                <descriptor>scripts/assembly-thirdparty-bundles.xml</descriptor>
+              </descriptors>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
         <artifactId>maven-antrun-plugin</artifactId>
         <executions>
           <execution>
@@ -83,9 +115,9 @@
   <profiles>
 
     <!--
-      Name:  framework-any
-      Descr: Create the testsuite.zip and skip tests
-    -->
+	 Name: framework-any 
+     Descr: Create the testsuite.zip and skip tests
+	-->
     <profile>
       <id>framework-any</id>
       <activation>
@@ -138,8 +170,7 @@
                 <configuration>
                   <artifacts>
                     <artifact>
-                      <file>target/${project.artifactId}-${project.version}.zip 
-                  </file>
+                      <file>target/${project.artifactId}-${project.version}.zip</file>
                       <type>zip</type>
                     </artifact>
                   </artifacts>
@@ -158,7 +189,7 @@
     </profile>
 
     <!--
-      Name:  framework-default
+	  Name: framework-default 
       Descr: Setup for default framework integration testing
     -->
     <profile>
@@ -184,9 +215,9 @@
     </profile>
 
     <!--
-      Name:  embedded-tesing
+	  Name: embedded-tesing 
       Descr: Setup for embedded integration testing
-    -->
+	-->
     <profile>
       <id>embedded-tesing</id>
       <activation>
@@ -211,7 +242,7 @@
     </profile>
 
     <!--
-      Name:  remote-tesing
+	  Name: remote-tesing 
       Descr: Setup for remote integration testing
     -->
     <profile>

Modified: projects/jboss-osgi/trunk/testsuite/scripts/antrun-test-jars.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/scripts/antrun-test-jars.xml	2009-04-11 14:37:30 UTC (rev 87164)
+++ projects/jboss-osgi/trunk/testsuite/scripts/antrun-test-jars.xml	2009-04-11 19:41:30 UTC (rev 87165)
@@ -22,7 +22,7 @@
     <property name="maven.runtime.classpath" value="/usr/java/bnd.jar" />
     <property name="tests.output.dir" value="${basedir}/../target" />
 
-    <mkdir dir="${tests.output.dir}/test-libs" />
+    <mkdir dir="${tests.output.dir}/test-libs/example" />
     <property name="tests.classes.dir" value="${tests.output.dir}/test-classes" />
     <property name="tests.resources.dir" value="${tests.output.dir}/test-classes" />
 
@@ -42,6 +42,9 @@
 
     <!-- Please add alphabetically -->
 
+    <!-- example/log -->
+    <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/example/example-log-bundleA.jar" files="${tests.resources.dir}/example/log/example-log-bundleA.bnd" />
+  	
     <!-- jbosgi36 -->
     <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/jbosgi36-bundle.jar" files="${tests.resources.dir}/deployer/jbosgi36/jbosgi36.bnd" />
     <jar jarfile="${tests.output.dir}/test-libs/jbosgi36-mbean.jar">

Added: projects/jboss-osgi/trunk/testsuite/scripts/assembly-thirdparty-bundles.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/scripts/assembly-thirdparty-bundles.xml	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/scripts/assembly-thirdparty-bundles.xml	2009-04-11 19:41:30 UTC (rev 87165)
@@ -0,0 +1,27 @@
+<assembly xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/assembly-1.1.0-SNAPSHOT.xsd">
+
+  <id>deploy-artifacts</id>
+  <formats>
+    <format>dir</format>
+  </formats>
+  <includeBaseDirectory>false</includeBaseDirectory>
+
+  <!-- Dependency Sets -->
+  <dependencySets>
+  
+    <!-- bundle -->
+    <dependencySet>
+      <outputDirectory>thirdparty</outputDirectory>
+      <outputFileNameMapping>${artifact.artifactId}${dashClassifier?}.${artifact.extension}</outputFileNameMapping>
+      <includes>
+        <include>*:org.apache.felix.log:jar</include>
+        <include>*:org.osgi.compendium:jar</include>
+      </includes>
+      <useStrictFiltering>true</useStrictFiltering>
+      <scope>provided</scope>
+      <unpack>false</unpack>
+    </dependencySet>
+    
+  </dependencySets>
+</assembly>


Property changes on: projects/jboss-osgi/trunk/testsuite/scripts/assembly-thirdparty-bundles.xml
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/example/log/LogServiceTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/example/log/LogServiceTestCase.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/example/log/LogServiceTestCase.java	2009-04-11 19:41:30 UTC (rev 87165)
@@ -0,0 +1,84 @@
+/*
+ * 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.test.osgi.example.log;
+
+//$Id$
+
+import java.util.List;
+
+import org.jboss.osgi.service.log.LogEntryCache;
+import org.jboss.osgi.service.log.LogEntryFilter;
+import org.jboss.osgi.spi.framework.OSGiBootstrap;
+import org.jboss.osgi.spi.framework.OSGiFramework;
+import org.jboss.osgi.spi.junit.OSGiTest;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogEntry;
+import org.osgi.service.log.LogReaderService;
+import org.osgi.service.log.LogService;
+import org.osgi.util.tracker.ServiceTracker;
+
+/**
+ * This example demonstrates the usage of the {@link LogService}
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 09-Apr-2009
+ */
+public class LogServiceTestCase extends OSGiTest
+{
+   public void testServiceA() throws Exception
+   {
+      // Bootstrap the Framework and get the system bundle
+      OSGiFramework framework = OSGiBootstrap.getBootstrapProvider().getFramework();
+      BundleContext sysContext = framework.getSystemBundleContext();
+
+      // Setup the LogEntryStore
+      LogEntryFilter filter = new LogEntryFilter("example-log(.*)", LogService.LOG_DEBUG, "BundleEvent(.*)");
+      final LogEntryCache logEntryStore = new LogEntryCache(filter);
+      
+      // Track the LogReaderService to add the LogEntryStore as LogListener
+      ServiceTracker tracker = new ServiceTracker(sysContext, LogReaderService.class.getName(), null)
+      {
+         @Override
+         public Object addingService(ServiceReference sref)
+         {
+            LogReaderService service = (LogReaderService)super.addingService(sref);
+            service.addLogListener(logEntryStore);
+            return service;
+         }
+      };
+      tracker.open();
+
+      // Install and start the 3rd party LogService.   
+      installBundle(sysContext, "thirdparty/org.apache.felix.log.jar", true);
+
+      // Install and start the test bundle
+      installBundle(sysContext, "example/example-log-bundleA.jar", true);
+
+      // Verify the received log entries
+      List<LogEntry> entries = logEntryStore.getLog();
+      assertEquals("Number of entries", 3, entries.size());
+      assertEquals("BundleEvent INSTALLED", entries.get(0).getMessage());
+      assertEquals("BundleEvent RESOLVED", entries.get(1).getMessage());
+      assertEquals("BundleEvent STARTED", entries.get(2).getMessage());
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/example/log/LogServiceTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/example/log/bundleA/ServiceA.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/example/log/bundleA/ServiceA.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/example/log/bundleA/ServiceA.java	2009-04-11 19:41:30 UTC (rev 87165)
@@ -0,0 +1,58 @@
+/*
+ * 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.test.osgi.example.log.bundleA;
+
+//$Id$
+
+import static org.osgi.service.log.LogService.LOG_INFO;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
+import org.osgi.util.tracker.ServiceTracker;
+
+/**
+ * A service that logs some messages to the LogService
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 11-Apr-2009
+ */
+public class ServiceA 
+{
+   private LogService log;
+   
+   public ServiceA(BundleContext context)
+   {
+      // Track changes in LogService registration
+      ServiceTracker tracker = new ServiceTracker(context, LogService.class.getName(), null)
+      {
+         @Override
+         public Object addingService(ServiceReference sref)
+         {
+            log = (LogService)super.addingService(sref);
+            log.log(sref, LOG_INFO, "LogService added - " + log.getClass().getName());
+            return log;
+         }
+      };
+      tracker.open();
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/example/log/bundleA/ServiceA.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/example/log/bundleA/ServiceActivator.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/example/log/bundleA/ServiceActivator.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/example/log/bundleA/ServiceActivator.java	2009-04-11 19:41:30 UTC (rev 87165)
@@ -0,0 +1,48 @@
+/*
+ * 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.test.osgi.example.log.bundleA;
+
+//$Id$
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+public class ServiceActivator implements BundleActivator
+{
+   private ServiceRegistration registration;
+
+   public void start(BundleContext context)
+   {
+      ServiceA service = new ServiceA(context);
+      registration = context.registerService(ServiceA.class.getName(), service, null);
+   }
+
+   public void stop(BundleContext context)
+   {
+      if (registration != null)
+      {
+         registration.unregister();
+         registration = null;
+      }
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/example/log/bundleA/ServiceActivator.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/service/microcontainer/bundle/MBeanTestService.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/service/microcontainer/bundle/MBeanTestService.java	2009-04-11 14:37:30 UTC (rev 87164)
+++ projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/service/microcontainer/bundle/MBeanTestService.java	2009-04-11 19:41:30 UTC (rev 87165)
@@ -26,7 +26,7 @@
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
 
-import org.jboss.osgi.service.MicrocontainerService;
+import org.jboss.osgi.service.mc.MicrocontainerService;
 import org.jboss.osgi.spi.management.ObjectNameFactory;
 import org.jboss.test.osgi.service.microcontainer.bundle.Foo;
 import org.osgi.framework.BundleContext;

Added: projects/jboss-osgi/trunk/testsuite/src/test/resources/example/log/example-log-bundleA.bnd
===================================================================
--- projects/jboss-osgi/trunk/testsuite/src/test/resources/example/log/example-log-bundleA.bnd	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/src/test/resources/example/log/example-log-bundleA.bnd	2009-04-11 19:41:30 UTC (rev 87165)
@@ -0,0 +1,6 @@
+# bnd build -classpath target/test-classes -output target/test-libs/example-log-bundleA.jar src/test/resources/example/log/example-log-bundleA.bnd
+
+Bundle-SymbolicName: example-log-bundleA
+
+Bundle-Activator: org.jboss.test.osgi.example.log.bundleA.ServiceActivator
+Export-Package: org.jboss.test.osgi.example.log.bundleA




More information about the jboss-cvs-commits mailing list