Fix issue Felix-834.
Provides annotations for the whiteboard, extender and event admin handlers.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@720508 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/tests/core/annotations/pom.xml b/ipojo/tests/core/annotations/pom.xml
index 92151fd..848d557 100644
--- a/ipojo/tests/core/annotations/pom.xml
+++ b/ipojo/tests/core/annotations/pom.xml
@@ -31,7 +31,8 @@
 		</dependency>

 		<dependency>

 			<groupId>org.apache.felix</groupId>

-			<artifactId>org.apache.felix.ipojo.metadata</artifactId>

+			<artifactId>org.apache.felix.ipojo.metadata

+			</artifactId>

 			<version>1.1.0-SNAPSHOT</version>

 		</dependency>

 		<dependency>

@@ -46,17 +47,24 @@
 		</dependency>

 		<dependency>

 			<groupId>ipojo.examples</groupId>

-			<artifactId>org.apache.felix.ipojo.junit4osgi</artifactId>

+			<artifactId>org.apache.felix.ipojo.junit4osgi

+			</artifactId>

 			<version>1.1.0-SNAPSHOT</version>

 		</dependency>

 		<dependency>

 			<groupId>org.apache.felix</groupId>

-			<artifactId>org.apache.felix.ipojo.annotations</artifactId>

+			<artifactId>org.apache.felix.ipojo.annotations

+			</artifactId>

 			<version>1.1.0-SNAPSHOT</version>

 		</dependency>

-

-

+		<dependency>

+			<groupId>org.apache.felix</groupId>

+			<artifactId>org.apache.felix.ipojo.handler.eventadmin

+			</artifactId>

+			<version>1.1.0-SNAPSHOT</version>

+		</dependency>

 	</dependencies>

+	

 	<build>

 		<plugins>

 			<plugin>

diff --git a/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/AnnotationsTestSuite.java b/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/AnnotationsTestSuite.java
index edea2a5..dc7d880 100644
--- a/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/AnnotationsTestSuite.java
+++ b/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/AnnotationsTestSuite.java
@@ -44,6 +44,11 @@
         // External handler annotations

         ots.addTestSuite(TemporalDependencies.class);

         ots.addTestSuite(JMX.class);

+        ots.addTestSuite(WhiteBoard.class);

+        ots.addTestSuite(Extender.class);

+        ots.addTestSuite(EventAdmin.class);

+

+

         return ots;

     }

 

diff --git a/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/EventAdmin.java b/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/EventAdmin.java
new file mode 100644
index 0000000..cc61cc3
--- /dev/null
+++ b/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/EventAdmin.java
@@ -0,0 +1,114 @@
+package org.apache.felix.ipojo.test.scenarios.annotations;
+
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.metadata.Element;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+
+public class EventAdmin extends OSGiTestCase {
+    String type = "org.apache.felix.ipojo.test.scenarios.component.event.PubSub";
+    String namespace = "org.apache.felix.ipojo.handlers.event";
+    
+    Element component;
+    
+    public void setUp() {
+        component = Utils.getMetatadata(context, type);
+        assertNotNull("Check component", component);
+    }
+    
+    public void tearDown() {
+        component = null;
+    }
+    
+    public void testP1() {
+        //P1, synchronous
+        Element elem = getElementByName("p1");
+        checkPublisher(elem);
+        assertNull("Check topics", elem.getAttribute("topics"));
+        assertEquals("Check synchronous", "true", elem.getAttribute("synchronous"));
+        assertEquals("Check field", "publisher1", elem.getAttribute("field"));
+        assertNull("Check data_key", elem.getAttribute("data_key"));  
+    }
+    
+    public void testP2() {
+        //name="p2", synchronous=false, topics="foo,bar", data_key="data"
+        Element elem = getElementByName("p2");
+        checkPublisher(elem);
+        assertEquals("Check topics (" + elem.getAttribute("topics")+")", "foo,bar", elem.getAttribute("topics"));
+        assertEquals("Check synchronous", "false", elem.getAttribute("synchronous"));
+        assertEquals("Check field", "publisher2", elem.getAttribute("field"));
+        assertEquals("Check data_key", "data" ,elem.getAttribute("data_key"));  
+    }
+    
+    public void testP3() {
+        //name="p3", synchronous=true, topics="bar"
+        Element elem = getElementByName("p3");
+        checkPublisher(elem);
+        assertEquals("Check topics", "bar" ,elem.getAttribute("topics"));
+        assertEquals("Check synchronous", "true", elem.getAttribute("synchronous"));
+        assertEquals("Check field", "publisher3", elem.getAttribute("field"));
+        assertNull("Check data_key", elem.getAttribute("data_key"));  
+    }
+    
+    public void testS1() {
+        //name="s1", data_key="data"
+        Element elem = getElementByName("s1");
+        checkSubscriber(elem);
+        assertNull("Check topics",elem.getAttribute("topics"));
+        assertEquals("Check method", "receive1", elem.getAttribute("method"));
+        assertEquals("Check data_key", "data" ,elem.getAttribute("data_key"));  
+        assertNull("Check data_type", elem.getAttribute("data_type"));
+        assertNull("Check filter", elem.getAttribute("filter"));
+    }
+    
+    public void testS2() {
+        //name="s2", topics="foo,bar", filter="(foo=true)"
+        Element elem = getElementByName("s2");
+        checkSubscriber(elem);
+        assertEquals("Check topics", "foo,bar", elem.getAttribute("topics"));
+        assertEquals("Check method", "receive2", elem.getAttribute("method"));
+        assertNull("Check data_key" ,elem.getAttribute("data_key"));  
+        assertNull("Check data_type", elem.getAttribute("data_type"));
+        assertEquals("Check filter","(foo=true)" , elem.getAttribute("filter"));
+    }
+    
+    public void testS3() {
+        //name="s3", topics="foo", data_key="data", data_type="java.lang.String"
+        Element elem = getElementByName("s3");
+        checkSubscriber(elem);
+        assertEquals("Check topics", "foo", elem.getAttribute("topics"));
+        assertEquals("Check method", "receive3", elem.getAttribute("method"));
+        assertEquals("Check data_key", "data" ,elem.getAttribute("data_key"));  
+        assertEquals("Check data_type", "java.lang.String", elem.getAttribute("data_type"));
+        assertNull("Check filter", elem.getAttribute("filter"));
+    }
+    
+   
+    
+    public Element getElementByName(String name) {
+        Element [] elems = component.getElements();
+        for (int i = 0; i < elems.length; i++) {
+            if (elems[i].containsAttribute("name") && elems[i].getAttribute("name").equals(name)) {
+                return elems[i];
+            }
+        }
+        return null;
+    }
+    
+    public void checkSubscriber(Element elem) {
+        assertNotNull("Can't check subscriber : null element",elem);
+        String ns = elem.getNameSpace();
+        String nm = elem.getName();
+        assertEquals("Elem is not a subscriber : bad namespace", namespace, ns);
+        assertEquals("Elem is not a subscriber : bad name", "subscriber", nm);
+
+    }
+    
+    public void checkPublisher(Element elem) {
+        assertNotNull("Can't check publisher : null element",elem);
+        String ns = elem.getNameSpace();
+        String nm = elem.getName();
+        assertEquals("Elem is not a publisher : bad namespace", namespace, ns);
+        assertEquals("Elem is not a publisher : bad name", "publisher", nm);
+    }
+
+}
diff --git a/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/Extender.java b/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/Extender.java
new file mode 100644
index 0000000..28e9661
--- /dev/null
+++ b/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/Extender.java
@@ -0,0 +1,27 @@
+package org.apache.felix.ipojo.test.scenarios.annotations;
+
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.metadata.Element;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+
+public class Extender extends OSGiTestCase {
+    
+    String type = "org.apache.felix.ipojo.test.scenarios.component.extender.Extender";
+    String namespace = "org.apache.felix.ipojo.extender";
+
+    
+    public void testMetadata() {
+        Element meta = Utils.getMetatadata(context, type);
+        assertNotNull("Check meta", meta);
+        Element[] ext = meta.getElements("extender", namespace);
+        assertEquals("Check size", 1, ext.length);
+        String extension = ext[0].getAttribute("extension");
+        String onArr = ext[0].getAttribute("onArrival");
+        String onDep = ext[0].getAttribute("onDeparture");
+        
+        assertEquals("Check extension", "foo", extension);
+        assertEquals("Check onArrival", "onArrival", onArr);
+        assertEquals("Check onDeparture", "onDeparture", onDep);
+    }
+
+}
diff --git a/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/JMX.java b/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/JMX.java
index 7714d3b..656d987 100644
--- a/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/JMX.java
+++ b/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/JMX.java
@@ -8,7 +8,31 @@
     
     public void testSimple() {
         Element meta = Utils.getMetatadata(context, "org.apache.felix.ipojo.test.scenarios.component.jmx.JMXSimple");
-        System.out.println("meta: " + meta);
+        /*
+         * org.apache.felix.ipojo.handlers.jmx:config domain="my-domain" usesmosgi="false"
+        org.apache.felix.ipojo.handlers.jmx:property field="m_foo" name="prop" rights="w" notification="true"
+        org.apache.felix.ipojo.handlers.jmx:method description="get the foo prop" method="getFoo"
+        org.apache.felix.ipojo.handlers.jmx:method description="set the foo prop" method="setFoo"
+         */
+        
+        Element[] ele = meta.getElements("config", "org.apache.felix.ipojo.handlers.jmx");
+        assertNotNull("ele not null", ele);
+        assertEquals("Ele size", 1, ele.length);
+        String domain = ele[0].getAttribute("domain");
+        String mosgi = ele[0].getAttribute("usesmosgi");
+        assertEquals("domain", "my-domain", domain);
+        assertEquals("mosgi", "false", mosgi);
+        
+        Element[] props = ele[0].getElements("property", "org.apache.felix.ipojo.handlers.jmx");
+        assertNotNull("props not null", props);
+        assertEquals("props size", 1, props.length);
+        
+        Element[] methods = ele[0].getElements("method", "org.apache.felix.ipojo.handlers.jmx");
+        assertNotNull("methods not null", methods);
+        assertEquals("methods size", 2, methods.length);
+        
+
+
     }
 
 }
diff --git a/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/WhiteBoard.java b/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/WhiteBoard.java
new file mode 100644
index 0000000..4f9022a
--- /dev/null
+++ b/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/WhiteBoard.java
@@ -0,0 +1,49 @@
+package org.apache.felix.ipojo.test.scenarios.annotations;
+
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.metadata.Element;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+
+public class WhiteBoard extends OSGiTestCase {
+    
+    String typeWI = "org.apache.felix.ipojo.test.scenarios.component.whiteboard.WhiteBoardWIModification";
+    String typeWO = "org.apache.felix.ipojo.test.scenarios.component.whiteboard.WhiteBoardWOModification";
+    String namespace = "org.apache.felix.ipojo.whiteboard";
+    
+    public void testMetadataWithOnModification() {
+        Element meta = Utils.getMetatadata(context, typeWI);
+        assertNotNull("Check meta", meta);
+        Element[] ext = meta.getElements("wbp", namespace);
+        assertEquals("Check size", 1, ext.length);
+        String filter = ext[0].getAttribute("filter");
+        String onArr = ext[0].getAttribute("onArrival");
+        String onDep = ext[0].getAttribute("onDeparture");
+        String onMod = ext[0].getAttribute("onModification");
+
+        
+        assertEquals("Check filter", "(foo=true)", filter);
+        assertEquals("Check onArrival", "onArrival", onArr);
+        assertEquals("Check onDeparture", "onDeparture", onDep);
+        assertEquals("Check onModification", "onModification", onMod);
+
+    }
+    
+    public void testMetadataWithoutOnModification() {
+        Element meta = Utils.getMetatadata(context, typeWO);
+        assertNotNull("Check meta", meta);
+        Element[] ext = meta.getElements("wbp", namespace);
+        assertEquals("Check size", 1, ext.length);
+        String filter = ext[0].getAttribute("filter");
+        String onArr = ext[0].getAttribute("onArrival");
+        String onDep = ext[0].getAttribute("onDeparture");
+        String onMod = ext[0].getAttribute("onModification");
+
+        
+        assertEquals("Check filter", "(foo=true)", filter);
+        assertEquals("Check onArrival", "onArrival", onArr);
+        assertEquals("Check onDeparture", "onDeparture", onDep);
+        assertNull("Check onModification", onMod);
+
+    }
+
+}
diff --git a/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/event/PubSub.java b/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/event/PubSub.java
new file mode 100644
index 0000000..be15ac2
--- /dev/null
+++ b/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/event/PubSub.java
@@ -0,0 +1,37 @@
+package org.apache.felix.ipojo.test.scenarios.component.event;
+
+import org.apache.felix.ipojo.annotations.Component;
+import org.apache.felix.ipojo.handlers.event.Subscriber;
+import org.osgi.service.event.Event;
+
+
+@Component
+public class PubSub {
+    @org.apache.felix.ipojo.handlers.event.Publisher(name="p1", synchronous=true)
+    org.apache.felix.ipojo.handlers.event.publisher.Publisher publisher1;
+    
+    @org.apache.felix.ipojo.handlers.event.Publisher(name="p2", synchronous=false, topics="foo,bar", data_key="data")
+    org.apache.felix.ipojo.handlers.event.publisher.Publisher publisher2;
+    
+    @org.apache.felix.ipojo.handlers.event.Publisher(name="p3", synchronous=true, topics="bar")
+    org.apache.felix.ipojo.handlers.event.publisher.Publisher publisher3;
+    
+    @Subscriber(name="s1", data_key="data")
+    public void receive1(Object foo) {
+        // Nothing
+    }
+    
+    @Subscriber(name="s2", topics="foo,bar", filter="(foo=true)")
+    public void receive2(Event foo) {
+        // Nothing
+    }
+    
+    
+    @Subscriber(name="s3", topics="foo", data_key="data", data_type="java.lang.String")
+    public void receive3(String foo) {
+        // Nothing
+    }
+    
+    
+    
+}
diff --git a/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/extender/Extender.java b/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/extender/Extender.java
new file mode 100644
index 0000000..230388a
--- /dev/null
+++ b/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/extender/Extender.java
@@ -0,0 +1,18 @@
+package org.apache.felix.ipojo.test.scenarios.component.extender;
+
+import org.apache.felix.ipojo.annotations.Component;
+import org.osgi.framework.Bundle;
+
+
+@Component
+@org.apache.felix.ipojo.extender.Extender(extension="foo", onArrival="onArrival", onDeparture="onDeparture")
+public class Extender {
+    
+    public void onArrival(Bundle bundle, String foo) {
+        // nothing
+    }
+    
+    public void onDeparture(Bundle bundle) {
+        // nothing
+    }
+}
diff --git a/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/jmx/JMXSimple.java b/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/jmx/JMXSimple.java
index 7cbc1ae..54cbbe7 100644
--- a/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/jmx/JMXSimple.java
+++ b/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/jmx/JMXSimple.java
@@ -1,11 +1,12 @@
 package org.apache.felix.ipojo.test.scenarios.component.jmx;
 
 import org.apache.felix.ipojo.annotations.Component;
+import org.apache.felix.ipojo.handlers.jmx.Config;
 import org.apache.felix.ipojo.handlers.jmx.Method;
 import org.apache.felix.ipojo.handlers.jmx.Property;
 
 @Component
-@org.apache.felix.ipojo.handlers.jmx.Config(domain="my-domain", usesMOSGi=false)
+@Config(domain="my-domain", usesMOSGi=false)
 public class JMXSimple {
 
     @Property(name="prop", notification=true, rights="w")
diff --git a/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/whiteboard/WhiteBoardWIModification.java b/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/whiteboard/WhiteBoardWIModification.java
new file mode 100644
index 0000000..840d899
--- /dev/null
+++ b/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/whiteboard/WhiteBoardWIModification.java
@@ -0,0 +1,25 @@
+package org.apache.felix.ipojo.test.scenarios.component.whiteboard;
+
+import org.apache.felix.ipojo.annotations.Component;
+import org.osgi.framework.ServiceReference;
+
+@Component
+@org.apache.felix.ipojo.whiteboard.Wbp(filter="(foo=true)", 
+        onArrival="onArrival", 
+        onDeparture="onDeparture",
+        onModification="onModification")
+public class WhiteBoardWIModification {
+    
+    public void onArrival(ServiceReference ref) {
+        // nothing
+    }
+    
+    public void onDeparture(ServiceReference ref) {
+        // nothing
+    }
+    
+    public void onModification(ServiceReference ref) {
+        // nothing
+    }
+
+}
diff --git a/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/whiteboard/WhiteBoardWOModification.java b/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/whiteboard/WhiteBoardWOModification.java
new file mode 100644
index 0000000..1424db1
--- /dev/null
+++ b/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/whiteboard/WhiteBoardWOModification.java
@@ -0,0 +1,18 @@
+package org.apache.felix.ipojo.test.scenarios.component.whiteboard;
+
+import org.apache.felix.ipojo.annotations.Component;
+import org.osgi.framework.ServiceReference;
+
+@Component
+@org.apache.felix.ipojo.whiteboard.Wbp(filter="(foo=true)", onArrival="onArrival", onDeparture="onDeparture")
+public class WhiteBoardWOModification {
+    
+    public void onArrival(ServiceReference ref) {
+        // nothing
+    }
+    
+    public void onDeparture(ServiceReference ref) {
+        // nothing
+    }
+
+}