felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clem...@apache.org
Subject svn commit: r607434 - in /felix/sandbox/clement/ipojo: ./ arch/src/main/java/org/apache/felix/ipojo/arch/ composite/ core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ event.admin.handler/ examples/ examples/juni4osgi/ examples/juni4os...
Date Sat, 29 Dec 2007 15:53:32 GMT
Author: clement
Date: Sat Dec 29 07:53:29 2007
New Revision: 607434

URL: http://svn.apache.org/viewvc?rev=607434&view=rev
Log:
Add the white board pattern handler aiming to simplify white board pattern implementation by automating binding (the tracking is based on a filter).
Add the extender pattern handler simplifying extender implementation by automating bundle detection.
Add an example using the extender handler. This example provides a way to create junit test suites in OSGi (with the ability to inject the bundle context). The bundle providing test suites are detected by an extender model (Test-Suite manifest entry).

Added:
    felix/sandbox/clement/ipojo/examples/   (with props)
    felix/sandbox/clement/ipojo/examples/juni4osgi/   (with props)
    felix/sandbox/clement/ipojo/examples/juni4osgi/metadata.xml
    felix/sandbox/clement/ipojo/examples/juni4osgi/pom.xml
    felix/sandbox/clement/ipojo/examples/juni4osgi/src/   (with props)
    felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/   (with props)
    felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/   (with props)
    felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/   (with props)
    felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/   (with props)
    felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/   (with props)
    felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/   (with props)
    felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/   (with props)
    felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/OSGiJunitRunner.java
    felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/OSGiTestCase.java
    felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/OSGiTestSuite.java
    felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/command/   (with props)
    felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/command/JunitCommand.java
    felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/impl/   (with props)
    felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/impl/JunitExtender.java
    felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/impl/ResultPrinter.java
    felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/   (with props)
    felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestOSGiTestCase.java
    felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestOSGiTestSuite.java
    felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestTestCase.java
    felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestTestSuite.java
    felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/resources/   (with props)
    felix/sandbox/clement/ipojo/extender.pattern.handler/   (with props)
    felix/sandbox/clement/ipojo/extender.pattern.handler/metadata.xml
    felix/sandbox/clement/ipojo/extender.pattern.handler/pom.xml
    felix/sandbox/clement/ipojo/extender.pattern.handler/src/
    felix/sandbox/clement/ipojo/extender.pattern.handler/src/main/
    felix/sandbox/clement/ipojo/extender.pattern.handler/src/main/java/
    felix/sandbox/clement/ipojo/extender.pattern.handler/src/main/java/org/
    felix/sandbox/clement/ipojo/extender.pattern.handler/src/main/java/org/apache/
    felix/sandbox/clement/ipojo/extender.pattern.handler/src/main/java/org/apache/felix/
    felix/sandbox/clement/ipojo/extender.pattern.handler/src/main/java/org/apache/felix/ipojo/
    felix/sandbox/clement/ipojo/extender.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/
    felix/sandbox/clement/ipojo/extender.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/extender/
    felix/sandbox/clement/ipojo/extender.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/extender/ExtenderManager.java
    felix/sandbox/clement/ipojo/extender.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/extender/ExtenderModelHandler.java
    felix/sandbox/clement/ipojo/extender.pattern.handler/src/main/resources/
    felix/sandbox/clement/ipojo/white.board.pattern.handler/   (with props)
    felix/sandbox/clement/ipojo/white.board.pattern.handler/metadata.xml
    felix/sandbox/clement/ipojo/white.board.pattern.handler/pom.xml
    felix/sandbox/clement/ipojo/white.board.pattern.handler/src/
    felix/sandbox/clement/ipojo/white.board.pattern.handler/src/main/
    felix/sandbox/clement/ipojo/white.board.pattern.handler/src/main/java/
    felix/sandbox/clement/ipojo/white.board.pattern.handler/src/main/java/org/
    felix/sandbox/clement/ipojo/white.board.pattern.handler/src/main/java/org/apache/
    felix/sandbox/clement/ipojo/white.board.pattern.handler/src/main/java/org/apache/felix/
    felix/sandbox/clement/ipojo/white.board.pattern.handler/src/main/java/org/apache/felix/ipojo/
    felix/sandbox/clement/ipojo/white.board.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/
    felix/sandbox/clement/ipojo/white.board.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/wbp/
    felix/sandbox/clement/ipojo/white.board.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/wbp/WhiteBoardManager.java
    felix/sandbox/clement/ipojo/white.board.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/wbp/WhiteBoardPatternHandler.java
    felix/sandbox/clement/ipojo/white.board.pattern.handler/src/main/resources/
Modified:
    felix/sandbox/clement/ipojo/arch/src/main/java/org/apache/felix/ipojo/arch/ArchCommandImpl.java
    felix/sandbox/clement/ipojo/composite/pom.xml
    felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java
    felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java
    felix/sandbox/clement/ipojo/event.admin.handler/pom.xml
    felix/sandbox/clement/ipojo/plugin/src/main/java/org/apache/felix/ipojo/plugin/ManipulatorMojo.java
    felix/sandbox/clement/ipojo/pom.xml

Modified: felix/sandbox/clement/ipojo/arch/src/main/java/org/apache/felix/ipojo/arch/ArchCommandImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/arch/src/main/java/org/apache/felix/ipojo/arch/ArchCommandImpl.java?rev=607434&r1=607433&r2=607434&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/arch/src/main/java/org/apache/felix/ipojo/arch/ArchCommandImpl.java (original)
+++ felix/sandbox/clement/ipojo/arch/src/main/java/org/apache/felix/ipojo/arch/ArchCommandImpl.java Sat Dec 29 07:53:29 2007
@@ -19,7 +19,10 @@
 package org.apache.felix.ipojo.arch;
 
 import java.io.PrintStream;
+import java.lang.reflect.Field;
+import java.util.List;
 
+import org.apache.felix.ipojo.AbstractFactory;
 import org.apache.felix.ipojo.ComponentInstance;
 import org.apache.felix.ipojo.Factory;
 import org.apache.felix.ipojo.HandlerFactory;
@@ -113,10 +116,29 @@
             printHandlers(out);
             return;
         }
+        
+        if (line2.startsWith("-stats")) {
+            printStats(out);
+            return;
+        }
 
         err.println(getUsage());
     }
     
+    private void printStats(PrintStream out) {
+        try {
+            Field field = AbstractFactory.class.getDeclaredField("m_instancesName");
+            field.setAccessible(true);
+            List names = (List) field.get(null);
+            out.println("Number of living instances : " + names.size());
+            out.println("Created instances : " + names);
+        } catch (Exception e) {
+            out.println("Cannot compute stats : " + e.getMessage());
+        }
+        
+        
+    }
+
     /**
      * Print instance list.
      * 

Modified: felix/sandbox/clement/ipojo/composite/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/composite/pom.xml?rev=607434&r1=607433&r2=607434&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/composite/pom.xml (original)
+++ felix/sandbox/clement/ipojo/composite/pom.xml Sat Dec 29 07:53:29 2007
@@ -70,9 +70,7 @@
               	org.objectweb.asm*;-split-package:=merge-first
             </Private-Package>
             <Export-Package>
-              org.apache.felix.ipojo.composite; version="0.7.6",
-              org.osgi.service.cm,
-              org.osgi.service.log
+              org.apache.felix.ipojo.composite; version="0.7.6"
             </Export-Package>
             <IPOJO-Extension>composite:org.apache.felix.ipojo.composite.CompositeFactory</IPOJO-Extension>
             <_donotcopy>(CVS|.svn|.+.bak|~.+|metadata.xml)</_donotcopy>

Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java?rev=607434&r1=607433&r2=607434&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java Sat Dec 29 07:53:29 2007
@@ -277,18 +277,9 @@
      * the service registry.
      */
     public synchronized void update() {
-        // Contruct the service properties list
-        Properties serviceProperties = getServiceProperties();
-
-        if (serviceProperties == null) {
-            m_handler.error("Cannot get the properties of the provided service");
-            getInstanceManager().stop();
-            return;
-        }
-
         // Update the service registration
         if (m_serviceRegistration != null) {
-            m_serviceRegistration.setProperties(serviceProperties);
+            m_serviceRegistration.setProperties(getServiceProperties());
         }
     }
 

Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java?rev=607434&r1=607433&r2=607434&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java Sat Dec 29 07:53:29 2007
@@ -359,7 +359,7 @@
             boolean update = false;
             for (int j = 0; j < ps.getProperties().length; j++) {
                 Property prop = ps.getProperties()[j];
-                if (fieldName.equals(prop.getField())) {
+                if (fieldName.equals(prop.getField()) && ! prop.getValue().equals(value)) {
                     // it is the associated property
                     prop.set(value);
                     update = true;

Modified: felix/sandbox/clement/ipojo/event.admin.handler/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/event.admin.handler/pom.xml?rev=607434&r1=607433&r2=607434&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/event.admin.handler/pom.xml (original)
+++ felix/sandbox/clement/ipojo/event.admin.handler/pom.xml Sat Dec 29 07:53:29 2007
@@ -1,7 +1,7 @@
 <project>
   <modelVersion>4.0.0</modelVersion>
   <packaging>bundle</packaging>
-  <name>iPOJO Event Admin Handler</name>
+  <name>Apache Felix iPOJO Event Admin Handler</name>
   <groupId>org.apache.felix</groupId>
   <version>0.7.6-SNAPSHOT</version>
   <artifactId>org.apache.felix.ipojo.handler.event</artifactId>

Propchange: felix/sandbox/clement/ipojo/examples/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Dec 29 07:53:29 2007
@@ -0,0 +1,5 @@
+target*
+.classpath*
+.setting*
+.project*
+bin*

Propchange: felix/sandbox/clement/ipojo/examples/juni4osgi/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Dec 29 07:53:29 2007
@@ -0,0 +1,5 @@
+target*
+.classpath*
+.setting*
+.project*
+bin*

Added: felix/sandbox/clement/ipojo/examples/juni4osgi/metadata.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/examples/juni4osgi/metadata.xml?rev=607434&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/examples/juni4osgi/metadata.xml (added)
+++ felix/sandbox/clement/ipojo/examples/juni4osgi/metadata.xml Sat Dec 29 07:53:29 2007
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<iPOJO xmlns:extender="org.apache.felix.ipojo.extender">
+	<Component className="org.apache.felix.ipojo.junit4osgi.impl.JunitExtender">
+		<extender:extender extension="Test-Suite" onArrival="onBundleArrival" onDeparture="onBundleDeparture"/>
+		<callback transition="invalidate" method="stopping"/>
+		<provides/>
+	</Component>
+	<instance component="org.apache.felix.ipojo.junit4osgi.impl.JunitExtender"/>
+	
+	<component className="org.apache.felix.ipojo.junit4osgi.command.JunitCommand" factory="false">
+		<requires field="runner"/>
+		<provides/>
+	</component>
+	<instance component="org.apache.felix.ipojo.junit4osgi.command.JunitCommand"/>
+</iPOJO>
\ No newline at end of file

Added: felix/sandbox/clement/ipojo/examples/juni4osgi/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/examples/juni4osgi/pom.xml?rev=607434&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/examples/juni4osgi/pom.xml (added)
+++ felix/sandbox/clement/ipojo/examples/juni4osgi/pom.xml Sat Dec 29 07:53:29 2007
@@ -0,0 +1,77 @@
+<project>
+  <parent>
+    <groupId>org.apache.felix</groupId>
+    <artifactId>felix</artifactId>
+    <version>1.1.0-SNAPSHOT</version>
+    <relativePath>../../pom/pom.xml</relativePath>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <packaging>bundle</packaging>
+  <name>Junit4Osgi</name>
+  <version>0.7.6-SNAPSHOT</version>
+  <artifactId>org.apache.felix.ipojo.junit4osgi</artifactId>
+  <dependencies>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>org.apache.felix.ipojo</artifactId>
+      <version>${pom.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>org.apache.felix.ipojo.metadata</artifactId>
+      <version>${pom.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>org.apache.felix.shell</artifactId>
+      <version>1.1.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+    </dependency>
+  </dependencies>
+  <build>
+  <plugins>
+  <plugin>
+		<groupId>org.apache.maven.plugins</groupId>
+		<artifactId>maven-compiler-plugin</artifactId>
+		<configuration>
+		<source>1.5</source>
+		<target>1.5</target>
+		</configuration>
+	  </plugin>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <version>1.1.0-SNAPSHOT</version>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+          	<Bundle-Name>iPOJO OSGi Junit Runner</Bundle-Name>
+            <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+            <Private-Package>org.apache.felix.ipojo.junit4osgi.impl, org.apache.felix.ipojo.junit4osgi.command, org.apache.felix.ipojo.junit4osgi.test</Private-Package>
+            <Export-Package>org.apache.felix.ipojo.junit4osgi, junit.*</Export-Package>
+            <Test-Suite>org.apache.felix.ipojo.junit4osgi.test.TestTestCase, org.apache.felix.ipojo.junit4osgi.test.TestOSGiTestCase, org.apache.felix.ipojo.junit4osgi.test.TestTestSuite, org.apache.felix.ipojo.junit4osgi.test.TestOSGiTestSuite</Test-Suite>
+          </instructions>
+        </configuration>
+      </plugin>
+      <plugin>
+	      <groupId>org.apache.felix</groupId>
+	      <artifactId>maven-ipojo-plugin</artifactId>
+              <version>${pom.version}</version>
+		  <executions>
+          	<execution>
+            	<goals>
+	              <goal>ipojo-bundle</goal>
+               </goals>
+            <configuration>
+   				<ignoreAnnotations>true</ignoreAnnotations>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+   </build>
+</project>

Propchange: felix/sandbox/clement/ipojo/examples/juni4osgi/src/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Dec 29 07:53:29 2007
@@ -0,0 +1,5 @@
+target*
+.classpath*
+.setting*
+.project*
+bin*

Propchange: felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Dec 29 07:53:29 2007
@@ -0,0 +1,5 @@
+target*
+.classpath*
+.setting*
+.project*
+bin*

Propchange: felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Dec 29 07:53:29 2007
@@ -0,0 +1,5 @@
+target*
+.classpath*
+.setting*
+.project*
+bin*

Propchange: felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Dec 29 07:53:29 2007
@@ -0,0 +1,5 @@
+target*
+.classpath*
+.setting*
+.project*
+bin*

Propchange: felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Dec 29 07:53:29 2007
@@ -0,0 +1,5 @@
+target*
+.classpath*
+.setting*
+.project*
+bin*

Propchange: felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Dec 29 07:53:29 2007
@@ -0,0 +1,5 @@
+target*
+.classpath*
+.setting*
+.project*
+bin*

Propchange: felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Dec 29 07:53:29 2007
@@ -0,0 +1,5 @@
+target*
+.classpath*
+.setting*
+.project*
+bin*

Propchange: felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Dec 29 07:53:29 2007
@@ -0,0 +1,5 @@
+target*
+.classpath*
+.setting*
+.project*
+bin*

Added: felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/OSGiJunitRunner.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/OSGiJunitRunner.java?rev=607434&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/OSGiJunitRunner.java (added)
+++ felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/OSGiJunitRunner.java Sat Dec 29 07:53:29 2007
@@ -0,0 +1,22 @@
+package org.apache.felix.ipojo.junit4osgi;
+
+import java.io.PrintStream;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestResult;
+
+
+public interface OSGiJunitRunner {
+    
+    public void setResultPrinter(PrintStream ps);
+    
+    public List<TestResult>  run();
+    
+    public List<TestResult> run(long bundleId);
+    
+    public List<Test> getTests();
+    
+    public List<Test> getTests(long bundleId);
+
+}

Added: felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/OSGiTestCase.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/OSGiTestCase.java?rev=607434&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/OSGiTestCase.java (added)
+++ felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/OSGiTestCase.java Sat Dec 29 07:53:29 2007
@@ -0,0 +1,45 @@
+package org.apache.felix.ipojo.junit4osgi;
+
+import junit.framework.TestCase;
+
+import org.osgi.framework.BundleContext;
+
+public class OSGiTestCase extends TestCase {
+    
+    protected BundleContext context;
+    
+    public void setBundleContext(BundleContext bc) {
+        context = bc;
+    }
+    
+    /**
+     * Asserts that two doubles are equal.  If they are not
+     * an AssertionFailedError is thrown with the given message. 
+     */
+    static public void assertEquals(String message, double expected, double actual) {
+        if (Double.compare(expected, actual) != 0) {
+            fail(formatEqualsMessage(message, expected, actual));
+        }
+    }
+    
+    static String formatEqualsMessage(String message, Object expected, Object actual) {
+        String formatted = "";
+        if (message != null)
+            formatted = message + " ";
+        return formatted + "expected:<" + expected + "> but was:<" + actual + ">";
+    }
+    
+    static String formatNotEqualsMessage(String message, Object o1, Object o2) {
+        String formatted = "";
+        if (message != null)
+            formatted = message + " ";
+        return formatted + "o1:<" + o1 + "> is equals to o2:<" + o2 + ">";
+    }
+    
+    static public void assertNotEquals(String message, Object o1, Object o2) {
+        if (o1.equals(o2)) {
+            fail(formatNotEqualsMessage(message, o1, o2));
+        }
+    }
+
+}

Added: felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/OSGiTestSuite.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/OSGiTestSuite.java?rev=607434&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/OSGiTestSuite.java (added)
+++ felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/OSGiTestSuite.java Sat Dec 29 07:53:29 2007
@@ -0,0 +1,66 @@
+package org.apache.felix.ipojo.junit4osgi;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestResult;
+import junit.framework.TestSuite;
+
+import org.osgi.framework.BundleContext;
+
+public class OSGiTestSuite extends TestSuite {
+    
+    protected BundleContext context;
+    
+    public OSGiTestSuite(Class clazz, BundleContext bc) {
+       super(clazz);
+       context = bc;
+    }
+    
+    public OSGiTestSuite(BundleContext bc) {
+        super();
+        context = bc;
+    }
+    
+    public OSGiTestSuite(String name, BundleContext bc) {
+        super(name);
+        context = bc;
+    }
+    
+    public OSGiTestSuite(Class clazz, String name, BundleContext bc) {
+        super(clazz, name);
+        context = bc;
+    }
+    
+    public void setBundleContext(BundleContext bc) {
+        context = bc;
+    }
+    
+    /**
+     * Adds the tests from the given class to the suite
+     */
+    public void addTestSuite(Class testClass) {
+        if (OSGiTestCase.class.isAssignableFrom(testClass)) {
+            addTest(new OSGiTestSuite(testClass, context));
+        } else if (TestCase.class.isAssignableFrom(testClass)) {
+            addTest(new TestSuite(testClass));
+        } else {
+            System.out.println("Error : the " + testClass + " is not a valid test class");
+        }
+    }
+    
+    
+    public void runTest(Test test, TestResult result) {
+        if (test instanceof OSGiTestSuite) {
+            ((OSGiTestSuite) test).context = context;
+            test.run(result);
+        } else if (test instanceof OSGiTestCase) {
+            ((OSGiTestCase) test).context = context;
+            test.run(result);
+        } else {
+            test.run(result);
+        }
+        
+        
+    }
+
+}

Propchange: felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/command/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Dec 29 07:53:29 2007
@@ -0,0 +1,5 @@
+target*
+.classpath*
+.setting*
+.project*
+bin*

Added: felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/command/JunitCommand.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/command/JunitCommand.java?rev=607434&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/command/JunitCommand.java (added)
+++ felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/command/JunitCommand.java Sat Dec 29 07:53:29 2007
@@ -0,0 +1,72 @@
+package org.apache.felix.ipojo.junit4osgi.command;
+
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.felix.ipojo.junit4osgi.OSGiJunitRunner;
+import org.apache.felix.shell.Command;
+
+public class JunitCommand implements Command {
+    
+    private OSGiJunitRunner runner;
+    
+    private List<String> getNamesFromTests(List<Test> list) {
+        List<String> names = new ArrayList<String>(list.size());
+        for (int i = 0; i < list.size(); i++) {
+            if (list.get(i) instanceof TestCase) {
+                names.add(((TestCase) list.get(i)).getName());
+            }
+            if (list.get(i) instanceof TestSuite) {
+                String name = ((TestSuite) list.get(i)).getName();
+                if (name == null) {
+                    name = ((TestSuite) list.get(i)).toString();
+                }
+                names.add(name);
+            }
+        }
+        return names;
+    }
+
+    public void execute(String line, PrintStream out, PrintStream err) {
+       line = line.substring(getName().length()).trim();
+       if (line.equals("all")) {
+           if (runner.getTests() == null) {
+               err.println("No tests to execute");
+           } else {
+               out.println("Executing " + getNamesFromTests(runner.getTests()));
+               runner.run();
+           }
+       } else {
+           try {
+               Long bundleId = new Long(line);
+               if (runner.getTests(bundleId) == null) {
+                   err.println("No tests to execute");
+               } else {
+                   out.println("Executing " + getNamesFromTests(runner.getTests(bundleId)));
+                   runner.run(bundleId);
+               }
+           } catch (NumberFormatException e ) {
+               System.err.println("Unable to parse id " + line);
+           }
+       }
+    }
+
+
+    public String getName() {
+        return "junit";
+    }
+
+    public String getShortDescription() {
+        return "launch junit tests";
+    }
+
+    public String getUsage() {
+        return "junit";
+    }
+
+}

Propchange: felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/impl/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Dec 29 07:53:29 2007
@@ -0,0 +1,5 @@
+target*
+.classpath*
+.setting*
+.project*
+bin*

Added: felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/impl/JunitExtender.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/impl/JunitExtender.java?rev=607434&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/impl/JunitExtender.java (added)
+++ felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/impl/JunitExtender.java Sat Dec 29 07:53:29 2007
@@ -0,0 +1,228 @@
+/* 
+ * 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.ipojo.junit4osgi.impl;
+
+import java.io.PrintStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import junit.framework.Test;
+import junit.framework.TestResult;
+import junit.framework.TestSuite;
+
+import org.apache.felix.ipojo.junit4osgi.OSGiJunitRunner;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestSuite;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class JunitExtender implements OSGiJunitRunner {
+    
+    public static final String SUITE_METHODNAME = "suite";
+    
+    private Map<Bundle, List<Class>> m_suites = new HashMap<Bundle, List<Class>>();
+    
+    private ResultPrinter m_printer = new ResultPrinter(System.out);
+    
+    void onBundleArrival(Bundle bundle, String header) {
+        String[] tss = header.split(",");
+        for (int i = 0; i < tss.length; i++) {
+            try {
+                if (tss[i].length() != 0) {
+                    System.out.println("Loading " + tss[i]);
+                    Class<? extends Test> clazz = bundle.loadClass(tss[i].trim());
+                    addTestSuite(bundle, clazz);
+                }
+            } catch (ClassNotFoundException e) {
+                System.err.println("The test suite " + tss[i] + " is not in the bundle " + bundle.getBundleId() + " : " + e.getMessage());
+            }           
+        }
+    }
+    
+    private void addTestSuite(Bundle bundle, Class<? extends Test> test) {
+        List<Class> list = m_suites.get(bundle);
+        if (list == null) {
+            list = new ArrayList<Class>();
+            list.add(test);
+            m_suites.put(bundle, list);
+        } else {
+            list.add(test);
+        }
+    }
+    
+    private void removeTestSuites(Bundle bundle) {
+        List<Class> list = m_suites.remove(bundle);
+    }
+    
+    void onBundleDeparture(Bundle bundle) {
+        removeTestSuites(bundle);
+    }    
+    
+    public void setResultPrinter(PrintStream pw) {
+        m_printer = new ResultPrinter(pw);
+    }
+    
+    public List<TestResult> run() {
+        List<TestResult> results = new ArrayList<TestResult>(m_suites.size());
+        Iterator<Entry<Bundle, List<Class>>> it = m_suites.entrySet().iterator();
+        while(it.hasNext()) {
+            Entry<Bundle, List<Class>> entry = it.next();
+            Bundle bundle = entry.getKey();
+            List<Class> list = m_suites.get(bundle);
+            for (int i = 0; i < list.size(); i++) {
+                Test test = createTestFromClass(list.get(i), bundle);
+                TestResult tr = doRun(test);
+                results.add(tr);
+            }
+        }
+        return results;
+    }
+    
+    private TestResult doRun(Test test) {
+        TestResult result= new TestResult();
+        result.addListener(m_printer);
+        long startTime= System.currentTimeMillis();
+        
+        test.run(result);
+        
+        long endTime= System.currentTimeMillis();
+        long runTime= endTime-startTime;
+        m_printer.print(result, runTime);
+
+        return result;
+    }
+    
+    private Test createTestFromClass(Class<?> clazz, Bundle bundle) {
+            Method suiteMethod= null;
+            boolean bc = false;
+            try {
+                suiteMethod= clazz.getMethod(SUITE_METHODNAME, new Class[0]);
+            } catch(Exception e) {
+                // try to use a suite method receiving a bundle context
+                try {
+                    suiteMethod= clazz.getMethod(SUITE_METHODNAME, new Class[] {BundleContext.class});
+                    bc = true;
+                } catch(Exception e2) {
+                    // try to extract a test suite automatically
+                    if (OSGiTestSuite.class.isAssignableFrom(clazz)) {
+                        OSGiTestSuite ts = new OSGiTestSuite(clazz, bundle.getBundleContext());
+                        return ts;
+                    } else if (OSGiTestCase.class.isAssignableFrom(clazz)) {
+                        OSGiTestSuite ts = new OSGiTestSuite(clazz, bundle.getBundleContext());
+                        return ts;
+                    } else {
+                        return new TestSuite(clazz);
+                    }
+                }
+            }
+            
+            if (! Modifier.isStatic(suiteMethod.getModifiers())) {
+                System.err.println("Suite() method must be static");
+                return null;
+            }
+            Test test= null;
+            try {
+                if (bc) {
+                    test = (Test)suiteMethod.invoke(null,  new Object[] {bundle.getBundleContext()}); // static method injection the bundle context
+                } else {
+                    test = (Test)suiteMethod.invoke(null, (Object[])new Class[0]); // static method
+                }
+            }
+            catch (InvocationTargetException e) {
+                System.err.println("Failed to invoke suite():" + e.getTargetException().toString());
+                return null;
+            }
+            catch (IllegalAccessException e) {
+                System.err.println("Failed to invoke suite():" + e.toString());
+                return null;
+            }
+
+            return test;
+    }
+
+    public List<Test> getTests() {
+        List<Test> results = new ArrayList<Test>();
+        Iterator<Entry<Bundle, List<Class>>> it = m_suites.entrySet().iterator();
+        while(it.hasNext()) {
+            Entry<Bundle, List<Class>> entry = it.next();
+            Bundle bundle = entry.getKey();
+            List<Class> list = m_suites.get(bundle);
+            for (int i = 0; i < list.size(); i++) {
+                Test test = createTestFromClass(list.get(i), bundle);
+                results.add(test);
+            }
+        }
+        return results;
+    }
+
+    public List<Test> getTests(long bundleId) {
+        Iterator<Entry<Bundle, List<Class>>> it = m_suites.entrySet().iterator();
+        while(it.hasNext()) {
+            Entry<Bundle, List<Class>> entry = it.next();
+            Bundle bundle = entry.getKey();
+            if (bundle.getBundleId() == bundleId) {
+                List<Test> results = new ArrayList<Test>();
+                List<Class> list = m_suites.get(bundle);
+                for (int i = 0; i < list.size(); i++) {
+                    Test test = createTestFromClass(list.get(i), bundle);
+                    results.add(test);
+                }
+                return results;
+            }
+        }
+        return null;
+    }
+
+    public List<TestResult> run(long bundleId) {
+        Iterator<Entry<Bundle, List<Class>>> it = m_suites.entrySet().iterator();
+        while(it.hasNext()) {
+            Entry<Bundle, List<Class>> entry = it.next();
+            Bundle bundle = entry.getKey();
+            if (bundle.getBundleId() == bundleId) {
+                List<TestResult> results = new ArrayList<TestResult>();
+                List<Class> list = m_suites.get(bundle);
+                for (int i = 0; i < list.size(); i++) {
+                    Test test = createTestFromClass(list.get(i), bundle);
+                    TestResult tr = doRun(test);
+                    results.add(tr);
+                }
+                return results;
+            }
+        }
+        return null;
+    }
+    
+    public void stopping() {
+        System.out.println("Cleaning test suites ...");
+        m_suites = null;
+    }
+    
+
+    
+}

Added: felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/impl/ResultPrinter.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/impl/ResultPrinter.java?rev=607434&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/impl/ResultPrinter.java (added)
+++ felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/impl/ResultPrinter.java Sat Dec 29 07:53:29 2007
@@ -0,0 +1,139 @@
+
+package org.apache.felix.ipojo.junit4osgi.impl;
+
+import java.io.PrintStream;
+import java.text.NumberFormat;
+import java.util.Enumeration;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.Test;
+import junit.framework.TestFailure;
+import junit.framework.TestListener;
+import junit.framework.TestResult;
+import junit.runner.BaseTestRunner;
+
+public class ResultPrinter implements TestListener {
+	PrintStream fWriter;
+	int fColumn= 0;
+	
+	public ResultPrinter(PrintStream writer) {
+		fWriter= writer;
+	}
+	
+	/* API for use by textui.TestRunner
+	 */
+
+	synchronized void print(TestResult result, long runTime) {
+		printHeader(runTime);
+	    printErrors(result);
+	    printFailures(result);
+	    printFooter(result);
+	}
+
+	void printWaitPrompt() {
+		getWriter().println();
+		getWriter().println("<RETURN> to continue");
+	}
+	
+	/* Internal methods 
+	 */
+
+	protected void printHeader(long runTime) {
+		getWriter().println();
+		getWriter().println("Time: "+elapsedTimeAsString(runTime));
+	}
+	
+	protected void printErrors(TestResult result) {
+		printDefects(result.errors(), result.errorCount(), "error");
+	}
+	
+	protected void printFailures(TestResult result) {
+		printDefects(result.failures(), result.failureCount(), "failure");
+	}
+	
+	protected void printDefects(Enumeration<TestFailure> booBoos, int count, String type) {
+		if (count == 0) return;
+		if (count == 1)
+			getWriter().println("There was " + count + " " + type + ":");
+		else
+			getWriter().println("There were " + count + " " + type + "s:");
+		for (int i= 1; booBoos.hasMoreElements(); i++) {
+			printDefect(booBoos.nextElement(), i);
+		}
+	}
+	
+	public void printDefect(TestFailure booBoo, int count) { // only public for testing purposes
+		printDefectHeader(booBoo, count);
+		printDefectTrace(booBoo);
+	}
+
+	protected void printDefectHeader(TestFailure booBoo, int count) {
+		// I feel like making this a println, then adding a line giving the throwable a chance to print something
+		// before we get to the stack trace.
+		getWriter().print(count + ") " + booBoo.failedTest());
+	}
+
+	protected void printDefectTrace(TestFailure booBoo) {
+		getWriter().print(BaseTestRunner.getFilteredTrace(booBoo.trace()));
+	}
+
+	protected void printFooter(TestResult result) {
+		if (result.wasSuccessful()) {
+			getWriter().println();
+			getWriter().print("OK");
+			getWriter().println (" (" + result.runCount() + " test" + (result.runCount() == 1 ? "": "s") + ")");
+
+		} else {
+			getWriter().println();
+			getWriter().println("FAILURES!!!");
+			getWriter().println("Tests run: "+result.runCount()+ 
+				         ",  Failures: "+result.failureCount()+
+				         ",  Errors: "+result.errorCount());
+		}
+	    getWriter().println();
+	}
+
+
+	/**
+	 * Returns the formatted string of the elapsed time.
+	 * Duplicated from BaseTestRunner. Fix it.
+	 */
+	protected String elapsedTimeAsString(long runTime) {
+		return NumberFormat.getInstance().format((double)runTime/1000);
+	}
+
+	public PrintStream getWriter() {
+		return fWriter;
+	}
+	/**
+	 * @see junit.framework.TestListener#addError(Test, Throwable)
+	 */
+	public void addError(Test test, Throwable t) {
+		getWriter().print("E");
+	}
+
+	/**
+	 * @see junit.framework.TestListener#addFailure(Test, AssertionFailedError)
+	 */
+	public void addFailure(Test test, AssertionFailedError t) {
+		getWriter().print("F");
+	}
+
+	/**
+	 * @see junit.framework.TestListener#endTest(Test)
+	 */
+	public void endTest(Test test) {
+	}
+
+	/**
+	 * @see junit.framework.TestListener#startTest(Test)
+	 */
+	public void startTest(Test test) {
+		getWriter().print(".");
+		if (fColumn++ >= 40) {
+			getWriter().println();
+			fColumn= 0;
+		}
+	}
+
+}

Propchange: felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Dec 29 07:53:29 2007
@@ -0,0 +1,5 @@
+target*
+.classpath*
+.setting*
+.project*
+bin*

Added: felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestOSGiTestCase.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestOSGiTestCase.java?rev=607434&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestOSGiTestCase.java (added)
+++ felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestOSGiTestCase.java Sat Dec 29 07:53:29 2007
@@ -0,0 +1,12 @@
+package org.apache.felix.ipojo.junit4osgi.test;
+
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+
+public class TestOSGiTestCase extends OSGiTestCase {
+    
+    public void test1() {
+        System.out.println("Test BC");
+        assertNotNull("Test bundle context", context);
+    }
+
+}

Added: felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestOSGiTestSuite.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestOSGiTestSuite.java?rev=607434&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestOSGiTestSuite.java (added)
+++ felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestOSGiTestSuite.java Sat Dec 29 07:53:29 2007
@@ -0,0 +1,21 @@
+package org.apache.felix.ipojo.junit4osgi.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.felix.ipojo.junit4osgi.OSGiTestSuite;
+import org.osgi.framework.BundleContext;
+
+public class TestOSGiTestSuite extends TestSuite {
+    
+    public static Test suite(BundleContext bc) {
+        TestSuite ts = new TestSuite();
+        ts.setName("Test OSGi suite() method");
+        ts.addTestSuite(TestTestCase.class);
+        OSGiTestSuite ots = new OSGiTestSuite(TestOSGiTestCase.class, bc);
+        ots.setBundleContext(bc);
+        ts.addTest(ots);
+        return ts;
+    }
+
+}

Added: felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestTestCase.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestTestCase.java?rev=607434&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestTestCase.java (added)
+++ felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestTestCase.java Sat Dec 29 07:53:29 2007
@@ -0,0 +1,15 @@
+package org.apache.felix.ipojo.junit4osgi.test;
+
+import junit.framework.TestCase;
+
+public class TestTestCase extends TestCase {
+    
+    public void test1() { }
+    
+    public void test2() { }
+    
+    public void test3() { }
+    
+    public void test4() { }
+
+}

Added: felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestTestSuite.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestTestSuite.java?rev=607434&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestTestSuite.java (added)
+++ felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestTestSuite.java Sat Dec 29 07:53:29 2007
@@ -0,0 +1,15 @@
+package org.apache.felix.ipojo.junit4osgi.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class TestTestSuite extends TestSuite {
+    
+    public static Test suite() {
+        TestSuite ts = new TestSuite();
+        ts.setName("Test suite() method");
+        ts.addTestSuite(TestTestCase.class);
+        return ts;
+    }
+
+}

Propchange: felix/sandbox/clement/ipojo/examples/juni4osgi/src/main/resources/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Dec 29 07:53:29 2007
@@ -0,0 +1,5 @@
+target*
+.classpath*
+.setting*
+.project*
+bin*

Propchange: felix/sandbox/clement/ipojo/extender.pattern.handler/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Dec 29 07:53:29 2007
@@ -0,0 +1,4 @@
+.classpath
+.project
+target*
+bin*

Added: felix/sandbox/clement/ipojo/extender.pattern.handler/metadata.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/extender.pattern.handler/metadata.xml?rev=607434&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/extender.pattern.handler/metadata.xml (added)
+++ felix/sandbox/clement/ipojo/extender.pattern.handler/metadata.xml Sat Dec 29 07:53:29 2007
@@ -0,0 +1,4 @@
+<ipojo>
+<handler classname="org.apache.felix.ipojo.handler.extender.ExtenderModelHandler" name="extender" namespace="org.apache.felix.ipojo.extender">
+</handler>
+</ipojo>
\ No newline at end of file

Added: felix/sandbox/clement/ipojo/extender.pattern.handler/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/extender.pattern.handler/pom.xml?rev=607434&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/extender.pattern.handler/pom.xml (added)
+++ felix/sandbox/clement/ipojo/extender.pattern.handler/pom.xml Sat Dec 29 07:53:29 2007
@@ -0,0 +1,65 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <packaging>bundle</packaging>
+  <name>Apache Felix iPOJO Extender Pattern Handler</name>
+  <groupId>org.apache.felix</groupId>
+  <version>0.7.6-SNAPSHOT</version>
+  <artifactId>org.apache.felix.ipojo.handler.extender.pattern</artifactId>
+	  
+  <dependencies>
+	  <dependency>
+  			<groupId>org.apache.felix</groupId>
+      		<artifactId>org.apache.felix.ipojo</artifactId>
+	        <version>0.7.6-SNAPSHOT</version>
+	  </dependency>
+	  <dependency>
+  			<groupId>org.apache.felix</groupId>
+      		<artifactId>org.apache.felix.ipojo.metadata</artifactId>
+	      	<version>0.7.6-SNAPSHOT</version>
+	  </dependency>
+	  <dependency>
+  			<groupId>org.apache.felix</groupId>
+      		<artifactId>org.osgi.core</artifactId>
+      		<version>1.1.0-SNAPSHOT</version>
+	  </dependency>
+	  <dependency>
+	     <groupId>org.apache.felix</groupId>
+  		 <artifactId>org.osgi.compendium</artifactId>
+         <version>0.9.0-SNAPSHOT</version>
+	</dependency>
+  </dependencies>
+  
+
+  
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Private-Package>org.apache.felix.ipojo.handler.extender</Private-Package>
+            <Bundle-Name>${pom.name}</Bundle-Name>
+            <Bundle-SymbolicName>ipojo.event.admin.handler.extender</Bundle-SymbolicName>
+          </instructions>
+        </configuration>
+      </plugin>
+      <plugin>
+	      <groupId>org.apache.felix</groupId>
+	      <artifactId>maven-ipojo-plugin</artifactId>
+          <version>${pom.version}</version>
+		  <executions>
+          	<execution>
+            	<goals>
+	              <goal>ipojo-bundle</goal>
+               </goals>
+            <configuration>
+   				<metadata>metadata.xml</metadata>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Added: felix/sandbox/clement/ipojo/extender.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/extender/ExtenderManager.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/extender.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/extender/ExtenderManager.java?rev=607434&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/extender.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/extender/ExtenderManager.java (added)
+++ felix/sandbox/clement/ipojo/extender.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/extender/ExtenderManager.java Sat Dec 29 07:53:29 2007
@@ -0,0 +1,103 @@
+package org.apache.felix.ipojo.handler.extender;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.List;
+
+import org.apache.felix.ipojo.PrimitiveHandler;
+import org.apache.felix.ipojo.util.Callback;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.SynchronousBundleListener;
+
+public class ExtenderManager implements SynchronousBundleListener {
+    
+    private String m_extension;
+    private Callback m_onArrival;
+    private Callback m_onDeparture;
+    private PrimitiveHandler m_handler;
+    private BundleContext m_context;
+    private List m_bundles = new ArrayList();
+    
+    public ExtenderManager(ExtenderModelHandler handler, String extension, String bind, String unbind) {
+        m_handler = handler;
+        m_onArrival = new Callback(bind, new Class[] {Bundle.class, String.class}, false, m_handler.getInstanceManager());
+        m_onDeparture = new Callback(unbind, new Class[] {Bundle.class}, false, m_handler.getInstanceManager());
+        m_extension = extension;
+        m_context = handler.getInstanceManager().getContext();
+    }
+    
+    public void start() {
+        synchronized (this) {
+            // listen to any changes in bundles.
+            m_context.addBundleListener(this);
+            // compute already started bundles.
+            for (int i = 0; i < m_context.getBundles().length; i++) {
+                if (m_context.getBundles()[i].getState() == Bundle.ACTIVE) {
+                    onArrival(m_context.getBundles()[i]);
+                }
+            }
+        }
+    }
+    
+    private void onArrival(Bundle bundle) {
+        Dictionary headers = bundle.getHeaders();
+        String header = (String )headers.get(m_extension);
+        if (header != null) {
+            m_bundles.add(bundle);
+            try {
+                m_onArrival.call(new Object[] {bundle, header});
+            } catch (NoSuchMethodException e) {
+                m_handler.error("The onArrival method " + m_onArrival.getMethod() + " does not exist in the class", e);
+                m_handler.getInstanceManager().stop();
+            } catch (IllegalAccessException e) {
+                m_handler.error("The onArrival method " + m_onArrival.getMethod() + " cannot be called", e);
+                m_handler.getInstanceManager().stop();
+            } catch (InvocationTargetException e) {
+                m_handler.error("The onArrival method " + m_onArrival.getMethod() + " has thrown an exception", e.getTargetException());
+                m_handler.getInstanceManager().stop();
+            }
+        }
+    }
+
+    public void stop() {
+        m_context.removeBundleListener(this);
+        m_bundles.clear();
+    }
+
+    public void bundleChanged(BundleEvent event) {
+        switch (event.getType()) {
+            case BundleEvent.STARTED:
+                onArrival(event.getBundle());
+                break;
+            case BundleEvent.STOPPING:
+                onDeparture(event.getBundle());
+                break;
+            default: 
+                break;
+        }
+        
+    }
+
+    private void onDeparture(Bundle bundle) {
+        if (m_bundles.contains(bundle)) {
+            try {
+                m_onDeparture.call(new Object[] {bundle});
+            } catch (NoSuchMethodException e) {
+                m_handler.error("The onDeparture method " + m_onDeparture.getMethod() + " does not exist in the class", e);
+                m_handler.getInstanceManager().stop();
+            } catch (IllegalAccessException e) {
+                m_handler.error("The onDeparture method " + m_onDeparture.getMethod() + " cannot be called", e);
+                m_handler.getInstanceManager().stop();
+            } catch (InvocationTargetException e) {
+                m_handler.error("The onDeparture method " + m_onDeparture.getMethod() + " has thrown an exception", e.getTargetException());
+                m_handler.getInstanceManager().stop();
+            }
+        }
+    }
+
+    
+
+}

Added: felix/sandbox/clement/ipojo/extender.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/extender/ExtenderModelHandler.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/extender.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/extender/ExtenderModelHandler.java?rev=607434&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/extender.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/extender/ExtenderModelHandler.java (added)
+++ felix/sandbox/clement/ipojo/extender.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/extender/ExtenderModelHandler.java Sat Dec 29 07:53:29 2007
@@ -0,0 +1,49 @@
+package org.apache.felix.ipojo.handler.extender;
+
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.List;
+
+import org.apache.felix.ipojo.ConfigurationException;
+import org.apache.felix.ipojo.PrimitiveHandler;
+import org.apache.felix.ipojo.metadata.Element;
+
+public class ExtenderModelHandler extends PrimitiveHandler {
+    
+    public final static String NAMESPACE = "org.apache.felix.ipojo.extender";
+    
+    private List m_managers = new ArrayList(1);
+
+    public void configure(Element elem, Dictionary dict) throws ConfigurationException {
+        Element[] elems = elem.getElements("extender",NAMESPACE);
+        for (int i = 0; i < elems.length; i++) {
+            String extension = elems[i].getAttribute("extension");
+            String onArrival = elems[i].getAttribute("onArrival");
+            String onDeparture = elems[i].getAttribute("onDeparture");
+            
+            if (extension == null) {
+                throw new ConfigurationException("The extender element requires an 'extender' attribute");
+            }
+            if (onArrival == null || onDeparture == null) {
+                throw new ConfigurationException("The extender element requires the onArrival and onDeparture attributes");
+            }
+            
+            ExtenderManager wbm = new ExtenderManager(this, extension, onArrival, onDeparture);
+            m_managers.add(wbm);
+        }
+        
+    }
+
+    public void start() {
+        for (int i = 0; i < m_managers.size(); i++) {
+            ((ExtenderManager) m_managers.get(i)).start();
+        }
+    }
+
+    public void stop() {
+        for (int i = 0; i < m_managers.size(); i++) {
+            ((ExtenderManager) m_managers.get(i)).stop();
+        } 
+    }
+
+}

Modified: felix/sandbox/clement/ipojo/plugin/src/main/java/org/apache/felix/ipojo/plugin/ManipulatorMojo.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/plugin/src/main/java/org/apache/felix/ipojo/plugin/ManipulatorMojo.java?rev=607434&r1=607433&r2=607434&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/plugin/src/main/java/org/apache/felix/ipojo/plugin/ManipulatorMojo.java (original)
+++ felix/sandbox/clement/ipojo/plugin/src/main/java/org/apache/felix/ipojo/plugin/ManipulatorMojo.java Sat Dec 29 07:53:29 2007
@@ -126,7 +126,15 @@
 
         getLog().info("Start bundle manipulation");
         // Get metadata file
+
+        // Look for the metadata file in the output directory
         File meta = new File(m_outputDirectory + File.separator + m_metadata);
+        
+        // If not found look inside the pom directory
+        if (! meta.exists()) {
+            meta = new File(m_project.getBasedir() + File.separator + m_metadata);
+        }
+        
         getLog().info("Metadata File : " + meta.getAbsolutePath());
         if (!meta.exists()) {
             // Verify if annotations are ignored

Modified: felix/sandbox/clement/ipojo/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/pom.xml?rev=607434&r1=607433&r2=607434&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/pom.xml (original)
+++ felix/sandbox/clement/ipojo/pom.xml Sat Dec 29 07:53:29 2007
@@ -19,5 +19,8 @@
 	<module>composite</module>
     <module>arch</module>
 	<module>ant</module>
+	<module>event.admin.handler</module>
+	<module>white.board.pattern.handler</module>
+	<module>extender.pattern.handler</module>
   </modules>
 </project>

Propchange: felix/sandbox/clement/ipojo/white.board.pattern.handler/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Dec 29 07:53:29 2007
@@ -0,0 +1,5 @@
+target*
+bin*
+.settings
+.project
+.classpath

Added: felix/sandbox/clement/ipojo/white.board.pattern.handler/metadata.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/white.board.pattern.handler/metadata.xml?rev=607434&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/white.board.pattern.handler/metadata.xml (added)
+++ felix/sandbox/clement/ipojo/white.board.pattern.handler/metadata.xml Sat Dec 29 07:53:29 2007
@@ -0,0 +1,4 @@
+<ipojo>
+<handler classname="org.apache.felix.ipojo.handler.wbp.WhiteBoardPatternHandler" name="wbp" namespace="org.apache.felix.ipojo.white-board-pattern">
+</handler>
+</ipojo>
\ No newline at end of file

Added: felix/sandbox/clement/ipojo/white.board.pattern.handler/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/white.board.pattern.handler/pom.xml?rev=607434&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/white.board.pattern.handler/pom.xml (added)
+++ felix/sandbox/clement/ipojo/white.board.pattern.handler/pom.xml Sat Dec 29 07:53:29 2007
@@ -0,0 +1,65 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <packaging>bundle</packaging>
+  <name>Apache FelixiPOJO White Board Pattern Handler</name>
+  <groupId>org.apache.felix</groupId>
+  <version>0.7.6-SNAPSHOT</version>
+  <artifactId>org.apache.felix.ipojo.handler.white.board.pattern</artifactId>
+	  
+  <dependencies>
+	  <dependency>
+  			<groupId>org.apache.felix</groupId>
+      		<artifactId>org.apache.felix.ipojo</artifactId>
+	        <version>0.7.6-SNAPSHOT</version>
+	  </dependency>
+	  <dependency>
+  			<groupId>org.apache.felix</groupId>
+      		<artifactId>org.apache.felix.ipojo.metadata</artifactId>
+	      	<version>0.7.6-SNAPSHOT</version>
+	  </dependency>
+	  <dependency>
+  			<groupId>org.apache.felix</groupId>
+      		<artifactId>org.osgi.core</artifactId>
+      		<version>1.1.0-SNAPSHOT</version>
+	  </dependency>
+	  <dependency>
+	     <groupId>org.apache.felix</groupId>
+  		 <artifactId>org.osgi.compendium</artifactId>
+         <version>0.9.0-SNAPSHOT</version>
+	</dependency>
+  </dependencies>
+  
+
+  
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Private-Package>org.apache.felix.ipojo.handler.wbp</Private-Package>
+            <Bundle-Name>${pom.name}</Bundle-Name>
+            <Bundle-SymbolicName>ipojo.event.admin.handler.wbp</Bundle-SymbolicName>
+          </instructions>
+        </configuration>
+      </plugin>
+      <plugin>
+	      <groupId>org.apache.felix</groupId>
+	      <artifactId>maven-ipojo-plugin</artifactId>
+          <version>${pom.version}</version>
+		  <executions>
+          	<execution>
+            	<goals>
+	              <goal>ipojo-bundle</goal>
+               </goals>
+            <configuration>
+   				<metadata>metadata.xml</metadata>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Added: felix/sandbox/clement/ipojo/white.board.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/wbp/WhiteBoardManager.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/white.board.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/wbp/WhiteBoardManager.java?rev=607434&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/white.board.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/wbp/WhiteBoardManager.java (added)
+++ felix/sandbox/clement/ipojo/white.board.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/wbp/WhiteBoardManager.java Sat Dec 29 07:53:29 2007
@@ -0,0 +1,91 @@
+package org.apache.felix.ipojo.handler.wbp;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.felix.ipojo.PrimitiveHandler;
+import org.apache.felix.ipojo.util.Callback;
+import org.apache.felix.ipojo.util.Tracker;
+import org.apache.felix.ipojo.util.TrackerCustomizer;
+import org.osgi.framework.Filter;
+import org.osgi.framework.ServiceReference;
+
+public class WhiteBoardManager implements TrackerCustomizer {
+    
+    private Filter m_filter;
+    private Callback m_onArrival;
+    private Callback m_onDeparture;
+    private Callback m_onModification;
+    private Tracker m_tracker;
+    private PrimitiveHandler m_handler;
+    
+    public WhiteBoardManager(WhiteBoardPatternHandler handler, Filter filter, String bind, String unbind, String modification) {
+        m_handler = handler;
+        m_onArrival = new Callback(bind, new Class[] {ServiceReference.class}, false, m_handler.getInstanceManager());
+        m_onDeparture = new Callback(unbind, new Class[] {ServiceReference.class}, false, m_handler.getInstanceManager());
+        if (modification != null) {
+            m_onModification = new Callback(modification, new Class[] {ServiceReference.class}, false, m_handler.getInstanceManager());
+        }
+        m_filter = filter;
+        m_tracker = new Tracker(handler.getInstanceManager().getContext(), m_filter, this);
+    }
+    
+    public void start() {
+        m_tracker.open();
+    }
+    
+    public void stop() {
+        m_tracker.close();
+    }
+
+    public void addedService(ServiceReference arg0) {
+        try {
+            m_onArrival.call(new Object[] {arg0});
+        } catch (NoSuchMethodException e) {
+            m_handler.error("The onArrival method " + m_onArrival.getMethod() + " does not exist in the class", e);
+            m_handler.getInstanceManager().stop();
+        } catch (IllegalAccessException e) {
+            m_handler.error("The onArrival method " + m_onArrival.getMethod() + " cannot be invoked", e);
+            m_handler.getInstanceManager().stop();
+        } catch (InvocationTargetException e) {
+            m_handler.error("The onArrival method " + m_onArrival.getMethod() + " has thrown an exception", e.getTargetException());
+            m_handler.getInstanceManager().stop();
+        }
+    }
+
+    public boolean addingService(ServiceReference arg0) {
+        return true;
+    }
+
+    public void modifiedService(ServiceReference arg0, Object arg1) {
+        if (m_onModification != null) {
+            try {
+                m_onModification.call(new Object[] {arg0});
+            } catch (NoSuchMethodException e) {
+                m_handler.error("The onModification method " + m_onModification.getMethod() + " does not exist in the class", e);
+                m_handler.getInstanceManager().stop();
+            } catch (IllegalAccessException e) {
+                m_handler.error("The onModification method " + m_onModification.getMethod() + " cannot be invoked", e);
+                m_handler.getInstanceManager().stop();
+            } catch (InvocationTargetException e) {
+                m_handler.error("The onModification method " + m_onModification.getMethod() + " has thrown an exception", e.getTargetException());
+                m_handler.getInstanceManager().stop();
+            }
+        }
+    }
+
+    public void removedService(ServiceReference arg0, Object arg1) {
+        try {
+            m_onDeparture.call(new Object[] {arg0});
+        } catch (NoSuchMethodException e) {
+            m_handler.error("The onDeparture method " + m_onDeparture.getMethod() + " does not exist in the class", e);
+            m_handler.getInstanceManager().stop();
+        } catch (IllegalAccessException e) {
+            m_handler.error("The onDeparture method " + m_onDeparture.getMethod() + " cannot be invoked", e);
+            m_handler.getInstanceManager().stop();
+        } catch (InvocationTargetException e) {
+            m_handler.error("The onDeparture method " + m_onDeparture.getMethod() + " has thrown an exception", e.getTargetException());
+            m_handler.getInstanceManager().stop();
+        }
+    }
+
+}

Added: felix/sandbox/clement/ipojo/white.board.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/wbp/WhiteBoardPatternHandler.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/white.board.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/wbp/WhiteBoardPatternHandler.java?rev=607434&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/white.board.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/wbp/WhiteBoardPatternHandler.java (added)
+++ felix/sandbox/clement/ipojo/white.board.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/wbp/WhiteBoardPatternHandler.java Sat Dec 29 07:53:29 2007
@@ -0,0 +1,55 @@
+package org.apache.felix.ipojo.handler.wbp;
+
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.List;
+
+import org.apache.felix.ipojo.ConfigurationException;
+import org.apache.felix.ipojo.PrimitiveHandler;
+import org.apache.felix.ipojo.metadata.Element;
+import org.osgi.framework.InvalidSyntaxException;
+
+public class WhiteBoardPatternHandler extends PrimitiveHandler {
+    
+    public final static String NAMESPACE = "org.apache.felix.ipojo.white-board-pattern";
+    
+    private List m_managers = new ArrayList(1);
+
+    public void configure(Element elem, Dictionary dict) throws ConfigurationException {
+        Element[] elems = elem.getElements("wbp",NAMESPACE);
+        for (int i = 0; i < elems.length; i++) {
+            String filter = elems[i].getAttribute("filter");
+            String onArrival = elems[i].getAttribute("onArrival");
+            String onDeparture = elems[i].getAttribute("onDeparture");
+            String onModification = elems[i].getAttribute("onModification");
+            
+            if (filter == null) {
+                throw new ConfigurationException("The white board pattern element requires a filter attribute");
+            }
+            if (onArrival == null || onDeparture == null) {
+                throw new ConfigurationException("The white board pattern element requires the onArrival and onDeparture attributes");
+            }
+            
+            try {
+                WhiteBoardManager wbm = new WhiteBoardManager(this, getInstanceManager().getContext().createFilter(filter), onArrival, onDeparture, onModification);
+                m_managers.add(wbm);
+            } catch (InvalidSyntaxException e) {
+                throw new ConfigurationException("The filter " + filter + " is invalid : " + e);
+            }
+        }
+        
+    }
+
+    public void start() {
+        for (int i = 0; i < m_managers.size(); i++) {
+            ((WhiteBoardManager) m_managers.get(i)).start();
+        }
+    }
+
+    public void stop() {
+        for (int i = 0; i < m_managers.size(); i++) {
+            ((WhiteBoardManager) m_managers.get(i)).stop();
+        } 
+    }
+
+}



Mime
View raw message