#1607 - Refactored version of the event console plugin

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@818455 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole-plugins/event/LICENSE b/webconsole-plugins/event/LICENSE
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/webconsole-plugins/event/LICENSE
@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
diff --git a/webconsole-plugins/event/NOTICE b/webconsole-plugins/event/NOTICE
new file mode 100644
index 0000000..e829dee
--- /dev/null
+++ b/webconsole-plugins/event/NOTICE
@@ -0,0 +1,26 @@
+Apache Felix OSGi Web Console Event Plugin
+Copyright 2007-2009 The Apache Software Foundation
+
+
+I. Included Software
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+Licensed under the Apache License 2.0.
+
+This product includes software from http://www.json.org.
+Copyright (c) 2002 JSON.org
+Licensed under the JSON License
+
+
+II. Used Software
+
+This product uses software developed at
+The OSGi Alliance (http://www.osgi.org/).
+Copyright (c) OSGi Alliance (2000, 2009).
+Licensed under the Apache License 2.0.
+
+
+III. License Summary
+- Apache License 2.0
+- JSON License
diff --git a/webconsole-plugins/event/pom.xml b/webconsole-plugins/event/pom.xml
new file mode 100644
index 0000000..328ec08
--- /dev/null
+++ b/webconsole-plugins/event/pom.xml
@@ -0,0 +1,114 @@
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+    
+    http://www.apache.org/licenses/LICENSE-2.0
+    
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+-->
+<project 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/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>felix-parent</artifactId>
+        <version>1.2.0</version>
+        <relativePath>../../../pom/pom.xml</relativePath>
+    </parent>
+
+    <artifactId>org.apache.felix.webconsole.plugins.event</artifactId>
+    <packaging>bundle</packaging>
+    <version>0.9.0-SNAPSHOT</version>
+
+    <name>Apache Felix Web Console Event Plugin</name>
+    <description>
+        This is a plugin for the Apache Felxi OSGi web console for displaying
+        OSGi events.
+    </description>
+
+    <scm>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/felix/trunk/webconsole-plugins/event</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/felix/trunk/webconsole-plugins/event</developerConnection>
+        <url>http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/event</url>
+    </scm>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <version>1.4.3</version>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Bundle-SymbolicName>
+                            ${artifactId}
+                        </Bundle-SymbolicName>
+                        <Bundle-Vendor>
+                            The Apache Software Foundation
+                        </Bundle-Vendor>
+                        <Bundle-Activator>
+                            org.apache.felix.webconsole.plugins.event.internal.Activator
+                        </Bundle-Activator>
+                        <Private-Package>
+                            org.apache.felix.webconsole.plugins.event.*,
+                        </Private-Package>
+                        <Import-Package>
+                            !org.osgi.service.event,
+                            !org.osgi.service.cm,
+                            *
+                        </Import-Package>
+                        <Embed-Dependency>
+                            <!-- Required for JSON data transfer -->
+                            json
+                        </Embed-Dependency>
+                        <DynamicImport-Package>
+                            org.osgi.service.event, 
+                            org.osgi.service.cm
+                        </DynamicImport-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+            <version>2.4</version>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <version>4.0.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+            <version>4.0.0</version>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.json</groupId>
+            <artifactId>json</artifactId>
+            <version>20070829</version>
+            <scope>compile</scope>
+            <optional>true</optional>
+        </dependency>
+    </dependencies>
+</project>
diff --git a/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/Activator.java b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/Activator.java
new file mode 100644
index 0000000..bd6a3e0
--- /dev/null
+++ b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/Activator.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.felix.webconsole.plugins.event.internal;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import javax.servlet.Servlet;
+
+import org.osgi.framework.*;
+
+/**
+ * Setup the event plugin
+ */
+public class Activator implements BundleActivator
+{
+    /** Registration for the plugin. */
+    private ServiceRegistration pluginRegistration;
+
+    /** Listener */
+    private EventListener eventListener;
+
+    /** The plugin. */
+    private PluginServlet plugin;
+
+    /** Optional features handler. */
+    private OptionalFeaturesHandler featuresHandler;
+
+    /**
+     * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+     */
+    public void start(final BundleContext context) throws Exception
+    {
+        // we start with the plugin
+        this.plugin = new PluginServlet();
+
+        // now we create the listener
+        this.eventListener = new EventListener(this.plugin, context);
+
+        // and the optional features handler
+        this.featuresHandler = new OptionalFeaturesHandler(this.plugin, context);
+
+        // finally we register the plugin
+        final Dictionary props = new Hashtable();
+        props.put( Constants.SERVICE_DESCRIPTION, "Event plugin for the Apache Felix Web Console" );
+        props.put( Constants.SERVICE_VENDOR, "The Apache Software Foundation" );
+        props.put( "felix.webconsole.label", "events");
+        props.put( "felix.webconsole.title", "Events");
+        this.pluginRegistration = context.registerService(Servlet.class.getName(),
+                                plugin,
+                                props);
+    }
+
+    /**
+     * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+     */
+    public void stop(final BundleContext context) throws Exception
+    {
+        if ( this.pluginRegistration != null )
+        {
+            this.pluginRegistration.unregister();
+            this.pluginRegistration = null;
+        }
+        if ( this.eventListener != null )
+        {
+            this.eventListener.destroy();
+            eventListener = null;
+        }
+        if ( this.featuresHandler != null)
+        {
+            this.featuresHandler.destroy();
+            this.featuresHandler = null;
+        }
+        if ( this.plugin != null ) {
+            this.plugin.destroy();
+            this.plugin = null;
+        }
+    }
+
+}
diff --git a/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/ConfigurationListener.java b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/ConfigurationListener.java
new file mode 100644
index 0000000..e07e6d1
--- /dev/null
+++ b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/ConfigurationListener.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.webconsole.plugins.event.internal;
+
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.osgi.framework.*;
+import org.osgi.service.cm.ManagedService;
+
+
+public class ConfigurationListener implements ManagedService
+{
+    private final PluginServlet plugin;
+
+    private final String pid;
+
+    static ServiceRegistration create( final BundleContext context, final PluginServlet plugin )
+    {
+        ConfigurationListener cl = new ConfigurationListener( plugin );
+
+        Dictionary props = new Hashtable();
+        props.put( Constants.SERVICE_VENDOR, "The Apache Software Foundation" );
+        props.put( Constants.SERVICE_DESCRIPTION, "Event plugin for the Felix Web Console Configuration Receiver" );
+        props.put( Constants.SERVICE_PID, cl.pid );
+
+        return context.registerService( ManagedService.class.getName(), cl, props );
+    }
+
+
+    private ConfigurationListener( PluginServlet plugin )
+    {
+        this.plugin = plugin;
+        this.pid = plugin.getClass().getName();
+    }
+
+    //---------- ManagedService
+
+    public void updated( Dictionary config )
+    {
+        plugin.updateConfiguration( config );
+    }
+}
\ No newline at end of file
diff --git a/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventCollector.java b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventCollector.java
new file mode 100644
index 0000000..3d81fd4
--- /dev/null
+++ b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventCollector.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.felix.webconsole.plugins.event.internal;
+
+import java.util.*;
+
+/**
+ * This class collects events
+ */
+public class EventCollector
+{
+
+    private static final String PROPERTY_MAX_SIZE = "max.size";
+    private static final int DEFAULT_MAX_SIZE = 250;
+
+    private List eventInfos = new ArrayList();
+
+    private int maxSize;
+
+    public EventCollector(final Dictionary props)
+    {
+        updateConfiguration(props);
+    }
+
+    public void add(final EventInfo info)
+    {
+        if ( info != null )
+        {
+            synchronized ( this.eventInfos )
+            {
+                this.eventInfos.add( info );
+                if ( eventInfos.size() > this.maxSize )
+                {
+                    eventInfos.remove( 0 );
+                }
+            }
+        }
+    }
+
+    public void clear()
+    {
+        synchronized ( this.eventInfos )
+        {
+            this.eventInfos = new ArrayList();
+        }
+    }
+
+    /**
+     * Return a copy of the current event list
+     */
+    public List getEvents()
+    {
+        synchronized ( this.eventInfos )
+        {
+            return new ArrayList(eventInfos);
+        }
+    }
+
+    public void updateConfiguration( final Dictionary props)
+    {
+        this.maxSize = OsgiUtil.toInteger(props, PROPERTY_MAX_SIZE, DEFAULT_MAX_SIZE);
+        synchronized ( this.eventInfos ) {
+            while ( eventInfos.size() > this.maxSize )
+            {
+                eventInfos.remove( 0 );
+            }
+
+        }
+    }
+}
diff --git a/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventHandler.java b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventHandler.java
new file mode 100644
index 0000000..ec611bf
--- /dev/null
+++ b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventHandler.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.felix.webconsole.plugins.event.internal;
+
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.felix.webconsole.plugins.event.internal.converter.*;
+import org.osgi.service.event.Event;
+
+/**
+ * Event listener for the OSGi event admin, listening
+ * to all events.
+ */
+public class EventHandler implements org.osgi.service.event.EventHandler
+{
+    /** A list of topics that are always excluded, there is no way to change this
+     * via configuration.
+     * This list includes the framework events that are already covered by the
+     * event listener and all log events.
+     */
+    private final String[] excludeTopics = new String[] {"org/osgi/service/log",
+            BundleEventConverter.TOPIC,
+            FrameworkEventConverter.TOPIC,
+            ServiceEventConverter.TOPIC};
+
+    private final EventCollector collector;
+
+    public EventHandler(final EventCollector c)
+    {
+        this.collector = c;
+    }
+
+    /**
+     * @see org.osgi.service.event.EventHandler#handleEvent(org.osgi.service.event.Event)
+     */
+    public void handleEvent( Event event )
+    {
+        boolean include = true;
+        for(int i=0; i<excludeTopics.length; i++)
+        {
+            if ( event.getTopic().startsWith(excludeTopics[i]))
+            {
+                include = false;
+                break;
+            }
+        }
+        if ( include )
+        {
+            Map props = null;
+            final String[] names = event.getPropertyNames();
+            if ( names != null && names.length > 0 )
+            {
+                props = new HashMap();
+                for ( int i = 0; i < names.length; i++ )
+                {
+                    props.put(names[i], event.getProperty(names[i]));
+                }
+            }
+            collector.add(new EventInfo(event.getTopic(), null, props));
+        }
+    }
+}
diff --git a/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventInfo.java b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventInfo.java
new file mode 100644
index 0000000..8eb75ef
--- /dev/null
+++ b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventInfo.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.felix.webconsole.plugins.event.internal;
+
+import java.util.Map;
+
+/**
+ * An event as displayed in the console.
+ * The console displays the time {@link #received},
+ * the {@link #topic} and if available the {@link #info}.
+ * If the info is not available, the {@link #properties}
+ * are displayed instead.
+ */
+public class EventInfo {
+
+    /** The event topic. */
+    public final String topic;
+
+    /** Additional information for this event. */
+    public final String info;
+
+    /** The time this event has been received. */
+    public final long received;
+
+    /** Properties. */
+    public final Map properties;
+
+    public EventInfo( final String topic, final String info )
+    {
+        this.topic = topic;
+        this.info = info;
+        this.received = System.currentTimeMillis();
+        this.properties = null;
+    }
+
+    public EventInfo( final String topic, final String info, final Map props )
+    {
+        this.topic = topic;
+        this.info = info;
+        this.received = System.currentTimeMillis();
+        this.properties = props;
+    }
+}
diff --git a/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventListener.java b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventListener.java
new file mode 100644
index 0000000..283f702
--- /dev/null
+++ b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventListener.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.felix.webconsole.plugins.event.internal;
+
+import org.apache.felix.webconsole.plugins.event.internal.converter.*;
+import org.osgi.framework.*;
+
+/**
+ * This class listens for all known framework events:
+ * - bundle events
+ * - framework events
+ * - service events
+ */
+public class EventListener
+    implements BundleListener, FrameworkListener, ServiceListener{
+
+    private final EventCollector collector;
+
+    private final BundleContext bundleContext;
+
+    public EventListener(final PluginServlet plugin, final BundleContext context)
+    {
+        this.collector = plugin.getCollector();
+        this.bundleContext = context;
+        context.addBundleListener(this);
+        context.addFrameworkListener(this);
+        context.addServiceListener(this);
+    }
+
+    public void destroy()
+    {
+        this.bundleContext.removeBundleListener(this);
+        this.bundleContext.removeFrameworkListener(this);
+        this.bundleContext.removeServiceListener(this);
+    }
+
+    /**
+     * @see org.osgi.framework.ServiceListener#serviceChanged(org.osgi.framework.ServiceEvent)
+     */
+    public void serviceChanged(ServiceEvent event)
+    {
+        final EventInfo info = ServiceEventConverter.getInfo(event);
+        this.collector.add(info);
+    }
+
+    /**
+     * @see org.osgi.framework.FrameworkListener#frameworkEvent(org.osgi.framework.FrameworkEvent)
+     */
+    public void frameworkEvent(FrameworkEvent event)
+    {
+        final EventInfo info = FrameworkEventConverter.getInfo(event);
+        this.collector.add(info);
+    }
+
+    /**
+     * @see org.osgi.framework.BundleListener#bundleChanged(org.osgi.framework.BundleEvent)
+     */
+    public void bundleChanged(BundleEvent event)
+    {
+        final EventInfo info = BundleEventConverter.getInfo(event);
+        this.collector.add(info);
+    }
+}
diff --git a/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/OptionalFeaturesHandler.java b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/OptionalFeaturesHandler.java
new file mode 100644
index 0000000..0de3a6c
--- /dev/null
+++ b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/OptionalFeaturesHandler.java
@@ -0,0 +1,185 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.felix.webconsole.plugins.event.internal;
+
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.osgi.framework.*;
+
+/**
+ * This class handles all optional stuff.
+ * It listens for specific services and activates/deactivates
+ * features.
+ */
+public class OptionalFeaturesHandler
+    implements ServiceListener
+{
+    private static final String EVENT_ADMIN_CLASS_NAME = "org.osgi.service.event.EventAdmin";
+    private static final String CONFIGURATION_ADMIN_CLASS_NAME = "org.osgi.service.cm.ConfigurationAdmin";
+    private static final String EVENT_HANDLER_CLASS_NAME = "org.osgi.service.event.EventHandler";
+
+    private static final String FILTER = "(|(" + Constants.OBJECTCLASS + "=" + EVENT_ADMIN_CLASS_NAME + ")"
+                                        +"(" + Constants.OBJECTCLASS + "=" + CONFIGURATION_ADMIN_CLASS_NAME + "))";
+
+    /** Event admin service reference */
+    private ServiceReference eventAdminReference;
+
+    /** Registration for the event handler. */
+    private ServiceRegistration eventHandlerRegistration;
+
+    /** Configuration admin service reference */
+    private ServiceReference configAdminReference;
+
+    /** Registration for the configuration listener. */
+    private ServiceRegistration configListenerRegistration;
+
+    /** Bundle context. */
+    private final BundleContext bundleContext;
+
+    /** The plugin */
+    private final PluginServlet plugin;
+
+    public OptionalFeaturesHandler(final PluginServlet plugin, final BundleContext context)
+    {
+        this.plugin = plugin;
+        this.bundleContext = context;
+        // check if event admin is already available
+        this.eventAdminReference = null;
+        final ServiceReference ref = this.bundleContext.getServiceReference(EVENT_ADMIN_CLASS_NAME);
+        if ( ref != null )
+        {
+            bindEventAdmin(ref);
+        }
+
+        // check if config admin is already available
+        this.configAdminReference = null;
+        final ServiceReference cfaRef = this.bundleContext.getServiceReference(CONFIGURATION_ADMIN_CLASS_NAME);
+        if ( cfaRef != null )
+        {
+            bindConfigAdmin(cfaRef);
+        }
+
+        // listen for event and config admin from now on
+        try {
+            context.addServiceListener(this, FILTER);
+        } catch (InvalidSyntaxException ise) {
+            // this should never happen as this is a constant, so we ignore it
+        }
+    }
+
+    /**
+     * @see javax.servlet.GenericServlet#destroy()
+     */
+    public void destroy()
+    {
+        this.bundleContext.removeServiceListener(this);
+        this.unbindEventAdmin(this.eventAdminReference);
+        this.unbindConfigAdmin(this.configAdminReference);
+    }
+
+    /**
+     * @see org.osgi.framework.ServiceListener#serviceChanged(org.osgi.framework.ServiceEvent)
+     */
+    public void serviceChanged(final ServiceEvent event)
+    {
+        final String[] objectClasses =  (String[])event.getServiceReference().getProperty(Constants.OBJECTCLASS);
+        if ( objectClasses != null)
+        {
+            for(int i=0; i<objectClasses.length; i++)
+            {
+                if ( objectClasses[i].equals(EVENT_ADMIN_CLASS_NAME) )
+                {
+                    if ( event.getType() == ServiceEvent.REGISTERED )
+                    {
+                        this.bindEventAdmin(event.getServiceReference());
+                    }
+                    else if ( event.getType() == ServiceEvent.UNREGISTERING )
+                    {
+                        this.unbindEventAdmin(event.getServiceReference());
+                    }
+                }
+                else if ( objectClasses[i].equals(CONFIGURATION_ADMIN_CLASS_NAME) )
+                {
+                    if ( event.getType() == ServiceEvent.REGISTERED )
+                    {
+                        this.bindConfigAdmin(event.getServiceReference());
+                    }
+                    else if ( event.getType() == ServiceEvent.UNREGISTERING )
+                    {
+                        this.unbindConfigAdmin(event.getServiceReference());
+                    }
+                }
+            }
+        }
+    }
+
+    private void bindEventAdmin(final ServiceReference ref)
+    {
+        if ( this.eventAdminReference != null)
+        {
+            this.unbindEventAdmin(this.eventAdminReference);
+        }
+        this.eventAdminReference = ref;
+        final Dictionary props = new Hashtable();
+        props.put( Constants.SERVICE_DESCRIPTION, "Event handler for the Apache Felix Web Console" );
+        props.put( Constants.SERVICE_VENDOR, "The Apache Software Foundation" );
+        props.put( "event.topics", "*");
+        this.plugin.setEventAdminAvailable(true);
+
+        this.eventHandlerRegistration = this.bundleContext.registerService(EVENT_HANDLER_CLASS_NAME,
+                new EventHandler(this.plugin.getCollector()), props);
+    }
+
+    private void unbindEventAdmin(final ServiceReference ref)
+    {
+        if ( this.eventAdminReference == ref )
+        {
+            this.eventAdminReference = null;
+            this.plugin.setEventAdminAvailable(false);
+            if ( this.eventHandlerRegistration != null )
+            {
+                this.eventHandlerRegistration.unregister();
+                this.eventHandlerRegistration = null;
+            }
+        }
+    }
+
+    private void bindConfigAdmin(final ServiceReference ref)
+    {
+        if ( this.configAdminReference != null )
+        {
+            this.unbindConfigAdmin(this.configAdminReference);
+        }
+        this.configAdminReference = ref;
+        this.configListenerRegistration = ConfigurationListener.create(this.bundleContext, this.plugin);
+    }
+
+    private void unbindConfigAdmin(final ServiceReference ref)
+    {
+        if ( this.configAdminReference == ref )
+        {
+            this.configAdminReference = null;
+            if ( this.configListenerRegistration != null )
+            {
+                this.configListenerRegistration.unregister();
+                this.configListenerRegistration = null;
+            }
+        }
+    }
+}
diff --git a/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/OsgiUtil.java b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/OsgiUtil.java
new file mode 100644
index 0000000..3abac87
--- /dev/null
+++ b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/OsgiUtil.java
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.webconsole.plugins.event.internal;
+
+import java.util.*;
+
+/**
+ * The <code>OsgiUtil</code> is a utility class providing some usefull utility
+ * methods.
+ */
+public class OsgiUtil {
+
+    public static boolean toBoolean(Dictionary props, String key, boolean defaultValue)
+    {
+        Object propValue = toObject( props, key );
+        if (propValue instanceof Boolean)
+        {
+            return ((Boolean) propValue).booleanValue();
+        }
+        else if (propValue != null)
+        {
+            return Boolean.valueOf(String.valueOf(propValue)).booleanValue();
+        }
+
+        return defaultValue;
+    }
+
+    public static String toString(Dictionary props, String key, String defaultValue)
+    {
+        Object propValue = toObject( props, key );
+        return (propValue != null) ? propValue.toString() : defaultValue;
+    }
+
+    public static int toInteger(Dictionary props, String key, int defaultValue)
+    {
+        Object propValue = toObject( props, key );
+        if (propValue instanceof Integer)
+        {
+            return ((Integer) propValue).intValue();
+        }
+        else if (propValue != null)
+        {
+            try
+            {
+                return Integer.valueOf(String.valueOf(propValue)).intValue();
+            }
+            catch (NumberFormatException nfe)
+            {
+                // don't care, fall through to default value
+            }
+        }
+
+        return defaultValue;
+    }
+
+    public static Object toObject(Dictionary props, String key)
+    {
+        if (props == null || key == null )
+        {
+            return null;
+        }
+        final Object propValue = props.get(key);
+        if ( propValue == null )
+        {
+            return null;
+        }
+        else if (propValue.getClass().isArray())
+        {
+            Object[] prop = (Object[]) propValue;
+            return prop.length > 0 ? prop[0] : null;
+        }
+        else if (propValue instanceof Collection)
+        {
+            Collection prop = (Collection) propValue;
+            return prop.isEmpty() ? null : prop.iterator().next();
+        }
+        else
+        {
+            return propValue;
+        }
+    }
+
+    public static String[] toStringArray(Dictionary props, String key, String[] defaultArray)
+    {
+        if (props == null || key == null )
+        {
+            return defaultArray;
+        }
+        final Object propValue = props.get(key);
+        if (propValue == null)
+        {
+            // no value at all
+            return defaultArray;
+
+        }
+        else if (propValue instanceof String)
+        {
+            // single string
+            return new String[] { (String) propValue };
+
+        }
+        else if (propValue instanceof String[])
+        {
+            // String[]
+            return (String[]) propValue;
+
+        }
+        else if (propValue.getClass().isArray())
+        {
+            // other array
+            Object[] valueArray = (Object[]) propValue;
+            List values = new ArrayList(valueArray.length);
+            for(int i=0; i<valueArray.length; i++)
+            {
+                final Object value = valueArray[i];
+                if (value != null)
+                {
+                    values.add(value.toString());
+                }
+            }
+            return (String[]) values.toArray(new String[values.size()]);
+
+        }
+        else if (propValue instanceof Collection)
+        {
+            // collection
+            Collection valueCollection = (Collection) propValue;
+            List valueList = new ArrayList(valueCollection.size());
+            final Iterator i = valueCollection.iterator();
+            while ( i.hasNext() )
+            {
+                final Object value = i.next();
+                if (value != null)
+                {
+                    valueList.add(value.toString());
+                }
+            }
+            return (String[]) valueList.toArray(new String[valueList.size()]);
+        }
+
+        return defaultArray;
+    }
+}
diff --git a/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/PluginServlet.java b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/PluginServlet.java
new file mode 100644
index 0000000..220d0b4
--- /dev/null
+++ b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/PluginServlet.java
@@ -0,0 +1,236 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.felix.webconsole.plugins.event.internal;
+
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.*;
+import java.util.Map.Entry;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.*;
+
+import org.json.JSONException;
+import org.json.JSONWriter;
+
+/**
+ * The Event Plugin
+ */
+public class PluginServlet extends HttpServlet
+{
+    private static final String ACTION_CLEAR = "clear";
+
+    private static final String PARAMETER_ACTION = "action";
+
+    /** The event collector. */
+    private final EventCollector collector;
+
+    /** Is the event admin available? */
+    private boolean eventAdminAvailable = false;
+
+    /** Is the config admin available? */
+    private boolean configAdminAvailable = false;
+
+    public PluginServlet()
+    {
+        this.collector = new EventCollector(null);
+    }
+
+    /**
+     * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+     */
+    protected void doPost( HttpServletRequest req, HttpServletResponse resp )
+    throws ServletException, IOException
+    {
+        final String action = req.getParameter( PARAMETER_ACTION );
+        // for now we only have the clear action
+        if ( ACTION_CLEAR.equals( action ) )
+        {
+            this.collector.clear();
+        }
+        // we always send back the json data
+        resp.setContentType( "application/json" );
+        resp.setCharacterEncoding( "utf-8" );
+
+        renderJSON( resp.getWriter() );
+    }
+
+    private void renderJSON( final PrintWriter pw ) throws IOException
+    {
+        List events = this.collector.getEvents();
+
+        StringBuffer statusLine = new StringBuffer();
+        if ( this.eventAdminAvailable )
+        {
+            statusLine.append("Event Admin service is available. ");
+        }
+        else
+        {
+            statusLine.append("Event Admin service is not available. ");
+        }
+        statusLine.append( events.size() );
+        statusLine.append( " Event");
+        if ( events.size() != 1 )
+        {
+            statusLine.append('s');
+        }
+        statusLine.append( " received" );
+        if ( !events.isEmpty() )
+        {
+            statusLine.append( " since " );
+            Date d = new Date();
+            d.setTime( ( ( EventInfo ) events.get( 0 ) ).received );
+            statusLine.append( d );
+        }
+        statusLine.append( "." );
+
+        JSONWriter jw = new JSONWriter( pw );
+        try
+        {
+            jw.object();
+
+            jw.key( "status" );
+            jw.value( statusLine );
+
+            jw.key( "data" );
+
+            jw.array();
+
+            // display list in reverse order
+            for ( int index = events.size() - 1; index >= 0; index-- )
+            {
+                eventJson( jw, ( EventInfo ) events.get( index ), index );
+            }
+
+            jw.endArray();
+
+            jw.endObject();
+
+        }
+        catch ( JSONException je )
+        {
+            throw new IOException( je.toString() );
+        }
+
+    }
+
+
+    protected void doGet( HttpServletRequest request, HttpServletResponse response )
+    throws ServletException, IOException
+    {
+
+        final String info = request.getPathInfo();
+        if ( info.endsWith( ".json" ) )
+        {
+            response.setContentType( "application/json" );
+            response.setCharacterEncoding( "UTF-8" );
+
+            PrintWriter pw = response.getWriter();
+            this.renderJSON( pw );
+
+            // nothing more to do
+            return;
+        }
+
+        this.renderContent( request, response );
+    }
+
+
+    protected void renderContent( HttpServletRequest request, HttpServletResponse response )
+    throws ServletException, IOException
+    {
+        final PrintWriter pw = response.getWriter();
+
+        final String appRoot = ( String ) request.getAttribute( "felix.webconsole.appRoot" );
+        pw.println( "<script src='" + appRoot + "/res/ui/" + "events.js" + "' language='JavaScript'></script>" );
+
+        pw.println( "<div id='plugin_content'/>");
+
+        pw.println( "<script type='text/javascript'>" );
+        pw.println( "// <![CDATA[" );
+        pw.println( "renderEvents( );" );
+        pw.println( "// ]]>" );
+        pw.println( "</script>" );
+    }
+
+
+    private void eventJson( JSONWriter jw, EventInfo info, int index ) throws JSONException
+    {
+        jw.object();
+        jw.key( "id" );
+        jw.value( String.valueOf( index ) );
+        jw.key( "received" );
+        jw.value( info.received );
+        jw.key( "topic" );
+        jw.value( info.topic );
+        if ( info.info != null )
+        {
+            jw.key( "info" );
+            jw.value( info.info );
+        }
+        jw.key( "properties" );
+        jw.object();
+        if ( info.properties != null && info.properties.size() > 0 )
+        {
+            final Iterator i = info.properties.entrySet().iterator();
+            while ( i.hasNext() )
+            {
+                final Map.Entry current = (Entry) i.next();
+                jw.key( current.getKey().toString() );
+                final Object value = current.getValue();
+                if ( value.getClass().isArray() )
+                {
+                    // as we can't use 1.5 functionality we have to print the array ourselves
+                    Object[] arr = (Object[])value;
+                    final StringBuffer b = new StringBuffer("[");
+                    for(int m=0; m<arr.length; m++) {
+                        if ( m > 0 )
+                        {
+                            b.append(", ");
+                        }
+                        b.append(arr[m].toString());
+                    }
+                    b.append(']');
+                    jw.value(b.toString());
+                }
+                else
+                {
+                    jw.value(value.toString());
+                }
+            }
+        }
+        jw.endObject();
+
+        jw.endObject();
+    }
+
+    public void updateConfiguration( Dictionary dict)
+    {
+        this.collector.updateConfiguration(dict);
+    }
+
+    public EventCollector getCollector()
+    {
+        return this.collector;
+    }
+
+    public void setEventAdminAvailable(final boolean flag)
+    {
+        this.eventAdminAvailable = flag;
+    }
+}
diff --git a/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/BundleEventConverter.java b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/BundleEventConverter.java
new file mode 100644
index 0000000..ac2eb80
--- /dev/null
+++ b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/BundleEventConverter.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.felix.webconsole.plugins.event.internal.converter;
+
+import org.apache.felix.webconsole.plugins.event.internal.EventInfo;
+import org.osgi.framework.BundleEvent;
+
+public class BundleEventConverter {
+
+    public static final String TOPIC = BundleEvent.class.getName().replace('.', '/');
+
+    public static EventInfo getInfo(final BundleEvent event) {
+        if ( event == null )
+        {
+            return null;
+        }
+        final StringBuffer topic = new StringBuffer(TOPIC);
+        topic.append('/');
+        final StringBuffer buffer = new StringBuffer( "Bundle " );
+        buffer.append( event.getBundle().getSymbolicName() );
+        buffer.append( ' ' );
+        switch ( event.getType() )
+        {
+            case BundleEvent.INSTALLED:
+                buffer.append( "installed" );
+                topic.append("INSTALLED");
+                break;
+            case BundleEvent.RESOLVED:
+                buffer.append( "resolved" );
+                topic.append("RESOLVED");
+                break;
+            case BundleEvent.STARTED:
+                buffer.append( "started" );
+                topic.append("STARTED");
+                break;
+            case BundleEvent.STARTING:
+                buffer.append( "starting" );
+                topic.append("STARTED");
+                break;
+            case BundleEvent.STOPPED:
+                buffer.append( "stopped" );
+                topic.append("INSSTARTEDTALLED");
+                break;
+            case BundleEvent.STOPPING:
+                buffer.append( "stopping" );
+                topic.append("STOPPING");
+                break;
+            case BundleEvent.UNINSTALLED:
+                buffer.append( "uninstalled" );
+                topic.append("UNINSTALLED");
+                break;
+            case BundleEvent.UNRESOLVED:
+                buffer.append( "unresolved" );
+                topic.append("UNINSTALLED");
+                break;
+            case BundleEvent.UPDATED:
+                buffer.append( "updated" );
+                topic.append("UPDATED");
+                break;
+            default:
+                return null; // IGNORE
+        }
+
+        return new EventInfo(topic.toString(), buffer.toString());
+    }
+}
diff --git a/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/FrameworkEventConverter.java b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/FrameworkEventConverter.java
new file mode 100644
index 0000000..52f99b4
--- /dev/null
+++ b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/FrameworkEventConverter.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.felix.webconsole.plugins.event.internal.converter;
+
+import org.apache.felix.webconsole.plugins.event.internal.EventInfo;
+import org.osgi.framework.FrameworkEvent;
+
+public class FrameworkEventConverter {
+
+    public static final String TOPIC = FrameworkEvent.class.getName().replace('.', '/');
+
+    public static EventInfo getInfo(final FrameworkEvent event) {
+        if ( event == null )
+        {
+            return null;
+        }
+
+        final StringBuffer topic = new StringBuffer(TOPIC);
+        topic.append('/');
+        final StringBuffer buffer = new StringBuffer( "Framework event " );
+        switch ( event.getType() )
+        {
+            case FrameworkEvent.ERROR:
+                buffer.append( "error" );
+                topic.append( "ERROR" );
+                break;
+            case FrameworkEvent.INFO:
+                buffer.append( "info" );
+                topic.append( "INFO" );
+                break;
+            case FrameworkEvent.PACKAGES_REFRESHED:
+                buffer.append( "packages refreshed" );
+                topic.append( "PACKAGES_REFRESHED" );
+                break;
+            case FrameworkEvent.STARTED:
+                buffer.append( "started" );
+                topic.append( "STARTED" );
+                break;
+            case FrameworkEvent.STARTLEVEL_CHANGED:
+                buffer.append( "start level changed" );
+                topic.append( "STARTLEVEL_CHANGED" );
+                break;
+            case FrameworkEvent.WARNING:
+                buffer.append( "warning" );
+                topic.append( "WARNING" );
+                break;
+            default:
+                return null; // IGNORE
+        }
+
+        return new EventInfo(topic.toString(), buffer.toString());
+    }
+}
diff --git a/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/ServiceEventConverter.java b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/ServiceEventConverter.java
new file mode 100644
index 0000000..5b40b0a
--- /dev/null
+++ b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/ServiceEventConverter.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.felix.webconsole.plugins.event.internal.converter;
+
+import org.apache.felix.webconsole.plugins.event.internal.EventInfo;
+import org.osgi.framework.*;
+
+public class ServiceEventConverter {
+
+    public static final String TOPIC = ServiceEvent.class.getName().replace('.', '/');
+
+    public static EventInfo getInfo(final ServiceEvent event) {
+        if ( event == null )
+        {
+            return null;
+        }
+
+        final ServiceReference ref = event.getServiceReference();
+
+        final StringBuffer buffer = new StringBuffer( "Service " );
+        final Object pid = ref.getProperty( Constants.SERVICE_PID );
+        if ( pid != null)
+        {
+            buffer.append( pid );
+        }
+        buffer.append( "(id=" );
+        buffer.append( ref.getProperty( Constants.SERVICE_ID ) );
+
+        final String[] arr = (String[]) ref.getProperty( Constants.OBJECTCLASS );
+        if ( arr != null )
+        {
+            buffer.append(", objectClass=");
+            if ( arr.length > 1 )
+            {
+                buffer.append('[');
+            }
+            for(int m = 0; m <arr.length; m++)
+            {
+                if ( m > 0 )
+                {
+                    buffer.append(", ");
+                }
+                buffer.append(arr[m].toString());
+            }
+            if ( arr.length > 1 )
+            {
+                buffer.append(']');
+            }
+        }
+        buffer.append( ", bundle=" );
+        buffer.append( ref.getBundle().getSymbolicName() );
+        buffer.append( ") " );
+        final StringBuffer topic = new StringBuffer(TOPIC);
+        topic.append('/');
+        switch ( event.getType() )
+        {
+            case ServiceEvent.REGISTERED:
+                buffer.append( "registered" );
+                topic.append("REGISTERED");
+                break;
+            case ServiceEvent.MODIFIED:
+                buffer.append( "modified" );
+                topic.append("MODIFIED");
+                break;
+            case ServiceEvent.UNREGISTERING:
+                buffer.append( "unregistering" );
+                topic.append("UNREGISTERING");
+                break;
+            default:
+                return null; // IGNORE
+        }
+
+        return new EventInfo(topic.toString(), buffer.toString());
+    }
+}
diff --git a/webconsole-plugins/event/src/main/resources/OSGI-INF/metatype/metatype.properties b/webconsole-plugins/event/src/main/resources/OSGI-INF/metatype/metatype.properties
new file mode 100644
index 0000000..7883600
--- /dev/null
+++ b/webconsole-plugins/event/src/main/resources/OSGI-INF/metatype/metatype.properties
@@ -0,0 +1,25 @@
+#
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing,
+#  software distributed under the License is distributed on an
+#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+#  specific language governing permissions and limitations
+#  under the License.
+#
+
+plugin.name = Apache Felix Web Console Event Plugin
+plugin.description = This is a plugin for the Apache Felix Web Console \
+ displaying all events occuring in the system.
+
+max.size.name = Maximum Events
+max.size.description = The maximum number of events displayed in the plugin.
diff --git a/webconsole-plugins/event/src/main/resources/OSGI-INF/metatype/metatype.xml b/webconsole-plugins/event/src/main/resources/OSGI-INF/metatype/metatype.xml
new file mode 100644
index 0000000..39b7f20
--- /dev/null
+++ b/webconsole-plugins/event/src/main/resources/OSGI-INF/metatype/metatype.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<metatype:MetaData xmlns:metatype="http://www.osgi.org/xmlns/metatype/v1.0.0" localization="OSGI-INF/metatype/metatype">
+    <OCD id="org.apache.felix.webconsole.plugins.event.internal.PluginServlet" name="%plugin.name" description="%plugin.description">
+        <AD id="max.size" type="Integer" default="250" name="%max.size.name" description="%max.size.description"/>
+    </OCD>
+    <Designate pid="org.apache.felix.webconsole.plugins.event.internal.PluginServlet">
+        <Object ocdref="org.apache.felix.webconsole.plugins.event.internal.PluginServlet"/>
+    </Designate>
+</metatype:MetaData>
diff --git a/webconsole-plugins/event/src/main/resources/res/ui/events.js b/webconsole-plugins/event/src/main/resources/res/ui/events.js
new file mode 100644
index 0000000..2d043af
--- /dev/null
+++ b/webconsole-plugins/event/src/main/resources/res/ui/events.js
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+function renderStatusLine() {
+	$("#plugin_content").append( "<div class='fullwidth'><div class='statusline'/></div>" );
+}
+
+function renderView( /* Array of String */ columns, /* String */ buttons ) {
+    renderStatusLine();
+    renderButtons(buttons);
+    var txt = "<div class='table'><table id='plugin_table' class='tablelayout'><thead><tr>";
+    for ( var name in columns ) {
+    	txt = txt + "<th class='col_" + columns[name] + "'>" + columns[name] + "</th>";
+    }
+    txt = txt + "</tr></thead><tbody></tbody></table></div>";
+    $("#plugin_content").append( txt );
+    renderButtons(buttons);
+    renderStatusLine();	
+}
+
+function renderButtons( buttons ) {
+	$("#plugin_content").append( "<form method='post' enctype='multipart/form-data'><div class='fullwidth'><div class='buttons'>" +
+	                             buttons + "</div></div></form>" );
+}
+
+function renderData( eventData )  {
+	$(".statusline").empty().append(eventData.status);
+	$("#plugin_table > tbody > tr").remove();	
+    for ( var idx in eventData.data ) {
+        entry( eventData.data[idx] );
+    }
+    $("#plugin_table").trigger("update");
+}
+
+function entry( /* Object */ dataEntry ) {
+    var trElement = tr( null, { id: "entry" + dataEntry.id } );
+    entryInternal( trElement,  dataEntry );
+	$("#plugin_table > tbody").append(trElement);	
+}
+
+
+function entryInternal( /* Element */ parent, /* Object */ dataEntry ) {
+    var id = dataEntry.id;
+    var topic = dataEntry.topic;
+    var properties = dataEntry.properties;
+
+    parent.appendChild( td( null, null, [ text( printDate(dataEntry.received) ) ] ) );
+    parent.appendChild( td( null, null, [ text( topic ) ] ) );
+
+    var propE;
+    if ( dataEntry.info ) {
+    	propE = text(dataEntry.info);
+    } else {
+	    var tableE = createElement("table");
+	    var bodyE = createElement("tbody");
+	    tableE.appendChild(bodyE);
+	
+	    for( var p in dataEntry.properties ) {
+	    	var c1 = td(null, null, [text(p)]);
+	    	$(c1).css("border", "0px none");
+            $(c1).css("padding", "0 4px 0 0");
+	    	var c2 = td(null, null, [text(dataEntry.properties[p])]);
+	    	$(c2).css("border", "0px none");
+            $(c2).css("padding", "0 0 0 4px");
+	    	bodyE.appendChild(tr(null, null, [ c1, c2 ]));
+	    }
+	    propE = tableE;
+    }
+    
+    parent.appendChild( td( null, null, [propE] ) );
+}
+
+/* displays a date in the user's local timezone */
+function printDate(time) {
+    var date = time ? new Date(time) : new Date();
+    return date.toLocaleString();
+}
+
+function loadData() {
+	$.get(pluginRoot + "/data.json", null, function(data) {
+	    renderData(data);
+	}, "json");	
+}
+
+function renderEvents() {
+	$(document).ready(function(){
+	    renderView( ["Received", "Topic", "Properties"],
+	    		 "<button class='clearButton' type='button' name='clear'>Clear List</button>" +
+	    		 "<button class='reloadButton' type='button' name='reload'>Reload</button>");
+	    loadData();
+	    
+	    $("#plugin_table").tablesorter();
+	    $(".reloadButton").click(loadData);
+	    $(".clearButton").click(function () {
+	    	$("#plugin_table > tbody > tr").remove();
+	    	$.post(pluginRoot, { "action":"clear" }, function(data) {
+	    	    renderData(data);
+	    	}, "json");
+	    });
+	});
+}