felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject svn commit: r416927 - in /incubator/felix/trunk/org.apache.felix.eventadmin.bridge.wireadmin: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/felix/ src/main/java/org/apache/felix/eventadmin/ src/m...
Date Sat, 24 Jun 2006 15:06:56 GMT
Author: pauls
Date: Sat Jun 24 08:06:56 2006
New Revision: 416927

URL: http://svn.apache.org/viewvc?rev=416927&view=rev
Log:
Implement mappings from WireAdminEvents (FELIX-86)

Added:
    incubator/felix/trunk/org.apache.felix.eventadmin.bridge.wireadmin/   (with props)
    incubator/felix/trunk/org.apache.felix.eventadmin.bridge.wireadmin/pom.xml   (with props)
    incubator/felix/trunk/org.apache.felix.eventadmin.bridge.wireadmin/src/
    incubator/felix/trunk/org.apache.felix.eventadmin.bridge.wireadmin/src/main/
    incubator/felix/trunk/org.apache.felix.eventadmin.bridge.wireadmin/src/main/java/
    incubator/felix/trunk/org.apache.felix.eventadmin.bridge.wireadmin/src/main/java/org/
    incubator/felix/trunk/org.apache.felix.eventadmin.bridge.wireadmin/src/main/java/org/apache/
    incubator/felix/trunk/org.apache.felix.eventadmin.bridge.wireadmin/src/main/java/org/apache/felix/
    incubator/felix/trunk/org.apache.felix.eventadmin.bridge.wireadmin/src/main/java/org/apache/felix/eventadmin/
    incubator/felix/trunk/org.apache.felix.eventadmin.bridge.wireadmin/src/main/java/org/apache/felix/eventadmin/bridge/
    incubator/felix/trunk/org.apache.felix.eventadmin.bridge.wireadmin/src/main/java/org/apache/felix/eventadmin/bridge/wireadmin/
    incubator/felix/trunk/org.apache.felix.eventadmin.bridge.wireadmin/src/main/java/org/apache/felix/eventadmin/bridge/wireadmin/Activator.java
  (with props)
    incubator/felix/trunk/org.apache.felix.eventadmin.bridge.wireadmin/src/main/java/org/apache/felix/eventadmin/bridge/wireadmin/WireAdminEventToEventAdminBridge.java
  (with props)

Propchange: incubator/felix/trunk/org.apache.felix.eventadmin.bridge.wireadmin/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Jun 24 08:06:56 2006
@@ -0,0 +1,16 @@
+classes
+target
+*.log
+*.ipr
+*.iws
+*.iml
+lib
+bundle
+dist
+.project
+.classpath
+bin
+build
+.settings
+.wtpmodules
+.deployables

Added: incubator/felix/trunk/org.apache.felix.eventadmin.bridge.wireadmin/pom.xml
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.eventadmin.bridge.wireadmin/pom.xml?rev=416927&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.eventadmin.bridge.wireadmin/pom.xml (added)
+++ incubator/felix/trunk/org.apache.felix.eventadmin.bridge.wireadmin/pom.xml Sat Jun 24
08:06:56 2006
@@ -0,0 +1,46 @@
+<project>
+  <parent>
+    <groupId>org.apache.felix</groupId>
+    <artifactId>felix</artifactId>
+    <version>0.8.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <packaging>osgi-bundle</packaging>
+  <name>Apache Felix EventAdmin Bridge WireAdmin</name>
+  <artifactId>org.apache.felix.eventadmin.bridge.wireadmin</artifactId>
+  <dependencies>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>org.osgi.core</artifactId>
+      <version>${pom.version}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>org.osgi.compendium</artifactId>
+      <version>${pom.version}</version>
+      <scope>provided</scope>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix.plugins</groupId>
+        <artifactId>maven-osgi-plugin</artifactId>
+        <version>${pom.version}</version>
+        <extensions>true</extensions>
+        <configuration>
+          <osgiManifest>
+            <bundleName>EventAdmin Bridge WireAdmin</bundleName>
+            <bundleVendor>Apache Software Foundation</bundleVendor>
+            <bundleDescription>
+              This bundle provides a bridge between WireAdmin and EventAdmin events.
+            </bundleDescription>
+            <bundleActivator>auto-detect</bundleActivator>
+            <bundleSymbolicName>${pom.artifactId}</bundleSymbolicName>
+          </osgiManifest>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: incubator/felix/trunk/org.apache.felix.eventadmin.bridge.wireadmin/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/trunk/org.apache.felix.eventadmin.bridge.wireadmin/src/main/java/org/apache/felix/eventadmin/bridge/wireadmin/Activator.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.eventadmin.bridge.wireadmin/src/main/java/org/apache/felix/eventadmin/bridge/wireadmin/Activator.java?rev=416927&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.eventadmin.bridge.wireadmin/src/main/java/org/apache/felix/eventadmin/bridge/wireadmin/Activator.java
(added)
+++ incubator/felix/trunk/org.apache.felix.eventadmin.bridge.wireadmin/src/main/java/org/apache/felix/eventadmin/bridge/wireadmin/Activator.java
Sat Jun 24 08:06:56 2006
@@ -0,0 +1,53 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   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.
+ *
+ */
+package org.apache.felix.eventadmin.bridge.wireadmin;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The BundleActivator that will register an WireAdminEventListener service with the 
+ * framework on start. Subsequently, WireAdminEvents will be bridged to available 
+ * EventAdmin services (as per spec).
+ * 
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ */
+public class Activator implements BundleActivator
+{
+    /**
+     * This registers an WireAdminEventListener service with the framework that bridges 
+     * WireAdminEvents to the EventAdmin.
+     * 
+     * @param context The context to use
+     * 
+     * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+     */
+    public void start(final BundleContext context) throws Exception
+    {
+        new WireAdminEventToEventAdminBridge(context);
+    }
+
+    /**
+     * Stop the bridging of WireAdminEvents to the EventAdmin.
+     * 
+     * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+     */
+    public void stop(final BundleContext context) throws Exception
+    {
+        // Services are unregistered by the framework
+    }
+}

Propchange: incubator/felix/trunk/org.apache.felix.eventadmin.bridge.wireadmin/src/main/java/org/apache/felix/eventadmin/bridge/wireadmin/Activator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/trunk/org.apache.felix.eventadmin.bridge.wireadmin/src/main/java/org/apache/felix/eventadmin/bridge/wireadmin/WireAdminEventToEventAdminBridge.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.eventadmin.bridge.wireadmin/src/main/java/org/apache/felix/eventadmin/bridge/wireadmin/WireAdminEventToEventAdminBridge.java?rev=416927&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.eventadmin.bridge.wireadmin/src/main/java/org/apache/felix/eventadmin/bridge/wireadmin/WireAdminEventToEventAdminBridge.java
(added)
+++ incubator/felix/trunk/org.apache.felix.eventadmin.bridge.wireadmin/src/main/java/org/apache/felix/eventadmin/bridge/wireadmin/WireAdminEventToEventAdminBridge.java
Sat Jun 24 08:06:56 2006
@@ -0,0 +1,162 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   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.
+ *
+ */
+package org.apache.felix.eventadmin.bridge.wireadmin;
+
+import java.util.Arrays;
+import java.util.Hashtable;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventAdmin;
+import org.osgi.service.event.EventConstants;
+import org.osgi.service.wireadmin.WireAdmin;
+import org.osgi.service.wireadmin.WireAdminEvent;
+import org.osgi.service.wireadmin.WireAdminListener;
+
+/**
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ */
+public class WireAdminEventToEventAdminBridge implements WireAdminListener
+{
+    private final BundleContext m_context;
+
+    public WireAdminEventToEventAdminBridge(final BundleContext context)
+    {
+        m_context = context;
+
+        m_context
+            .registerService(WireAdminListener.class.getName(), this, null);
+    }
+
+    public void wireAdminEvent(final WireAdminEvent event)
+    {
+        final ServiceReference ref = m_context
+            .getServiceReference(EventAdmin.class.getName());
+
+        if(null != ref)
+        {
+            final EventAdmin eventAdmin = (EventAdmin) m_context
+                .getService(ref);
+
+            if(null != eventAdmin)
+            {
+                final String topic;
+
+                switch(event.getType())
+                {
+                    case WireAdminEvent.WIRE_CREATED:
+                        topic = "org/osgi/service/wireadmin/WireAdminEvent/WIRE_CREATED";
+                        break;
+                    case WireAdminEvent.WIRE_CONNECTED:
+                        topic = "org/osgi/service/wireadmin/WireAdminEvent/WIRE_CONNECTED";
+                        break;
+                    case WireAdminEvent.WIRE_UPDATED:
+                        topic = "org/osgi/service/wireadmin/WireAdminEvent/WIRE_UPDATED";
+                        break;
+                    case WireAdminEvent.WIRE_TRACE:
+                        topic = "org/osgi/service/wireadmin/WireAdminEvent/WIRE_TRACE";
+                        break;
+                    case WireAdminEvent.WIRE_DISCONNECTED:
+                        topic = "org/osgi/service/wireadmin/WireAdminEvent/WIRE_DISCONNECTED";
+                        break;
+                    case WireAdminEvent.WIRE_DELETED:
+                        topic = "org/osgi/service/wireadmin/WireAdminEvent/WIRE_DELETED";
+                        break;
+                    case WireAdminEvent.PRODUCER_EXCEPTION:
+                        topic = "org/osgi/service/wireadmin/WireAdminEvent/PRODUCER_EXCEPTION";
+                        break;
+                    case WireAdminEvent.CONSUMER_EXCEPTION:
+                        topic = "org/osgi/service/wireadmin/WireAdminEvent/CONSUMER_EXCEPTION";
+                        break;
+                    default:
+                        m_context.ungetService(ref);
+                        return;
+                }
+
+                eventAdmin.postEvent(new Event(topic, new Hashtable()
+                {
+                    {
+                        put(EventConstants.EVENT, event);
+
+                        put("wire", event.getWire());
+
+                        put("wire.flavors", event.getWire().getFlavors());
+
+                        put("wire.scope", event.getWire().getScope());
+
+                        put("wire.connected", Boolean.valueOf(event.getWire()
+                            .isConnected()));
+
+                        put("wire.valid", Boolean.valueOf(event.getWire()
+                            .isValid()));
+
+                        final Throwable throwable = event.getThrowable();
+
+                        if(null != throwable)
+                        {
+                            put(EventConstants.EXCEPTION, throwable);
+
+                            put(EventConstants.EXCEPTION_CLASS, throwable
+                                .getClass().getName());
+
+                            final String message = throwable.getMessage();
+
+                            if(null != message)
+                            {
+                                put(EventConstants.EXCEPTION_MESSAGE, message);
+                            }
+
+                            final ServiceReference ref = event
+                                .getServiceReference();
+
+                            if(null == ref)
+                            {
+                                throw new IllegalArgumentException(
+                                    "WireAdminEvent.getServiceReference() may not be null");
+                            }
+
+                            put(EventConstants.SERVICE, ref);
+
+                            put(EventConstants.SERVICE_ID, ref
+                                .getProperty(EventConstants.SERVICE_ID));
+
+                            final Object objectClass = ref
+                                .getProperty(Constants.OBJECTCLASS);
+
+                            if(!(objectClass instanceof String[])
+                                || !Arrays.asList((String[]) objectClass)
+                                    .contains(WireAdmin.class.getName()))
+                            {
+                                throw new IllegalArgumentException(
+                                    "Bad objectclass: " + objectClass);
+                            }
+
+                            put(EventConstants.SERVICE_OBJECTCLASS, objectClass);
+
+                            put(EventConstants.SERVICE_PID, ref
+                                .getProperty(EventConstants.SERVICE_PID));
+                        }
+                    }
+                }));
+
+                m_context.ungetService(ref);
+            }
+        }
+    }
+}

Propchange: incubator/felix/trunk/org.apache.felix.eventadmin.bridge.wireadmin/src/main/java/org/apache/felix/eventadmin/bridge/wireadmin/WireAdminEventToEventAdminBridge.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message