felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clem...@apache.org
Subject svn commit: r766037 - in /felix/trunk/ipojo: api/src/main/java/org/apache/felix/ipojo/api/ api/src/main/java/org/apache/felix/ipojo/api/composite/ tests/api/ tests/api/src/test/java/org/apache/felix/ipojo/tests/api/ tests/api/src/test/java/org/example/...
Date Fri, 17 Apr 2009 14:46:06 GMT
Author: clement
Date: Fri Apr 17 14:46:05 2009
New Revision: 766037

URL: http://svn.apache.org/viewvc?rev=766037&view=rev
Log:
The iPOJO API now supports external handlers. To use them, the handler provider has to implements
HandlerConfiguration that returns the Element-Attribute structure representing the handler
configuration.

Added:
    felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/HandlerConfiguration.java
  (with props)
    felix/trunk/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/ExternalHandlerTest.java
  (with props)
    felix/trunk/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/Whiteboard.java
  (with props)
    felix/trunk/ipojo/tests/api/src/test/java/org/example/service/impl/HostImpl.java   (with
props)
Modified:
    felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/ComponentType.java
    felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/Dependency.java
    felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/PrimitiveComponentType.java
    felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/Service.java
    felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/TemporalDependency.java
    felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/composite/CompositeComponentType.java
    felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/composite/ExportedService.java
    felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/composite/ImportedService.java
    felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/composite/Instance.java
    felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/composite/InstantiatedService.java
    felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/composite/ProvidedService.java
    felix/trunk/ipojo/tests/api/pom.xml

Modified: felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/ComponentType.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/ComponentType.java?rev=766037&r1=766036&r2=766037&view=diff
==============================================================================
--- felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/ComponentType.java (original)
+++ felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/ComponentType.java Fri
Apr 17 14:46:05 2009
@@ -43,6 +43,7 @@
      * current component type.
      */
     private List m_instances = new ArrayList();
+   
     
     /**
      * Gets the factory attached to the current
@@ -64,7 +65,7 @@
      * component type.
      */
     public abstract void stop();
-    
+
     
     /**
      * Creates a component instance from the current type 
@@ -189,9 +190,6 @@
             }
         }
     }
-    
-    
-    
 
 
 }

Modified: felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/Dependency.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/Dependency.java?rev=766037&r1=766036&r2=766037&view=diff
==============================================================================
--- felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/Dependency.java (original)
+++ felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/Dependency.java Fri Apr
17 14:46:05 2009
@@ -28,7 +28,7 @@
  * Allows configuring a service dependencies.
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
-public class Dependency {
+public class Dependency implements HandlerConfiguration {
     
     /**
      * The dynamic binding policy.

Added: felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/HandlerConfiguration.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/HandlerConfiguration.java?rev=766037&view=auto
==============================================================================
--- felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/HandlerConfiguration.java
(added)
+++ felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/HandlerConfiguration.java
Fri Apr 17 14:46:05 2009
@@ -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.ipojo.api;
+
+import org.apache.felix.ipojo.metadata.Element;
+
+/**
+ * Common interfaces for all contributions.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public interface HandlerConfiguration {
+    
+    /**
+     * Gets the Handler description.
+     * @return the Element-Attribute structure containing the handler
+     * configuration.
+     */
+    public Element getElement();
+
+}

Propchange: felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/HandlerConfiguration.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/PrimitiveComponentType.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/PrimitiveComponentType.java?rev=766037&r1=766036&r2=766037&view=diff
==============================================================================
--- felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/PrimitiveComponentType.java
(original)
+++ felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/PrimitiveComponentType.java
Fri Apr 17 14:46:05 2009
@@ -125,6 +125,12 @@
     private ArrayList m_temporals = new ArrayList();
     
     /**
+     * List of Handler representing external
+     * handler configuration
+     */
+    private List m_handlers = new ArrayList();
+    
+    /**
      * Checks that the component type is not already
      * started.
      */
@@ -356,9 +362,28 @@
             element.addElement(properties);
         }
         
+        // External handlers
+        for (int i = 0; i < m_handlers.size(); i++) {
+            HandlerConfiguration hc = (HandlerConfiguration) m_handlers.get(i);
+            element.addElement(hc.getElement());
+        }
+        
         return element;
     }
     
+
+    /**
+     * Adds an HandlerConfiguration to the component type. Each component type
+     * implementation must uses the populated list (m_handlers) when generating
+     * the component metadata.
+     * @param handler the handler configuration to add
+     * @return the current component type
+     */
+    public PrimitiveComponentType addHandler(HandlerConfiguration handler) {
+        m_handlers.add(handler);
+        return this;
+    }
+    
     /**
      * Creates the component factory.
      */

Modified: felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/Service.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/Service.java?rev=766037&r1=766036&r2=766037&view=diff
==============================================================================
--- felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/Service.java (original)
+++ felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/Service.java Fri Apr 17
14:46:05 2009
@@ -33,7 +33,7 @@
  * Allows configuring a provided service.
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
-public class Service {
+public class Service implements HandlerConfiguration {
     
     /**
      * Creation strategy : singleton (default).

Modified: felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/TemporalDependency.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/TemporalDependency.java?rev=766037&r1=766036&r2=766037&view=diff
==============================================================================
--- felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/TemporalDependency.java
(original)
+++ felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/TemporalDependency.java
Fri Apr 17 14:46:05 2009
@@ -25,7 +25,7 @@
  * Allows configuring a service dependencies.
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
-public class TemporalDependency {
+public class TemporalDependency implements HandlerConfiguration {
     
     /**
      * OnTimeout policy: nullable object.

Modified: felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/composite/CompositeComponentType.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/composite/CompositeComponentType.java?rev=766037&r1=766036&r2=766037&view=diff
==============================================================================
--- felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/composite/CompositeComponentType.java
(original)
+++ felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/composite/CompositeComponentType.java
Fri Apr 17 14:46:05 2009
@@ -25,6 +25,7 @@
 import org.apache.felix.ipojo.ConfigurationException;
 import org.apache.felix.ipojo.Factory;
 import org.apache.felix.ipojo.api.ComponentType;
+import org.apache.felix.ipojo.api.HandlerConfiguration;
 import org.apache.felix.ipojo.composite.CompositeFactory;
 import org.apache.felix.ipojo.metadata.Attribute;
 import org.apache.felix.ipojo.metadata.Element;
@@ -82,7 +83,16 @@
      */
     private boolean m_public = true;
 
+    /**
+     * Component type name.
+     */
     private String m_name;
+    
+    /**
+     * List of Handler representing external
+     * handler configuration
+     */
+    private List m_handlers = new ArrayList();
 
     /**
      * Checks that the component type is not already
@@ -199,6 +209,17 @@
     }
     
     /**
+     * Adds an HandlerConfiguration to the component type. Each component type
+     * implementation must uses the populated list (m_handlers) when generating
+     * the component metadata.
+     * @param handler the handler configuration to add
+     * @return the current component type.
+     */
+    public void CompositeComponentType(HandlerConfiguration handler) {
+        m_handlers.add(handler);
+    }
+    
+    /**
      * Generates the component description.
      * @return the component type description of 
      * the current component type
@@ -231,6 +252,13 @@
             ProvidedService inst = (ProvidedService) m_provided.get(i);
             element.addElement(inst.getElement());
         }
+        
+        // External handlers
+        for (int i = 0; i < m_handlers.size(); i++) {
+            HandlerConfiguration hc = (HandlerConfiguration) m_handlers.get(i);
+            element.addElement(hc.getElement());
+        }
+        
         return element;
     }
     

Modified: felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/composite/ExportedService.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/composite/ExportedService.java?rev=766037&r1=766036&r2=766037&view=diff
==============================================================================
--- felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/composite/ExportedService.java
(original)
+++ felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/composite/ExportedService.java
Fri Apr 17 14:46:05 2009
@@ -18,11 +18,12 @@
  */
 package org.apache.felix.ipojo.api.composite;
 
+import org.apache.felix.ipojo.api.HandlerConfiguration;
 import org.apache.felix.ipojo.metadata.Attribute;
 import org.apache.felix.ipojo.metadata.Element;
 import org.apache.felix.ipojo.util.DependencyModel;
 
-public class ExportedService {
+public class ExportedService implements HandlerConfiguration {
     
     /**
      * The required specification.

Modified: felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/composite/ImportedService.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/composite/ImportedService.java?rev=766037&r1=766036&r2=766037&view=diff
==============================================================================
--- felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/composite/ImportedService.java
(original)
+++ felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/composite/ImportedService.java
Fri Apr 17 14:46:05 2009
@@ -18,11 +18,12 @@
  */
 package org.apache.felix.ipojo.api.composite;
 
+import org.apache.felix.ipojo.api.HandlerConfiguration;
 import org.apache.felix.ipojo.metadata.Attribute;
 import org.apache.felix.ipojo.metadata.Element;
 import org.apache.felix.ipojo.util.DependencyModel;
 
-public class ImportedService {
+public class ImportedService implements HandlerConfiguration {
     
     public static final String COMPOSITE_SCOPE = "composite";
     

Modified: felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/composite/Instance.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/composite/Instance.java?rev=766037&r1=766036&r2=766037&view=diff
==============================================================================
--- felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/composite/Instance.java
(original)
+++ felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/composite/Instance.java
Fri Apr 17 14:46:05 2009
@@ -28,10 +28,11 @@
 import java.util.Vector;
 import java.util.Map.Entry;
 
+import org.apache.felix.ipojo.api.HandlerConfiguration;
 import org.apache.felix.ipojo.metadata.Attribute;
 import org.apache.felix.ipojo.metadata.Element;
 
-public class Instance {
+public class Instance implements HandlerConfiguration {
     private String m_type;
     private List m_conf = new ArrayList();
     

Modified: felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/composite/InstantiatedService.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/composite/InstantiatedService.java?rev=766037&r1=766036&r2=766037&view=diff
==============================================================================
--- felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/composite/InstantiatedService.java
(original)
+++ felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/composite/InstantiatedService.java
Fri Apr 17 14:46:05 2009
@@ -28,11 +28,12 @@
 import java.util.Vector;
 import java.util.Map.Entry;
 
+import org.apache.felix.ipojo.api.HandlerConfiguration;
 import org.apache.felix.ipojo.metadata.Attribute;
 import org.apache.felix.ipojo.metadata.Element;
 import org.apache.felix.ipojo.util.DependencyModel;
 
-public class InstantiatedService {
+public class InstantiatedService implements HandlerConfiguration {
     
     /**
      * The required specification.

Modified: felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/composite/ProvidedService.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/composite/ProvidedService.java?rev=766037&r1=766036&r2=766037&view=diff
==============================================================================
--- felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/composite/ProvidedService.java
(original)
+++ felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/composite/ProvidedService.java
Fri Apr 17 14:46:05 2009
@@ -21,10 +21,11 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.felix.ipojo.api.HandlerConfiguration;
 import org.apache.felix.ipojo.metadata.Attribute;
 import org.apache.felix.ipojo.metadata.Element;
 
-public class ProvidedService {
+public class ProvidedService implements HandlerConfiguration {
     public static final String ALL_POLICY = "all";
     public static final String ONE_POLICY = "one";
     

Modified: felix/trunk/ipojo/tests/api/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/api/pom.xml?rev=766037&r1=766036&r2=766037&view=diff
==============================================================================
--- felix/trunk/ipojo/tests/api/pom.xml (original)
+++ felix/trunk/ipojo/tests/api/pom.xml Fri Apr 17 14:46:05 2009
@@ -72,6 +72,12 @@
 			<version>1.3.0-SNAPSHOT</version>
 		</dependency>
 		
+		<!-- For external handlermanagement -->
+		<dependency>
+			<groupId>org.apache.felix</groupId>
+			<artifactId>org.apache.felix.ipojo.handler.whiteboard</artifactId>
+			<version>1.3.0-SNAPSHOT</version>
+		</dependency>	
 		
 	<!--
 		Pax Exam API:
@@ -108,7 +114,7 @@
 		<version>4.5</version>
 		<type>jar</type>
 		<scope>test</scope>
-	</dependency>	
+	</dependency>
 	</dependencies>
 	
 	<repositories>

Added: felix/trunk/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/ExternalHandlerTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/ExternalHandlerTest.java?rev=766037&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/ExternalHandlerTest.java
(added)
+++ felix/trunk/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/ExternalHandlerTest.java
Fri Apr 17 14:46:05 2009
@@ -0,0 +1,107 @@
+package org.apache.felix.ipojo.tests.api;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.junit.Assert.assertThat;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.provision;
+import static org.ops4j.pax.exam.MavenUtils.asInProject;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.api.PrimitiveComponentType;
+import org.apache.felix.ipojo.architecture.HandlerDescription;
+import org.example.service.impl.HostImpl;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Inject;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.BundleContext;
+
+
+
+@RunWith( JUnit4TestRunner.class )
+public class ExternalHandlerTest {
+    
+    @Inject
+    private BundleContext context;
+    
+    private OSGiHelper osgi;
+    
+    private IPOJOHelper ipojo;
+    
+    @Before
+    public void init() {
+        osgi = new OSGiHelper(context);
+        ipojo = new IPOJOHelper(context);
+    }
+    
+    @After
+    public void stop() {
+        ipojo.dispose();
+        osgi.dispose();
+    }
+    
+    @Configuration
+    public static Option[] configure() {    
+        Option[] opt =  options(
+                provision(
+                        mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo").version(asInProject()),
+                        mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo.api").version(asInProject()),
+                        mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo.handler.whiteboard").version(asInProject())
+                    )
+                );
+        return opt;
+    }
+    
+    @Test
+    public void createAHost() throws Exception {
+        PrimitiveComponentType type = createAWhiteboardHost();
+        ComponentInstance ci = type.createInstance();
+        assertThat (ci.getState(), is (ComponentInstance.VALID));
+        HandlerDescription hd = ci.getInstanceDescription().getHandlerDescription(Whiteboard.NAMESPACE
+ ":" + Whiteboard.NAME);
+        assertThat (hd, is (notNullValue()));
+    }
+    
+    @Test
+    public void createDoubleHost() throws Exception {
+        PrimitiveComponentType type = createASecondWhiteboardHost();
+        ComponentInstance ci = type.createInstance();
+        assertThat (ci.getState(), is (ComponentInstance.VALID));
+        HandlerDescription hd = ci.getInstanceDescription().getHandlerDescription(Whiteboard.NAMESPACE
+ ":" + Whiteboard.NAME);
+        assertThat (hd, is (notNullValue()));
+    }
+    
+    private PrimitiveComponentType createAWhiteboardHost() {
+        return new PrimitiveComponentType()
+        .setBundleContext(context)
+        .setClassName(HostImpl.class.getName())
+        .addHandler(new Whiteboard()
+            .onArrival("arrival")
+            .onDeparture("departure")
+            .setFilter("(foo=foo)")
+         );
+    }
+    
+    private PrimitiveComponentType createASecondWhiteboardHost() {
+        return new PrimitiveComponentType()
+        .setBundleContext(context)
+        .setClassName(HostImpl.class.getName())
+        .addHandler(new Whiteboard()
+            .onArrival("arrival")
+            .onDeparture("departure")
+            .setFilter("(foo=foo)")
+         )
+         .addHandler(new Whiteboard()
+         .onArrival("arrival")
+         .onDeparture("departure")
+         .setFilter("(foo=bar)")
+         .onModification("modification")
+      );
+    }
+
+}

Propchange: felix/trunk/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/ExternalHandlerTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: felix/trunk/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/Whiteboard.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/Whiteboard.java?rev=766037&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/Whiteboard.java
(added)
+++ felix/trunk/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/Whiteboard.java
Fri Apr 17 14:46:05 2009
@@ -0,0 +1,71 @@
+package org.apache.felix.ipojo.tests.api;
+
+import org.apache.felix.ipojo.api.HandlerConfiguration;
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
+
+public class Whiteboard implements HandlerConfiguration {
+    
+    public static final String NAME = "wbp";
+    
+    public static final String NAMESPACE = "org.apache.felix.ipojo.whiteboard";
+    
+    private String arrival;
+    
+    private String departure;
+    
+    private String modification;
+    
+    private String filter;
+    
+    public Whiteboard onArrival(String method) {
+        arrival = method;
+        return this;
+    }
+    
+    public Whiteboard onDeparture(String method) {
+        departure = method;
+        return this;
+    }
+    
+    public Whiteboard onModification(String method) {
+        modification = method;
+        return this;
+    }
+    
+    public Whiteboard setFilter(String fil) {
+        filter = fil;
+        return this;
+    }
+
+    public Element getElement() {
+        ensureValidity();
+        // Create the root element.
+        Element element = new Element(NAME, NAMESPACE);
+        // Mandatory attributes
+        element.addAttribute(new Attribute("onArrival", arrival));
+        element.addAttribute(new Attribute("onDeparture", departure));
+        element.addAttribute(new Attribute("filter", filter));
+        
+        // Optional attribute
+        if (modification != null) {
+            element.addAttribute(new Attribute("onModification", modification));
+        }        
+        
+        return element;
+    }
+
+    private void ensureValidity() {
+        if (arrival == null) {
+            throw new IllegalStateException("The whiteboard pattern configuration must have
a onArrival method");
+        }
+        if (departure == null) {
+            throw new IllegalStateException("The whiteboard pattern configuration must have
a onDeparture method");
+        }
+        if (filter == null) {
+            throw new IllegalStateException("The whiteboard pattern configuration must have
a filter");
+        }
+        
+    }
+
+}

Propchange: felix/trunk/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/Whiteboard.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: felix/trunk/ipojo/tests/api/src/test/java/org/example/service/impl/HostImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/api/src/test/java/org/example/service/impl/HostImpl.java?rev=766037&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/api/src/test/java/org/example/service/impl/HostImpl.java (added)
+++ felix/trunk/ipojo/tests/api/src/test/java/org/example/service/impl/HostImpl.java Fri Apr
17 14:46:05 2009
@@ -0,0 +1,19 @@
+package org.example.service.impl;
+
+import org.osgi.framework.ServiceReference;
+
+public class HostImpl {
+    
+    public void arrival(ServiceReference ref) {
+        
+    }
+    
+    public void departure(ServiceReference ref) {
+        
+    }
+    
+    public void modification(ServiceReference ref) {
+        
+    }
+
+}

Propchange: felix/trunk/ipojo/tests/api/src/test/java/org/example/service/impl/HostImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message