Author: donsez
Date: Mon Nov  5 06:23:57 2007
New Revision: 592008

URL: http://svn.apache.org/viewvc?rev=592008&view=rev
Log:
creation of a bundle event.convertor : this bundle converts 
org.osgi.service.event.Events according conversion rules in order to adapt them

Added:
    felix/sandbox/donsez/event.convertor/
    felix/sandbox/donsez/event.convertor/pom.xml   (with props)
    felix/sandbox/donsez/event.convertor/src/
    felix/sandbox/donsez/event.convertor/src/main/
    felix/sandbox/donsez/event.convertor/src/main/java/
    felix/sandbox/donsez/event.convertor/src/main/java/org/
    felix/sandbox/donsez/event.convertor/src/main/java/org/apache/
    felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/
    felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/
    
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/
    
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/
    
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/activator/
    
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/activator/Activator.java
   (with props)
    
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/
    
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/BasicMapConvertor.java
   (with props)
    
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/Convertor.java
   (with props)
    
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/EventConvertor.java
   (with props)
    
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/EventConvertorCommand.java
   (with props)
    
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/EventConvertorFactory.java
   (with props)
    
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/JSR223Convertor.java
   (with props)
    
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/URLEncodingUtil.java
   (with props)
    felix/sandbox/donsez/event.convertor/src/site/
    felix/sandbox/donsez/event.convertor/src/site/TODOLIST.txt   (with props)
    felix/sandbox/donsez/event.convertor/src/site/script.txt   (with props)

Added: felix/sandbox/donsez/event.convertor/pom.xml
URL: 
http://svn.apache.org/viewvc/felix/sandbox/donsez/event.convertor/pom.xml?rev=592008&view=auto
==============================================================================
--- felix/sandbox/donsez/event.convertor/pom.xml (added)
+++ felix/sandbox/donsez/event.convertor/pom.xml Mon Nov  5 06:23:57 2007
@@ -0,0 +1,101 @@
+<!--
+ 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>
+
+       <properties>
+               
<repositoryLocation>http://people.apache.org/~donsez/dev/felix/sandbox/</repositoryLocation>
+               <description>provides a simple service to convert 
events.</description>
+       </properties>  
+
+  <modelVersion>4.0.0</modelVersion>
+  <packaging>bundle</packaging>
+  <name>Event Convertor</name>
+  <artifactId>org.apache.felix.sandbox.event.convertor</artifactId>
+  <groupId>org.apache.felix.sandbox</groupId>
+  <version>0.1.0</version>
+  <description>${description}</description>
+
+  <dependencies>
+
+       <dependency>
+               <groupId>org.apache.felix</groupId>
+               <artifactId>org.osgi.core</artifactId>
+               <version>1.0.0</version>
+       </dependency>
+       
+       <dependency>
+               <groupId>org.apache.felix</groupId>
+               <artifactId>org.osgi.compendium</artifactId>
+               <version>0.9.0-SNAPSHOT</version>
+       </dependency>
+        
+       <dependency>
+               <groupId>org.apache.felix</groupId>
+               <artifactId>org.apache.felix.shell</artifactId>
+               <version>1.1.0-SNAPSHOT</version>
+       </dependency>
+
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+          
+               <!-- docs in 
http://cwiki.apache.org/FELIX/bundle-plugin-for-maven-bnd.html and 
http://cwiki.apache.org/FELIX/osgi-plugin-for-maven-2.html -->
+               
+            
<Private-Package>${pom.artifactId}.impl,${pom.artifactId}.activator</Private-Package>
+            <Import-Package>
+            org.osgi.framework,
+            org.osgi.util.tracker,
+            org.osgi.service.event,
+            org.apache.felix.shell
+            </Import-Package>
+
+            
<Bundle-Activator>${pom.artifactId}.activator.Activator</Bundle-Activator>
+
+            <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+            <Bundle-Description>${description}</Bundle-Description>
+
+          </instructions>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+<!--
+  <repositories>
+    <repository>
+      <id>apache.m2.incubator</id>
+      <name>Apache M2 Incubator Repository</name>
+      <url>http://people.apache.org/repo/m2-incubating-repository/</url>
+    </repository>
+  </repositories>
+  <pluginRepositories>
+    <pluginRepository>
+      <id>apache.m2.incubator</id>
+      <name>Apache M2 Incubator Repository</name>
+      <url>http://people.apache.org/repo/m2-incubating-repository/</url>
+    </pluginRepository>
+  </pluginRepositories>
+  -->
+</project>

Propchange: felix/sandbox/donsez/event.convertor/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/activator/Activator.java
URL: 
http://svn.apache.org/viewvc/felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/activator/Activator.java?rev=592008&view=auto
==============================================================================
--- 
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/activator/Activator.java
 (added)
+++ 
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/activator/Activator.java
 Mon Nov  5 06:23:57 2007
@@ -0,0 +1,61 @@
+/*
+ * 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.sandbox.event.convertor.activator;
+
+import java.lang.reflect.Constructor;
+
+import org.apache.felix.sandbox.event.convertor.impl.EventConvertorFactory;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+/**
+ * this class provides the activator.
+ * @author <a href="mailto:[EMAIL PROTECTED]">Felix Project Team</a>
+ */
+
+public class Activator implements BundleActivator {
+
+       BundleActivator eventConvertorFactory;
+       BundleActivator eventconvertorcommand;
+
+       
+       public void start(BundleContext bundleContext) throws Exception {
+               eventConvertorFactory=new EventConvertorFactory();              
+               eventConvertorFactory.start(bundleContext);
+               
+               try {
+                       // Command is instanciated only if the Felix shell is 
available
+                       Class 
clazz=this.getClass().getClassLoader().loadClass("org.apache.felix.sandbox.event.convertor.impl.EventConvertorCommand");
+                       Constructor constructor=clazz.getConstructor(new 
Class[]{EventConvertorFactory.class});
+                       eventconvertorcommand=(BundleActivator) 
constructor.newInstance(new Object[] {eventConvertorFactory } );
+                       eventconvertorcommand.start(bundleContext);
+               } catch (ClassNotFoundException e) {
+                       // silently do nothing
+                       System.err.println(e);
+               }
+       }
+
+       
+       
+       public void stop(BundleContext bundleContext) throws Exception {
+               if(eventconvertorcommand!=null) 
eventconvertorcommand.stop(bundleContext);
+               eventConvertorFactory.stop(bundleContext);
+       }
+       
+}

Propchange: 
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/activator/Activator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/BasicMapConvertor.java
URL: 
http://svn.apache.org/viewvc/felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/BasicMapConvertor.java?rev=592008&view=auto
==============================================================================
--- 
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/BasicMapConvertor.java
 (added)
+++ 
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/BasicMapConvertor.java
 Mon Nov  5 06:23:57 2007
@@ -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.sandbox.event.convertor.impl;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.osgi.service.event.Event;
+
+/**
+ * this class provides a very simple event convertor which only changes the 
properties names in the input event.
+ * 
+ * @author <a href="mailto:[EMAIL PROTECTED]">Felix Project Team</a>
+ */
+public class BasicMapConvertor implements Convertor {
+       
+       private Map convertionMap;
+
+       private String topicIn;
+
+       private String topicOut;
+       
+       public BasicMapConvertor(String topicIn, String topicOut, Map 
convertionMap) {
+               this.topicIn=topicIn;
+               this.topicOut=topicOut;
+               this.convertionMap = convertionMap;
+       }       
+       
+       /**
+        * convert a event according to the convertion rules
+        * @param eventIn the event to convert
+        * @return the result event of the conversion or null if the conversion 
fails
+        */
+       public Event convert(Event eventIn) {
+               Dictionary dictionary = new Hashtable();
+               
+               for (Iterator iterator = convertionMap.keySet().iterator(); 
iterator.hasNext();) {
+                       String keyOut = (String) iterator.next();               
        
+                       String keyIn = (String)convertionMap.get(keyOut);
+                       Object propertyInValue=eventIn.getProperty(keyIn);
+                       if(propertyInValue==null) continue;
+                       dictionary.put(keyOut, propertyInValue);
+               }
+               
+               Event eventOut = new Event(topicOut, dictionary);
+               return eventOut;
+       }
+}

Propchange: 
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/BasicMapConvertor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/Convertor.java
URL: 
http://svn.apache.org/viewvc/felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/Convertor.java?rev=592008&view=auto
==============================================================================
--- 
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/Convertor.java
 (added)
+++ 
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/Convertor.java
 Mon Nov  5 06:23:57 2007
@@ -0,0 +1,36 @@
+/*
+ * 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.sandbox.event.convertor.impl;
+
+import org.osgi.service.event.Event;
+
+/**
+ * this interface provides a event convertor contract.
+ * 
+ * @author <a href="mailto:[EMAIL PROTECTED]">Felix Project Team</a>
+ */
+public interface Convertor {
+       /**
+        * convert a event according to the convertion rules
+        * @param eventIn the event to convert
+        * @return the result event of the conversion or null if the conversion 
fails
+        */
+       public Event convert(Event eventIn);
+}

Propchange: 
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/Convertor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/EventConvertor.java
URL: 
http://svn.apache.org/viewvc/felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/EventConvertor.java?rev=592008&view=auto
==============================================================================
--- 
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/EventConvertor.java
 (added)
+++ 
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/EventConvertor.java
 Mon Nov  5 06:23:57 2007
@@ -0,0 +1,88 @@
+/*
+ * 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.sandbox.event.convertor.impl;
+
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventAdmin;
+import org.osgi.service.event.EventConstants;
+import org.osgi.service.event.EventHandler;
+import org.osgi.util.tracker.ServiceTracker;
+
+/**
+ * this class subscribes to event topics, converts them and then send the 
converted events.
+ * 
+ * @author <a href="mailto:[EMAIL PROTECTED]">Felix Project Team</a>
+ */
+public class EventConvertor implements BundleActivator, EventHandler {
+
+       private Convertor convertor;
+
+       private ServiceTracker serviceTracker;
+
+       private ServiceRegistration serviceRegistration;
+
+       private String topicIn;
+       
+       private boolean trace=true;
+
+       private String bundleSymbolicName;
+       
+       public EventConvertor(String topicIn, String topicOut, Map 
convertionMap, ServiceTracker serviceTracker) {
+               this.topicIn=topicIn;
+               this.convertor = new 
BasicMapConvertor(topicIn,topicOut,convertionMap);
+               this.serviceTracker = serviceTracker;
+       }
+
+       public void start(BundleContext bundleContext) throws Exception {
+               Dictionary properties=new Hashtable();
+               properties.put(EventConstants.EVENT_TOPIC, new String[]{ 
topicIn });            
+               
serviceRegistration=bundleContext.registerService(EventHandler.class.getName(), 
this, properties);
+               
+               // for trace purpose
+               bundleSymbolicName=bundleContext.getBundle().getSymbolicName();
+       }
+
+       public void stop(BundleContext bundleContext) throws Exception {
+               serviceTracker = null;
+               serviceRegistration.unregister();
+       }
+
+       public void handleEvent(Event eventIn) {
+               if (serviceTracker == null)
+                       return;
+               EventAdmin eventAdmin = ((EventAdmin) 
serviceTracker.getService());
+               if (eventAdmin == null)
+                       return;
+               
+               Event eventOut = convertor.convert(eventIn);
+               if(eventOut==null) return;
+               eventAdmin.sendEvent(eventOut); // synchronous delivery
+               if(trace) System.out.println(bundleSymbolicName+"convert 
"+eventIn+ " -> "+eventOut);
+       }       
+}
\ No newline at end of file

Propchange: 
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/EventConvertor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/EventConvertorCommand.java
URL: 
http://svn.apache.org/viewvc/felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/EventConvertorCommand.java?rev=592008&view=auto
==============================================================================
--- 
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/EventConvertorCommand.java
 (added)
+++ 
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/EventConvertorCommand.java
 Mon Nov  5 06:23:57 2007
@@ -0,0 +1,143 @@
+/*
+ * 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.sandbox.event.convertor.impl;
+
+import java.io.PrintStream;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import org.apache.felix.shell.Command;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * this class provides a shell command to handle event convertors.
+ * @author <a href="mailto:[EMAIL PROTECTED]">Felix Project Team</a>
+ */
+
+public class EventConvertorCommand implements BundleActivator, Command {
+
+       private EventConvertorFactory eventConvertorFactory;
+
+       public EventConvertorCommand(EventConvertorFactory factoryActivator) {
+               this.eventConvertorFactory=factoryActivator;
+       }
+       
+       ServiceRegistration serviceRegistration=null;
+       
+       /**
+        * @see 
org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+        */
+       public void start(BundleContext bundleContext) throws Exception {
+               
serviceRegistration=bundleContext.registerService(Command.class.getName(), 
this, null);
+       }
+
+       /**
+        * @see 
org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+        */
+       public void stop(BundleContext bundleContext) throws Exception {
+               serviceRegistration.unregister();
+       }
+
+       /**
+        * @see org.apache.felix.shell.Command#execute(java.lang.String, 
java.io.PrintStream, java.io.PrintStream)
+        */
+       public void execute(String cmdline, PrintStream out, PrintStream err) {
+               StringTokenizer st=new StringTokenizer(cmdline, " ");
+               int n=st.countTokens();
+
+               if(n<2) {
+                       err.println(getFullUsage());
+                       return;
+               }
+               
+               st.nextToken(); // skip eventconvertorcommand name
+               
+               
+               String subcommand=st.nextToken();
+               n-=2;
+               
+               if("add".equals(subcommand) && n==3){
+                       String topicIn=st.nextToken();
+                       String topicOut=st.nextToken();
+                       String encodedConvertionMap=st.nextToken();
+                       
+                       eventConvertorFactory.add(topicIn, 
topicOut,URLEncodingUtil.decode(encodedConvertionMap));
+
+               } else if("remove".equals(subcommand) && n==2){
+                       String topicIn=st.nextToken();
+                       String topicOut=st.nextToken();
+                       eventConvertorFactory.remove(topicIn, topicOut);
+
+               } else if("convertors".equals(subcommand) && n==0){
+                       Set keys=eventConvertorFactory.getConvertors();
+                       if(keys==null) {
+                               out.println("no convertor");                    
        
+                               return;
+                       }
+                       for (Iterator iterator = keys.iterator(); 
iterator.hasNext();) {
+                               String key = (String) iterator.next();
+                               out.println(key);
+                       }
+
+               } else if("trace".equals(subcommand) && n==1){
+                       String trace=st.nextToken();
+                       eventConvertorFactory.setTrace("on".equals(trace));
+
+               } else {
+                       err.println(getFullUsage());
+                       return;
+               }
+       }
+
+       /**
+        * @see org.apache.felix.shell.Command#getName()
+        */
+       public String getName() {
+               return "eventconvertor";
+       }
+       
+       /**
+        * @see org.apache.felix.shell.Command#getShortDescription()
+        */
+       public String getShortDescription() {
+               return "command to add/remove event convertors";
+       }
+
+       /**
+        * @see org.apache.felix.shell.Command#getUsage()
+        */
+       public String getUsage() {
+               return  getName() + " [help]";
+       }       
+
+       /**
+        * @see org.apache.felix.shell.Command#getUsage()
+        */
+       public String getFullUsage() {
+               return
+                "\n"+  getName() + " add <topicIn> <topicOut> <convertion 
map>: add a convertor ((map is a set of url-encoded pair values)"
+               +"\n"+  getName() + " remove <topicIn> <topicOut>: remove a 
convertor"
+               +"\n"+  getName() + " convertors: list the actice convertors"
+               +"\n"+  getName() + " trace <on|off> : set on|off the trace"
+               ;
+       }       
+}

Propchange: 
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/EventConvertorCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/EventConvertorFactory.java
URL: 
http://svn.apache.org/viewvc/felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/EventConvertorFactory.java?rev=592008&view=auto
==============================================================================
--- 
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/EventConvertorFactory.java
 (added)
+++ 
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/EventConvertorFactory.java
 Mon Nov  5 06:23:57 2007
@@ -0,0 +1,123 @@
+/*
+ * 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.sandbox.event.convertor.impl;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.event.EventAdmin;
+import org.osgi.util.tracker.ServiceTracker;
+
+/**
+ * this class provides a factory to start and stop event convertors.
+ * @author <a href="mailto:[EMAIL PROTECTED]">Felix Project Team</a>
+ */
+public class EventConvertorFactory implements BundleActivator {
+
+       private ServiceTracker serviceTracker;
+       private boolean trace;
+       private Map eventConvertors;
+       private BundleContext bundleContext;
+       
+       public void start(BundleContext bundleContext) throws Exception {
+               this.bundleContext=bundleContext;
+               serviceTracker=new 
ServiceTracker(bundleContext,EventAdmin.class.getName(),null);
+               serviceTracker.open();
+               eventConvertors=new HashMap();
+       }
+
+       public void stop(BundleContext bundleContext) throws Exception {
+               for (Iterator iterator = eventConvertors.values().iterator(); 
iterator.hasNext();) {
+                       EventConvertor eventConvertor = (EventConvertor) 
iterator.next();
+                       try {
+                               eventConvertor.stop(bundleContext);
+                       } catch (Exception e) {
+                       }
+               }
+               eventConvertors=null;
+               
+               serviceTracker.close();
+       }
+
+       /**
+        * start a event convertor
+        * @param topicIn
+        * @param topicOut
+        * @param convertionMap
+        */
+       public void add(String topicIn, String topicOut, Map convertionMap) {
+               
+               String key=topicIn+"->"+topicOut;
+               
+               remove(key);
+               
+               EventConvertor eventConvertor= new EventConvertor(topicIn, 
topicOut, convertionMap,serviceTracker);
+               
+               try {
+                       eventConvertor.start(bundleContext);
+                       eventConvertors.put(key, eventConvertor);
+               } catch (Exception e) {
+               }               
+       }
+
+       /**
+        * stop and remove a event convertor
+        * @param key
+        */
+       private void remove(String key) {
+               EventConvertor eventConvertor=(EventConvertor) 
eventConvertors.remove(key);
+               if(eventConvertor!=null){
+                       try {
+                               eventConvertor.stop(bundleContext);
+                       } catch (Exception e) {
+                       }
+               }
+       }
+       
+       /**
+        * stop and remove a event convertor
+        * @param topicIn
+        * @param topicOut
+        */
+       public void remove(String topicIn, String topicOut) {
+               remove(topicIn+"->"+topicOut);
+       }
+
+       /**
+        * get the active convertors
+        * @return
+        */
+       public Set getConvertors() {
+               return eventConvertors.keySet();        
+       }
+
+       /**
+        * 
+        * @param trace
+        */
+       public void setTrace(boolean trace) {
+               this.trace=trace;
+       }
+       
+}

Propchange: 
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/EventConvertorFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/JSR223Convertor.java
URL: 
http://svn.apache.org/viewvc/felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/JSR223Convertor.java?rev=592008&view=auto
==============================================================================
--- 
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/JSR223Convertor.java
 (added)
+++ 
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/JSR223Convertor.java
 Mon Nov  5 06:23:57 2007
@@ -0,0 +1,62 @@
+/*
+ * 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.sandbox.event.convertor.impl;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.osgi.service.event.Event;
+
+/**
+ * this class provides a event convertor using a script to set the properties.
+ * 
+ * @author <a href="mailto:[EMAIL PROTECTED]">Felix Project Team</a>
+ */
+public class JSR223Convertor implements Convertor {
+       
+       private String language;
+       
+       private String scriptText;
+       
+       private String topicIn;
+
+       private String topicOut;
+       
+       public JSR223Convertor(String topicIn, String topicOut, String 
language, String scriptText) {
+               this.topicIn=topicIn;
+               this.topicOut=topicOut;
+               this.language = language;
+               this.scriptText = scriptText;
+       }       
+       
+       /**
+        * convert a event according to the convertion rules
+        * @param eventIn the event to convert
+        * @return the result event of the conversion or null if the conversion 
fails
+        */
+       public Event convert(Event eventIn) {
+               Dictionary dictionary = new Hashtable();
+               
+               // TODO run the script to fill up the dictionary
+               
+               Event eventOut = new Event(topicOut, dictionary);
+               return eventOut;
+       }
+}

Propchange: 
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/JSR223Convertor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/URLEncodingUtil.java
URL: 
http://svn.apache.org/viewvc/felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/URLEncodingUtil.java?rev=592008&view=auto
==============================================================================
--- 
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/URLEncodingUtil.java
 (added)
+++ 
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/URLEncodingUtil.java
 Mon Nov  5 06:23:57 2007
@@ -0,0 +1,70 @@
+/*
+ * 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.sandbox.event.convertor.impl;
+
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+/**
+ * this class provides a utility to decode/encode url encoded parameters 
to/from map.
+ * @author <a href="mailto:[EMAIL PROTECTED]">Felix Project Team</a>
+ */
+public class URLEncodingUtil {
+
+       public static String encode(Map map) {
+               String urlstring=null;
+               boolean first=true;
+               if (map != null) {
+
+                       for (Iterator iterator = map.keySet().iterator(); 
iterator.hasNext();) {
+                               Object key = iterator.next();
+                               Object value = map.get(key);
+                               if(first) { urlstring=""; first=false; } else { 
urlstring+='&'; }
+                               urlstring +=  URLEncoder.encode(key.toString()) 
+ '=' + URLEncoder.encode(value.toString());
+                       }
+               }
+               return urlstring;
+       }
+
+       /**
+        * TODO decode multi valued properties
+        * @param urlstring
+        * @return a map
+        */
+       public static Map decode(String urlstring) {
+               Map map=new HashMap();
+               StringTokenizer st=new StringTokenizer(urlstring,"&");
+               while(st.hasMoreTokens()){
+                       String pair=st.nextToken();
+                       StringTokenizer st2=new StringTokenizer(pair,"=");
+                       if (st2.hasMoreTokens()) {
+                               String name=st2.nextToken();
+                               String value="";
+                               if(st2.hasMoreTokens()) value=st2.nextToken();
+                               
map.put(URLDecoder.decode(name),URLDecoder.decode(value));
+                       }
+               }
+               
+               return map;
+       }       
+}

Propchange: 
felix/sandbox/donsez/event.convertor/src/main/java/org/apache/felix/sandbox/event/convertor/impl/URLEncodingUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/event.convertor/src/site/TODOLIST.txt
URL: 
http://svn.apache.org/viewvc/felix/sandbox/donsez/event.convertor/src/site/TODOLIST.txt?rev=592008&view=auto
==============================================================================
--- felix/sandbox/donsez/event.convertor/src/site/TODOLIST.txt (added)
+++ felix/sandbox/donsez/event.convertor/src/site/TODOLIST.txt Mon Nov  5 
06:23:57 2007
@@ -0,0 +1,2 @@
+1) add more complex event convertors (javascript-based, message format like, 
...)
+ 
\ No newline at end of file

Propchange: felix/sandbox/donsez/event.convertor/src/site/TODOLIST.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/event.convertor/src/site/script.txt
URL: 
http://svn.apache.org/viewvc/felix/sandbox/donsez/event.convertor/src/site/script.txt?rev=592008&view=auto
==============================================================================
--- felix/sandbox/donsez/event.convertor/src/site/script.txt (added)
+++ felix/sandbox/donsez/event.convertor/src/site/script.txt Mon Nov  5 
06:23:57 2007
@@ -0,0 +1,9 @@
+
+obr start "Apache Felix Event Admin"
+start mvn:org.apache.felix/org.apache.felix.eventadmin
+start mvn:org.apache.felix.sandbox/org.apache.felix.sandbox.eventadmin.cmd
+start mvn:org.apache.felix.sandbox/org.apache.felix.sandbox.event.convertor
+
+eventadmin subscribe org/apache/felix/sandbox/bunny
+eventconvertor blogs/* org/apache/felix/sandbox/bunny tts=title
+eventadmin send blogs/felixdev title=Felix+is+an+open+source+platform

Propchange: felix/sandbox/donsez/event.convertor/src/site/script.txt
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to