You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2008/09/11 17:23:40 UTC

svn commit: r694294 - in /felix/sandbox/clement/filter-injection: ./ filter.injection/ filter.injection/src/ filter.injection/src/main/ filter.injection/src/main/java/ filter.injection/src/main/java/org/ filter.injection/src/main/java/org/apache/ filte...

Author: clement
Date: Thu Sep 11 08:23:31 2008
New Revision: 694294

URL: http://svn.apache.org/viewvc?rev=694294&view=rev
Log:
Provide a handler allowing a pojo to reconfigure dynamically filters of its own service dependencies.
Provide the test suite of this pojo.

Added:
    felix/sandbox/clement/filter-injection/   (with props)
    felix/sandbox/clement/filter-injection/filter.injection/   (with props)
    felix/sandbox/clement/filter-injection/filter.injection/LICENSE
    felix/sandbox/clement/filter-injection/filter.injection/NOTICE
    felix/sandbox/clement/filter-injection/filter.injection/pom.xml
    felix/sandbox/clement/filter-injection/filter.injection/src/
    felix/sandbox/clement/filter-injection/filter.injection/src/main/
    felix/sandbox/clement/filter-injection/filter.injection/src/main/java/
    felix/sandbox/clement/filter-injection/filter.injection/src/main/java/org/
    felix/sandbox/clement/filter-injection/filter.injection/src/main/java/org/apache/
    felix/sandbox/clement/filter-injection/filter.injection/src/main/java/org/apache/felix/
    felix/sandbox/clement/filter-injection/filter.injection/src/main/java/org/apache/felix/ipojo/
    felix/sandbox/clement/filter-injection/filter.injection/src/main/java/org/apache/felix/ipojo/handler/
    felix/sandbox/clement/filter-injection/filter.injection/src/main/java/org/apache/felix/ipojo/handler/filter/
    felix/sandbox/clement/filter-injection/filter.injection/src/main/java/org/apache/felix/ipojo/handler/filter/injection/
    felix/sandbox/clement/filter-injection/filter.injection/src/main/java/org/apache/felix/ipojo/handler/filter/injection/FilterInjector.java
    felix/sandbox/clement/filter-injection/filter.injection/src/main/java/org/apache/felix/ipojo/handler/filter/injection/FilterInjectorHandler.java
    felix/sandbox/clement/filter-injection/filter.injection/src/main/resources/
    felix/sandbox/clement/filter-injection/filter.injection/src/main/resources/metadata.xml
    felix/sandbox/clement/filter-injection/tests.filter-injection/   (with props)
    felix/sandbox/clement/filter-injection/tests.filter-injection/pom.xml
    felix/sandbox/clement/filter-injection/tests.filter-injection/src/
    felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/
    felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/
    felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/
    felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/
    felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/
    felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/
    felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/
    felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/
    felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/component/
    felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CheckServiceProvider.java
    felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProvider.java
    felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/component/MultipleCheckServiceProvider.java
    felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/filter/
    felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/filter/AggregateFilterInjection.java
    felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/filter/FilterInjectorTestSuite.java
    felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/filter/SimpleFilterInjection.java
    felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/filter/service/
    felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/filter/service/BarService.java
    felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/filter/service/CheckService.java
    felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/filter/service/FooService.java
    felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/
    felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/util/
    felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java
    felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/resources/
    felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/resources/metadata.xml

Propchange: felix/sandbox/clement/filter-injection/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Sep 11 08:23:31 2008
@@ -0,0 +1,6 @@
+target
+bin
+.classpath
+.checkstyle
+.project
+maven-eclipse.*

Propchange: felix/sandbox/clement/filter-injection/filter.injection/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Sep 11 08:23:31 2008
@@ -0,0 +1,8 @@
+target
+bin
+.classpath
+.checkstyle
+.project
+maven-eclipse.*
+.externalToolBuilders
+.settings

Added: felix/sandbox/clement/filter-injection/filter.injection/LICENSE
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/filter-injection/filter.injection/LICENSE?rev=694294&view=auto
==============================================================================
--- felix/sandbox/clement/filter-injection/filter.injection/LICENSE (added)
+++ felix/sandbox/clement/filter-injection/filter.injection/LICENSE Thu Sep 11 08:23:31 2008
@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.

Added: felix/sandbox/clement/filter-injection/filter.injection/NOTICE
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/filter-injection/filter.injection/NOTICE?rev=694294&view=auto
==============================================================================
--- felix/sandbox/clement/filter-injection/filter.injection/NOTICE (added)
+++ felix/sandbox/clement/filter-injection/filter.injection/NOTICE Thu Sep 11 08:23:31 2008
@@ -0,0 +1,18 @@
+Apache Felix iPOJO Filter-Injector Handler
+Copyright 2008 The Apache Software Foundation
+
+I. Included Software
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+Licensed under the Apache License 2.0.
+
+II. Used Software
+
+This product uses software developed at
+The OSGi Alliance (http://www.osgi.org/).
+Copyright 2006 The OSGi Alliance.
+Licensed under the Apache License 2.0.
+
+III. License Summary
+- Apache License 2.0

Added: felix/sandbox/clement/filter-injection/filter.injection/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/filter-injection/filter.injection/pom.xml?rev=694294&view=auto
==============================================================================
--- felix/sandbox/clement/filter-injection/filter.injection/pom.xml (added)
+++ felix/sandbox/clement/filter-injection/filter.injection/pom.xml Thu Sep 11 08:23:31 2008
@@ -0,0 +1,102 @@
+<!--
+	Licensed to the Apache Software Foundation (ASF) under one
+	or more contributor license agreements.  See the NOTICE file
+	distributed with this work for additional information
+	regarding copyright ownership.  The ASF licenses this file
+	to you under the Apache License, Version 2.0 (the
+	"License"); you may not use this file except in compliance
+	with the License.  You may obtain a copy of the License at
+	
+	http://www.apache.org/licenses/LICENSE-2.0
+	
+	Unless required by applicable law or agreed to in writing,
+	software distributed under the License is distributed on an
+	"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+	KIND, either express or implied.  See the License for the
+	specific language governing permissions and limitations
+	under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+	<parent>
+		<groupId>org.apache.felix</groupId>
+		<artifactId>felix</artifactId>
+		<version>1.0.2</version>
+		<relativePath>../../pom/pom.xml</relativePath>
+	</parent>
+	<modelVersion>4.0.0</modelVersion>
+	<packaging>bundle</packaging>
+	<artifactId>org.apache.felix.ipojo.handler.filter-injection</artifactId>
+	<groupId>org.apache.felix</groupId>
+	<version>0.9.0-SNAPSHOT</version>
+	<name>Apache Felix iPOJO Filter Injection handler</name>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.apache.felix</groupId>
+			<artifactId>org.osgi.core</artifactId>
+			<version>1.0.0</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.felix</groupId>
+			<artifactId>org.osgi.compendium</artifactId>
+			<version>1.0.0</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.felix</groupId>
+			<artifactId>org.apache.felix.ipojo.metadata</artifactId>
+			<version>0.9.0-SNAPSHOT</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.felix</groupId>
+			<artifactId>org.apache.felix.ipojo</artifactId>
+			<version>0.9.0-SNAPSHOT</version>
+		</dependency>
+	</dependencies>
+
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.felix</groupId>
+				<artifactId>maven-bundle-plugin</artifactId>
+				<version>1.4.2</version>
+				<extensions>true</extensions>
+				<configuration>
+					<instructions>
+						<Private-Package>
+							org.apache.felix.ipojo.handler.filter.injection
+						</Private-Package>
+						<Bundle-Name>${pom.name}</Bundle-Name>
+						<Bundle-SymbolicName>
+							org.apache.felix.ipojo.handler.filter.injection
+						</Bundle-SymbolicName>
+						<Bundle-Vendor>
+							The Apache Software Foundation
+						</Bundle-Vendor>
+						<Bundle-Description>
+							iPOJO Filter Injection Handler
+						</Bundle-Description>
+						<Include-Resource>
+							META-INF/LICENCE=LICENSE,
+							META-INF/NOTICE=NOTICE
+						</Include-Resource>
+					</instructions>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.felix</groupId>
+				<artifactId>maven-ipojo-plugin</artifactId>
+				<version>0.9.0-SNAPSHOT</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/filter-injection/filter.injection/src/main/java/org/apache/felix/ipojo/handler/filter/injection/FilterInjector.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/filter-injection/filter.injection/src/main/java/org/apache/felix/ipojo/handler/filter/injection/FilterInjector.java?rev=694294&view=auto
==============================================================================
--- felix/sandbox/clement/filter-injection/filter.injection/src/main/java/org/apache/felix/ipojo/handler/filter/injection/FilterInjector.java (added)
+++ felix/sandbox/clement/filter-injection/filter.injection/src/main/java/org/apache/felix/ipojo/handler/filter/injection/FilterInjector.java Thu Sep 11 08:23:31 2008
@@ -0,0 +1,125 @@
+/* 
+ * 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.handler.filter.injection;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.FieldInterceptor;
+import org.apache.felix.ipojo.PrimitiveHandler;
+import org.apache.felix.ipojo.handlers.dependency.Dependency;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+
+/**
+ * Filter injector.
+ * Manages a field attached to a dependency filter.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class FilterInjector implements
+        FieldInterceptor {
+    
+    /**
+     * Actual Filter.
+     */
+    private String m_actualFilter;
+    
+    /**
+     * Attached service dependency.
+     */
+    private Dependency m_dependency;
+    
+    /**
+     * Bundle Context.
+     */
+    private BundleContext m_context;
+    
+    /**
+     * Handler. 
+     */
+    private PrimitiveHandler m_handler;
+    
+    /**
+     * Creates a field injector object.
+     * If the dependency is not optional, warns the user.
+     * @param dep : attached dependency
+     * @param bc : context
+     * @param handler : handler
+     */
+    public FilterInjector(Dependency dep, BundleContext bc, PrimitiveHandler handler) {
+        m_dependency = dep;
+        m_context = bc;
+        m_handler = handler;
+        
+        if (! dep.isOptional()) {
+            m_handler.warn("The dependency injector targets a non optional dependency, changing the filter can lead in incorrect behaviors");
+        }
+        
+        m_actualFilter = dep.getFilter();
+        
+    }
+
+    /**
+     * Returns the actual filters when the POJO needs it.
+     * @param pojo : pojo object
+     * @param field : field
+     * @param value : latest values
+     * @return the actual filter.
+     * @see org.apache.felix.ipojo.FieldInterceptor#onGet(java.lang.Object, java.lang.String, java.lang.Object)
+     */
+    public Object onGet(Object pojo, String field, Object value) {
+        return m_actualFilter;
+    }
+
+    /**
+     * Set the filter of the dependency.
+     * This method create the filter object. If the filter is incorrect, the filter is not changed.
+     * If the filter is correct, it apply the new filter, and invalidate the service object cache 
+     * of the current thread. Moreover, it checks that the instance state has not became invalid.
+     * @param pojo : pojo object
+     * @param field : field
+     * @param value : new value
+     * @see org.apache.felix.ipojo.FieldInterceptor#onSet(java.lang.Object, java.lang.String, java.lang.Object)
+     */
+    public void onSet(Object pojo, String field, Object value) {
+        boolean wasValid = m_handler.getInstanceManager().getState() == ComponentInstance.VALID;
+        if (value != null && ! value.equals(m_actualFilter) 
+                || value == null && m_actualFilter != null) {
+            String fil = (String) value;
+            Filter filter;
+            try {
+                filter = m_context.createFilter(fil);
+            } catch (InvalidSyntaxException e) {
+                m_handler.error("The new filter is incorrect " + fil + ", filter not set", e);
+                return;
+            }
+            m_dependency.setFilter(filter);
+            m_actualFilter = fil;
+            m_dependency.resetLocalCache();
+            
+            boolean isValid = m_handler.getInstanceManager().getState() == ComponentInstance.VALID;
+            if (wasValid && ! isValid) {
+                m_handler.warn("Updating the filter has invalidated the instance");
+            }
+        }
+        
+    }
+
+  
+
+}

Added: felix/sandbox/clement/filter-injection/filter.injection/src/main/java/org/apache/felix/ipojo/handler/filter/injection/FilterInjectorHandler.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/filter-injection/filter.injection/src/main/java/org/apache/felix/ipojo/handler/filter/injection/FilterInjectorHandler.java?rev=694294&view=auto
==============================================================================
--- felix/sandbox/clement/filter-injection/filter.injection/src/main/java/org/apache/felix/ipojo/handler/filter/injection/FilterInjectorHandler.java (added)
+++ felix/sandbox/clement/filter-injection/filter.injection/src/main/java/org/apache/felix/ipojo/handler/filter/injection/FilterInjectorHandler.java Thu Sep 11 08:23:31 2008
@@ -0,0 +1,122 @@
+/* 
+ * 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.handler.filter.injection;
+
+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.handlers.dependency.Dependency;
+import org.apache.felix.ipojo.handlers.dependency.DependencyHandler;
+import org.apache.felix.ipojo.metadata.Element;
+import org.apache.felix.ipojo.parser.FieldMetadata;
+import org.apache.felix.ipojo.parser.PojoMetadata;
+
+/**
+* Filter injector handler.
+* This handler allows the pojo implementation class to monitor a service
+* dependency field. This allows the code to get the current value and to 
+* update the filter. Be aware that, if the change makes the instance invalid,
+* the behavior of the pojo code is no more guaranty.
+* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+*/
+public class FilterInjectorHandler extends PrimitiveHandler {
+    
+    /**
+     * Handler namespace.
+     */
+    public static final String NAMESPACE = "org.apache.felix.ipojo.handler.filter";
+    
+    /**
+     * List of managed dependencies.
+     */
+    private List/*<deps>*/ m_dependencies = new ArrayList(1);
+
+    /**
+     * Configure method.
+     * Create filter injectors.
+     * @param meta : component type metadata.
+     * @param dictionary : instance configuration.
+     * @throws ConfigurationException : the dependency is not configured correctly
+     * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)
+     */
+    public void configure(Element meta, Dictionary dictionary) throws ConfigurationException {
+        PojoMetadata manipulation = getFactory().getPojoMetadata();
+        Element[] deps = meta.getElements("filter-injector", NAMESPACE);
+        for (int i = 0; i < deps.length; i++) {
+            String field = deps[i].getAttribute("field");
+            String id = deps[i].getAttribute("id");
+            
+            if (field == null  || id == null) {
+                throw new ConfigurationException("A filter injector cannot be configured correctly, both 'id' and 'field' attributes are required");
+            }
+            
+            Dependency dep = getDependencyById(id);
+            FieldMetadata fm = manipulation.getField(field);
+            if (fm == null) {
+                throw new ConfigurationException("A filter injector cannot be configured correctly, the field '" + field + "' does not exist in the implementation class");
+            }
+            if (!fm.getFieldType().equals(String.class.getName())) {
+                throw new ConfigurationException("A filter injector cannot be configured correctly, the field type of '" + field + "' must be String");
+            }
+            
+            FilterInjector fi = new FilterInjector(dep, getInstanceManager().getContext(), this);
+         
+            m_dependencies.add(fi);
+            
+            getInstanceManager().register(fm, fi);
+        }        
+    }
+
+    /**
+     * Returns a dependency object according to the given id.
+     * @param id : id of the dependency.
+     * @return the Dependency object.
+     * @throws ConfigurationException thrown when the dependency is not found.
+     */
+    private Dependency getDependencyById(String id) throws ConfigurationException {
+        DependencyHandler dh = (DependencyHandler) getHandler("org.apache.felix.ipojo:requires");
+        if (dh == null) {
+            throw new ConfigurationException("The service dependency handler is not found, no service dependency are declared");
+        }
+        Dependency[] deps = dh.getDependencies();
+        for (int i = 0; i < deps.length; i++) {
+            if (deps[i].getId().equals(id)) {
+                return deps[i];
+            }
+        }
+        throw new ConfigurationException("The dependency " + id + " is not a valid service dependency");
+    }
+
+    /**
+     * Nothing to do.
+     * @see org.apache.felix.ipojo.Handler#start()
+     */
+    public void start() { }
+
+    /**
+     * Nothing to do.
+     * @see org.apache.felix.ipojo.Handler#stop()
+     */
+    public void stop() { }
+    
+
+}

Added: felix/sandbox/clement/filter-injection/filter.injection/src/main/resources/metadata.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/filter-injection/filter.injection/src/main/resources/metadata.xml?rev=694294&view=auto
==============================================================================
--- felix/sandbox/clement/filter-injection/filter.injection/src/main/resources/metadata.xml (added)
+++ felix/sandbox/clement/filter-injection/filter.injection/src/main/resources/metadata.xml Thu Sep 11 08:23:31 2008
@@ -0,0 +1,24 @@
+<!--
+	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.
+-->
+<ipojo>
+	<handler
+		classname="org.apache.felix.ipojo.handler.filter.injection.FilterInjectorHandler"
+		name="filter-injector" namespace="org.apache.felix.ipojo.handler.filter">
+	</handler>
+</ipojo>
\ No newline at end of file

Propchange: felix/sandbox/clement/filter-injection/tests.filter-injection/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Sep 11 08:23:31 2008
@@ -0,0 +1,6 @@
+target
+bin
+.classpath
+.checkstyle
+.project
+maven-eclipse.*

Added: felix/sandbox/clement/filter-injection/tests.filter-injection/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/filter-injection/tests.filter-injection/pom.xml?rev=694294&view=auto
==============================================================================
--- felix/sandbox/clement/filter-injection/tests.filter-injection/pom.xml (added)
+++ felix/sandbox/clement/filter-injection/tests.filter-injection/pom.xml Thu Sep 11 08:23:31 2008
@@ -0,0 +1,93 @@
+<!--
+	Licensed to the Apache Software Foundation (ASF) under one
+	or more contributor license agreements.  See the NOTICE file
+	distributed with this work for additional information
+	regarding copyright ownership.  The ASF licenses this file
+	to you under the Apache License, Version 2.0 (the
+	"License"); you may not use this file except in compliance
+	with the License.  You may obtain a copy of the License at
+	
+	http://www.apache.org/licenses/LICENSE-2.0
+	
+	Unless required by applicable law or agreed to in writing,
+	software distributed under the License is distributed on an
+	"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+	KIND, either express or implied.  See the License for the
+	specific language governing permissions and limitations
+	under the License.
+-->
+<project>
+	<modelVersion>4.0.0</modelVersion>
+	<packaging>bundle</packaging>
+	<name>iPOJO Filter Injector Test Suite</name>
+	<artifactId>tests.filter-injector</artifactId>
+	<groupId>ipojo.tests</groupId>
+	<version>0.9.0-SNAPSHOT</version>
+	<dependencies>
+		<dependency>
+			<groupId>org.apache.felix</groupId>
+			<artifactId>org.apache.felix.ipojo</artifactId>
+			<version>0.9.0-SNAPSHOT</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.felix</groupId>
+			<artifactId>org.apache.felix.ipojo.metadata</artifactId>
+			<version>0.9.0-SNAPSHOT</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.felix</groupId>
+			<artifactId>org.osgi.core</artifactId>
+			<version>1.0.0</version>
+		</dependency>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<version>3.8.1</version>
+		</dependency>
+		<dependency>
+			<groupId>ipojo.examples</groupId>
+			<artifactId>org.apache.felix.ipojo.junit4osgi</artifactId>
+			<version>0.9.0-SNAPSHOT</version>
+		</dependency>
+
+
+	</dependencies>
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.felix</groupId>
+				<artifactId>maven-bundle-plugin</artifactId>
+				<version>1.4.2</version>
+				<extensions>true</extensions>
+				<configuration>
+					<instructions>
+						<Export-Package>
+							org.apache.felix.ipojo.test.scenarios.filter.service
+						</Export-Package>
+						<Bundle-SymbolicName>
+							${pom.artifactId}
+						</Bundle-SymbolicName>
+						<Private-Package>
+							org.apache.felix.ipojo.test*
+						</Private-Package>
+						<Test-Suite>
+				org.apache.felix.ipojo.test.scenarios.filter.FilterInjectorTestSuite
+						</Test-Suite>
+					</instructions>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.felix</groupId>
+				<artifactId>maven-ipojo-plugin</artifactId>
+				<version>0.9.0-SNAPSHOT</version>
+				<executions>
+					<execution>
+						<goals>
+							<goal>ipojo-bundle</goal>
+						</goals>
+					</execution>
+				</executions>
+			</plugin>
+		</plugins>
+	</build>
+</project>

Added: felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CheckServiceProvider.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CheckServiceProvider.java?rev=694294&view=auto
==============================================================================
--- felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CheckServiceProvider.java (added)
+++ felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CheckServiceProvider.java Thu Sep 11 08:23:31 2008
@@ -0,0 +1,89 @@
+/* 
+ * 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.test.scenarios.component;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.filter.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.filter.service.FooService;
+
+public class CheckServiceProvider implements CheckService {
+    
+    private Properties props = new Properties();
+    
+    /**
+     * Service dependency.
+     */
+    private FooService fs;
+    
+    private String filter;
+    
+    private int looked = 0;
+
+    public boolean check() {
+        props = new Properties();
+        if(filter != null) {
+            props.put("old-filter", new String(filter));
+        }
+        if (fs != null) {
+            props.put("old-foo", new Integer(fs.getInt()));
+        }
+        
+        if (looked == 0) {
+            looked = 1;
+        } else {
+            looked = 0;
+        }
+        
+        filter = "(id=" + looked + ")"; // Update the filter
+        System.out.println("Filter : " + filter);
+        if(filter != null) {
+            props.put("new-filter", new String(filter));
+        }
+        if (fs != null) {
+            props.put("new-foo", new Integer(fs.getInt()));
+        }
+        
+        return true;
+    }
+
+    public Properties getProps() {
+       return props;
+    }
+
+    public void setFilter(String filter) {
+        props = new Properties();
+        if(filter != null) {
+            props.put("old-filter", new String(this.filter));
+        }
+        if (fs != null) {
+            props.put("old-foo", new Integer(fs.getInt()));
+        }
+        
+        this.filter = filter; // Update the filter
+        
+        if(filter != null) {
+            props.put("new-filter", new String(this.filter));
+        }
+        if (fs != null) {
+            props.put("new-foo", new Integer(fs.getInt()));
+        }
+    }
+
+}

Added: felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProvider.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProvider.java?rev=694294&view=auto
==============================================================================
--- felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProvider.java (added)
+++ felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProvider.java Thu Sep 11 08:23:31 2008
@@ -0,0 +1,57 @@
+/* 
+ * 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.test.scenarios.component;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.filter.service.FooService;
+
+public class FooProvider implements FooService {
+
+    public boolean foo() {
+       return true;
+    }
+    
+    private int id;
+
+    public Properties fooProps() {
+        return null;
+    }
+
+    public boolean getBoolean() {
+        return false;
+    }
+
+    public double getDouble() {
+        return 0;
+    }
+
+    public int getInt() {
+        return id;
+    }
+
+    public long getLong() {
+        return 0;
+    }
+
+    public Boolean getObject() {
+        return null;
+    }
+
+}

Added: felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/component/MultipleCheckServiceProvider.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/component/MultipleCheckServiceProvider.java?rev=694294&view=auto
==============================================================================
--- felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/component/MultipleCheckServiceProvider.java (added)
+++ felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/component/MultipleCheckServiceProvider.java Thu Sep 11 08:23:31 2008
@@ -0,0 +1,87 @@
+/* 
+ * 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.test.scenarios.component;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.filter.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.filter.service.FooService;
+
+public class MultipleCheckServiceProvider implements CheckService {
+    
+    private Properties props = new Properties();
+    
+    private String filter;
+    
+    private int looked;
+    
+    
+    /**
+     * Service dependency.
+     */
+    private FooService[] fs;
+
+    public boolean check() {
+        
+        if (looked == 0) {
+            setFilter("(id=1)");
+            looked = 1;
+        } else {
+            setFilter("(id=0)");
+            looked = 0;
+        }
+        
+        return true;
+    }
+
+    public Properties getProps() {
+        return props;
+    }
+    
+    private List getFoos() {
+        List list = new ArrayList();
+        for (int i = 0; i < fs.length; i++) {
+            list.add(new Integer(fs[i].getInt()));
+        }
+        return list;
+    }
+    
+    public void setFilter(String filter) {
+        props = new Properties();
+        if(this.filter != null) {
+            props.put("old-filter", new String(this.filter));
+        }
+        if (fs != null) {
+            props.put("old-foo", getFoos());
+        }
+        
+        this.filter = filter; // Update the filter
+        
+        if(this.filter != null) {
+            props.put("new-filter", new String(this.filter));
+        }
+        if (fs != null) {
+            props.put("new-foo", getFoos());
+        }
+    }
+
+
+}

Added: felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/filter/AggregateFilterInjection.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/filter/AggregateFilterInjection.java?rev=694294&view=auto
==============================================================================
--- felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/filter/AggregateFilterInjection.java (added)
+++ felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/filter/AggregateFilterInjection.java Thu Sep 11 08:23:31 2008
@@ -0,0 +1,171 @@
+package org.apache.felix.ipojo.test.scenarios.filter;
+
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.filter.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class AggregateFilterInjection extends OSGiTestCase {
+    
+    ComponentInstance instance0, instance1, instance11;
+    ComponentInstance instance;
+    ComponentInstance filteredInstance;
+    
+    
+    public void setUp() {
+        Properties props0 = new Properties();
+        props0.put("id", "0");
+        instance0 = Utils.getComponentInstance(context, "FI-FooProvider", props0); 
+        
+        Properties props1 = new Properties();
+        props1.put("id", "1");
+        instance1 = Utils.getComponentInstance(context, "FI-FooProvider", props1);
+        
+        Properties props11 = new Properties();
+        props11.put("id", "1");
+        instance11 = Utils.getComponentInstance(context, "FI-FooProvider", props11);
+        
+        instance = Utils.getComponentInstance(context, "FI-MultipleCheckServiceProvider", null);
+        
+        
+        Properties filtered = new Properties();
+        Properties filters = new Properties();
+        filters.put("foo", "(id=0)");
+        filtered.put("requires.filters", filters);
+        filteredInstance = Utils.getComponentInstance(context, "FI-MultipleCheckServiceProvider", filtered);
+    }
+    
+    public void tearDown() {
+        instance0.dispose();
+        instance1.dispose();
+        instance11.dispose();
+        instance.dispose();
+        filteredInstance.dispose();
+    }
+    
+    public void testFilterSet() {
+        ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+        CheckService cs = (CheckService) context.getService(ref);
+        
+        cs.check();
+        Properties props = cs.getProps();
+        List oldfoos = (List) props.get("old-foo");
+        List newfoos = (List)  props.get("new-foo");
+        assertTrue("Check old-foo -1a", oldfoos.contains(new Integer(0)));
+        assertTrue("Check old-foo -1b", oldfoos.contains(new Integer(1)));
+        assertTrue("Check old-foo -1c", oldfoos.size() == 3);
+        assertEquals("Check old-filter -1", null, props.get("old-filter"));
+        assertEquals("Check new-filter -1", "(id=1)", props.get("new-filter"));
+        assertFalse("Check new-foo -1a", newfoos.contains(new Integer(0)));
+        assertTrue("Check new-foo -1b", newfoos.contains(new Integer(1)));
+        assertTrue("Check new-foo -1c", newfoos.size() == 2);
+        
+        cs.check();
+        props = cs.getProps();
+        oldfoos = (List) props.get("old-foo");
+        newfoos = (List)  props.get("new-foo");
+        assertFalse("Check old-foo -2a", oldfoos.contains(new Integer(0)));
+        assertTrue("Check old-foo -2b", oldfoos.contains(new Integer(1)));
+        assertTrue("Check old-foo -2c", oldfoos.size() == 2);
+        assertEquals("Check old-filter -2", "(id=1)", props.get("old-filter"));
+        assertEquals("Check new-filter -2", "(id=0)", props.get("new-filter"));
+        assertTrue("Check new-foo -2a", newfoos.contains(new Integer(0)));
+        assertFalse("Check new-foo -2b", newfoos.contains(new Integer(1)));
+
+        cs.setFilter("(id=3)"); // Becomes invalid.
+        ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+        assertNull("Check invalidity", ref);
+        
+        cs.setFilter("(id=1)");
+        ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+        assertNotNull("Check validity", ref);
+    }
+    
+    public void testFilterSetWithAFilter() {
+        ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), filteredInstance.getInstanceName());
+        CheckService cs = (CheckService) context.getService(ref);
+        cs.check();
+        Properties props = cs.getProps();
+        List oldfoos = (List) props.get("old-foo");
+        List newfoos = (List)  props.get("new-foo");
+        
+        assertTrue("Check old-foo -1a", oldfoos.contains(new Integer(0)));
+        assertTrue("Check old-foo -1b", oldfoos.size() == 1);
+        assertEquals("Check old-filter -1", "(id=0)", props.get("old-filter"));
+        assertEquals("Check new-filter -1", "(id=1)", props.get("new-filter"));
+        assertFalse("Check new-foo -1a", newfoos.contains(new Integer(0)));
+        assertTrue("Check new-foo -1b", newfoos.contains(new Integer(1)));
+        assertTrue("Check new-foo -1c", newfoos.size() == 2);
+        
+        cs.check();
+        props = cs.getProps();
+        oldfoos = (List) props.get("old-foo");
+        newfoos = (List)  props.get("new-foo");
+        assertFalse("Check old-foo -2a", oldfoos.contains(new Integer(0)));
+        assertTrue("Check old-foo -2b", oldfoos.contains(new Integer(1)));
+        assertTrue("Check old-foo -2c", oldfoos.size() == 2);
+        assertEquals("Check old-filter -2", "(id=1)", props.get("old-filter"));
+        assertEquals("Check new-filter -2", "(id=0)", props.get("new-filter"));
+        assertTrue("Check new-foo -2a", newfoos.contains(new Integer(0)));
+        assertFalse("Check new-foo -2b", newfoos.contains(new Integer(1)));
+        
+        cs.setFilter("(id=3)"); // Becomes invalid.
+        ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), filteredInstance.getInstanceName());
+        assertNull("Check invalidity", ref);
+        
+        cs.setFilter("(id=1)");
+        ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), filteredInstance.getInstanceName());
+        assertNotNull("Check validity", ref);
+    }
+    
+    public void testAddRemoveBinding() {
+        ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+        CheckService cs = (CheckService) context.getService(ref);
+        
+        cs.check();
+        Properties props = cs.getProps();
+        List oldfoos = (List) props.get("old-foo");
+        List newfoos = (List)  props.get("new-foo");
+        assertTrue("Check old-foo -1a", oldfoos.contains(new Integer(0)));
+        assertTrue("Check old-foo -1b", oldfoos.contains(new Integer(1)));
+        assertTrue("Check old-foo -1c", oldfoos.size() == 3);
+        assertEquals("Check old-filter -1", null, props.get("old-filter"));
+        assertEquals("Check new-filter -1", "(id=1)", props.get("new-filter"));
+        assertFalse("Check new-foo -1a", newfoos.contains(new Integer(0)));
+        assertTrue("Check new-foo -1b", newfoos.contains(new Integer(1)));
+        assertTrue("Check new-foo -1c", newfoos.size() == 2);
+        
+        
+        cs.setFilter("(id=*)");
+        props = cs.getProps();
+        oldfoos = (List) props.get("old-foo");
+        newfoos = (List)  props.get("new-foo");
+        assertTrue("Check new-foo -2a", newfoos.contains(new Integer(0)));
+        assertTrue("Check new-foo -2b", newfoos.contains(new Integer(1)));
+        assertTrue("Check new-foo -2c", newfoos.size() == 3);
+        assertEquals("Check old-filter -2", "(id=1)", props.get("old-filter"));
+        assertEquals("Check new-filter -2", "(id=*)", props.get("new-filter"));
+        assertFalse("Check old-foo -2a", oldfoos.contains(new Integer(0)));
+        assertTrue("Check old-foo -2b", oldfoos.contains(new Integer(1)));
+        assertTrue("Check old-foo -2c", oldfoos.size() == 2);
+        
+        cs.setFilter("(id=0)");
+        props = cs.getProps();
+        oldfoos = (List) props.get("old-foo");
+        newfoos = (List)  props.get("new-foo");
+        assertTrue("Check old-foo -3a", oldfoos.contains(new Integer(0)));
+        assertTrue("Check old-foo -3b", oldfoos.contains(new Integer(1)));
+        assertTrue("Check old-foo -3c", oldfoos.size() == 3);
+        assertEquals("Check old-filter -3", "(id=*)", props.get("old-filter"));
+        assertEquals("Check new-filter -3", "(id=0)", props.get("new-filter"));
+        assertTrue("Check new-foo -3a", newfoos.contains(new Integer(0)));
+        assertFalse("Check new-foo -3b", newfoos.contains(new Integer(1)));
+    }
+    
+    
+
+}

Added: felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/filter/FilterInjectorTestSuite.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/filter/FilterInjectorTestSuite.java?rev=694294&view=auto
==============================================================================
--- felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/filter/FilterInjectorTestSuite.java (added)
+++ felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/filter/FilterInjectorTestSuite.java Thu Sep 11 08:23:31 2008
@@ -0,0 +1,37 @@
+/* 
+ * 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.test.scenarios.filter;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.felix.ipojo.junit4osgi.OSGiTestSuite;
+import org.osgi.framework.BundleContext;
+
+public class FilterInjectorTestSuite extends TestSuite {
+
+    public static Test suite(BundleContext bc) {
+        OSGiTestSuite ots = new OSGiTestSuite("Filter Injector Test Suite", bc);
+        ots.addTestSuite(SimpleFilterInjection.class);
+        ots.addTestSuite(AggregateFilterInjection.class);
+        return ots;
+    }
+
+}
+

Added: felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/filter/SimpleFilterInjection.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/filter/SimpleFilterInjection.java?rev=694294&view=auto
==============================================================================
--- felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/filter/SimpleFilterInjection.java (added)
+++ felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/filter/SimpleFilterInjection.java Thu Sep 11 08:23:31 2008
@@ -0,0 +1,96 @@
+package org.apache.felix.ipojo.test.scenarios.filter;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.filter.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class SimpleFilterInjection extends OSGiTestCase {
+    
+    ComponentInstance instance0, instance1;
+    ComponentInstance instance;
+    ComponentInstance filteredInstance;
+    
+    
+    public void setUp() {
+        Properties props0 = new Properties();
+        props0.put("id", "0");
+        instance0 = Utils.getComponentInstance(context, "FI-FooProvider", props0); 
+        
+        Properties props1 = new Properties();
+        props1.put("id", "1");
+        instance1 = Utils.getComponentInstance(context, "FI-FooProvider", props1);
+        
+        instance = Utils.getComponentInstance(context, "FI-CheckServiceProvider", null);
+        
+        
+        Properties filtered = new Properties();
+        Properties filters = new Properties();
+        filters.put("foo", "(id=0)");
+        filtered.put("requires.filters", filters);
+        filteredInstance = Utils.getComponentInstance(context, "FI-CheckServiceProvider", filtered);
+    }
+    
+    public void tearDown() {
+        instance0.dispose();
+        instance1.dispose();
+        instance.dispose();
+        filteredInstance.dispose();
+    }
+    
+    public void testFilterSet() {
+        ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+        CheckService cs = (CheckService) context.getService(ref);
+        cs.check();
+        Properties props = cs.getProps();
+        assertEquals("Check old-foo -1", new Integer(0), props.get("old-foo"));
+        assertEquals("Check old-filter -1", null, props.get("old-filter"));
+        assertEquals("Check new-filter -1", "(id=1)", props.get("new-filter"));
+        assertEquals("Check new-foo -1", new Integer(1), props.get("new-foo"));
+        cs.check();
+        props = cs.getProps();
+        assertEquals("Check old-foo -2", new Integer(1), props.get("old-foo"));
+        assertEquals("Check old-filter -2", "(id=1)", props.get("old-filter"));
+        assertEquals("Check new-filter -2", "(id=0)", props.get("new-filter"));
+        assertEquals("Check new-foo -2", new Integer(0), props.get("new-foo"));
+
+        cs.setFilter("(id=3)"); // Becomes invalid.
+        ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+        assertNull("Check invalidity", ref);
+        
+        cs.setFilter("(id=1)");
+        ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+        assertNotNull("Check validity", ref);
+    }
+    
+    public void testFilterSetWithAFilter() {
+        ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), filteredInstance.getInstanceName());
+        CheckService cs = (CheckService) context.getService(ref);
+        cs.check();
+        Properties props = cs.getProps();
+        assertEquals("Check old-foo -1", new Integer(0), props.get("old-foo"));
+        assertEquals("Check old-filter -1", "(id=0)", props.get("old-filter"));
+        assertEquals("Check new-filter -1", "(id=1)", props.get("new-filter"));
+        assertEquals("Check new-foo -1", new Integer(1), props.get("new-foo"));
+        cs.check();
+        props = cs.getProps();
+        assertEquals("Check old-foo -2", new Integer(1), props.get("old-foo"));
+        assertEquals("Check old-filter -2", "(id=1)", props.get("old-filter"));
+        assertEquals("Check new-filter -2", "(id=0)", props.get("new-filter"));
+        assertEquals("Check new-foo -2", new Integer(0), props.get("new-foo"));
+
+        cs.setFilter("(id=3)"); // Becomes invalid.
+        ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), filteredInstance.getInstanceName());
+        assertNull("Check invalidity", ref);
+        
+        cs.setFilter("(id=1)");
+        ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), filteredInstance.getInstanceName());
+        assertNotNull("Check validity", ref);
+    }
+    
+    
+
+}

Added: felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/filter/service/BarService.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/filter/service/BarService.java?rev=694294&view=auto
==============================================================================
--- felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/filter/service/BarService.java (added)
+++ felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/filter/service/BarService.java Thu Sep 11 08:23:31 2008
@@ -0,0 +1,29 @@
+/* 
+ * 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.test.scenarios.filter.service;
+
+import java.util.Properties;
+
+public interface BarService {
+	
+	public boolean bar();
+	
+	public Properties getProps();
+
+}

Added: felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/filter/service/CheckService.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/filter/service/CheckService.java?rev=694294&view=auto
==============================================================================
--- felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/filter/service/CheckService.java (added)
+++ felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/filter/service/CheckService.java Thu Sep 11 08:23:31 2008
@@ -0,0 +1,33 @@
+/* 
+ * 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.test.scenarios.filter.service;
+
+import java.util.Properties;
+
+public interface CheckService {
+    
+    public static final String foo = "foo";
+	
+	public boolean check();
+	
+	public Properties getProps();
+	
+	public void setFilter(String filter);
+
+}

Added: felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/filter/service/FooService.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/filter/service/FooService.java?rev=694294&view=auto
==============================================================================
--- felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/filter/service/FooService.java (added)
+++ felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/filter/service/FooService.java Thu Sep 11 08:23:31 2008
@@ -0,0 +1,39 @@
+/* 
+ * 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.test.scenarios.filter.service;
+
+import java.util.Properties;
+
+public interface FooService {
+
+	boolean foo();
+	
+	Properties fooProps();
+	
+	Boolean getObject();
+	
+	boolean getBoolean();
+	
+	int getInt();
+	
+	long getLong();
+	
+	double getDouble();
+	
+}

Added: felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java?rev=694294&view=auto
==============================================================================
--- felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java (added)
+++ felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java Thu Sep 11 08:23:31 2008
@@ -0,0 +1,353 @@
+/* 
+ * 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.test.scenarios.util;
+
+import java.util.Dictionary;
+import java.util.Properties;
+
+import junit.framework.Assert;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.Handler;
+import org.apache.felix.ipojo.HandlerFactory;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.metadata.Element;
+import org.apache.felix.ipojo.parser.ManifestMetadataParser;
+import org.apache.felix.ipojo.parser.ParseException;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.ManagedServiceFactory;
+
+public class Utils {
+    
+    public static Element getMetatadata(BundleContext bc, String component) {
+        String elem = (String) bc.getBundle().getHeaders().get("iPOJO-Components");
+        Assert.assertNotNull("iPOJO Components exists", elem);
+        try {
+            Element element = ManifestMetadataParser.parseHeaderMetadata(elem);
+            Element[] childs = element.getElements("component");
+            for (int i = 0; i < childs.length; i++) {
+                String name = childs[i].getAttribute("name");
+                String clazz = childs[i].getAttribute("classname");
+                if (name != null && name.equalsIgnoreCase(component)) {
+                    return childs[i];
+                }
+                if (clazz.equalsIgnoreCase(component)) {
+                    return childs[i];
+                }
+            }
+            Assert.fail("Component " + component + " not found in " + bc.getBundle().getSymbolicName());
+        } catch (ParseException e) {
+            Assert.fail("Cannot parse the components from " + bc.getBundle().getSymbolicName() + ": " + e.getMessage());
+        }
+        
+        return null;
+        
+    }
+
+    public static Factory getFactoryByName(BundleContext bc, String factoryName) {
+        ServiceReference[] refs;
+        try {
+            refs = bc.getServiceReferences(Factory.class.getName(), "(factory.name=" + factoryName + ")");
+            if (refs == null) {
+                System.err.println("Cannot get the factory " + factoryName);
+                return null;
+            }
+            return ((Factory) bc.getService(refs[0]));
+        } catch (InvalidSyntaxException e) {
+            System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());
+            return null;
+        }
+    }
+
+    public static HandlerFactory getHandlerFactoryByName(BundleContext bc, String factoryName) {
+        ServiceReference[] refs;
+        try {
+            refs = bc.getServiceReferences(Factory.class.getName(), "(" + Handler.HANDLER_NAME_PROPERTY + "=" + factoryName + ")");
+            if (refs == null) {
+                System.err.println("Cannot get the factory " + factoryName);
+                return null;
+            }
+            return (HandlerFactory) bc.getService(refs[0]);
+        } catch (InvalidSyntaxException e) {
+            System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());
+            return null;
+        }
+    }
+
+    public static ComponentInstance getComponentInstance(BundleContext bc, String factoryName, Dictionary configuration) {
+        Factory fact = getFactoryByName(bc, factoryName);
+
+        if (fact == null) {
+            System.err.println("Factory " + factoryName + " not found");
+            return null;
+        }
+
+        // if(fact.isAcceptable(configuration)) {
+        try {
+            return fact.createComponentInstance(configuration);
+        } catch (Exception e) {
+            e.printStackTrace();
+            Assert.fail("Cannot create the instance from " + factoryName + " : " + e.getMessage());
+            return null;
+        }
+        // }
+        // else {
+        // System.err.println("Configuration not accepted by : " + factoryName);
+        // return null;
+        // }
+    }
+
+    public static ComponentInstance getComponentInstanceByName(BundleContext bc, String factoryName, String name) {
+        Factory fact = getFactoryByName(bc, factoryName);
+
+        if (fact == null) {
+            System.err.println("Factory " + factoryName + " not found");
+            return null;
+        }
+
+        try {
+            Properties props = new Properties();
+            props.put("instance.name",name);
+            return fact.createComponentInstance(props);
+        } catch (Exception e) {
+            System.err.println("Cannot create the instance from " + factoryName + " : " + e.getMessage());
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+    public static ServiceReference[] getServiceReferences(BundleContext bc, String itf, String filter) {
+        ServiceReference[] refs = null;
+        try {
+            refs = bc.getServiceReferences(itf, filter);
+        } catch (InvalidSyntaxException e) {
+            System.err.println("Invalid Filter : " + filter);
+        }
+        if (refs == null) {
+            return new ServiceReference[0];
+        } else {
+            return refs;
+        }
+    }
+
+    public static ServiceReference getServiceReference(BundleContext bc, String itf, String filter) {
+        ServiceReference[] refs = null;
+        try {
+            refs = bc.getServiceReferences(itf, filter);
+        } catch (InvalidSyntaxException e) {
+            System.err.println("Invalid Filter : " + filter);
+        }
+        if (refs == null) {
+            return null;
+        } else {
+            return refs[0];
+        }
+    }
+
+    public static ServiceReference getServiceReferenceByName(BundleContext bc, String itf, String name) {
+        ServiceReference[] refs = null;
+        String filter = null;
+        if (itf.equals(Factory.class.getName()) || itf.equals(ManagedServiceFactory.class.getName())) {
+            filter = "(" + "factory.name" + "=" + name + ")";
+        } else {
+            filter = "(" + "instance.name" + "=" + name + ")";
+        }
+        try {
+            refs = bc.getServiceReferences(itf, filter);
+        } catch (InvalidSyntaxException e) {
+            System.err.println("Invalid Filter : " + filter);
+        }
+        if (refs == null) {
+            return null;
+        } else {
+            return refs[0];
+        }
+    }
+    
+    public static ServiceReference getServiceReferenceByPID(BundleContext bc, String itf, String pid) {
+        ServiceReference[] refs = null;
+        String filter = "(" + "service.pid" + "=" + pid + ")";
+        try {
+            refs = bc.getServiceReferences(itf, filter);
+        } catch (InvalidSyntaxException e) {
+            System.err.println("Invalid Filter : " + filter);
+        }
+        if (refs == null) {
+            return null;
+        } else if (refs.length == 1) {
+            return refs[0];
+        } else {
+            Assert.fail("A service lookup by PID returned several providers (" + refs.length + ")" + " for " + itf + " with " + pid);
+            return null;
+        }
+    }
+
+    public static Object getServiceObject(BundleContext bc, String itf, String filter) {
+        ServiceReference ref = getServiceReference(bc, itf, filter);
+        if (ref != null) {
+            return bc.getService(ref);
+        } else {
+            return null;
+        }
+    }
+
+    public static Object[] getServiceObjects(BundleContext bc, String itf, String filter) {
+        ServiceReference[] refs = getServiceReferences(bc, itf, filter);
+        if (refs != null) {
+            Object[] list = new Object[refs.length];
+            for (int i = 0; i < refs.length; i++) {
+                list[i] = bc.getService(refs[i]);
+            }
+            return list;
+        } else {
+            return new Object[0];
+        }
+    }
+
+//    public static ServiceContext getServiceContext(ComponentInstance ci) {
+//        if (ci instanceof CompositeManager) {
+//            return ((CompositeManager) ci).getServiceContext();
+//        } else {
+//            throw new RuntimeException("Cannot get the service context form an non composite instance");
+//        }
+//    }
+
+    public static Factory getFactoryByName(ServiceContext bc, String factoryName) {
+        ServiceReference[] refs;
+        try {
+            refs = bc.getServiceReferences(Factory.class.getName(), "(factory.name=" + factoryName + ")");
+            if (refs == null) { return null; }
+            return ((Factory) bc.getService(refs[0]));
+        } catch (InvalidSyntaxException e) {
+            System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());
+            return null;
+        }
+    }
+
+    public static ComponentInstance getComponentInstance(ServiceContext bc, String factoryName, Dictionary configuration) {
+        Factory fact = getFactoryByName(bc, factoryName);
+
+        if (fact == null) { return null; }
+
+        if (fact.isAcceptable(configuration)) {
+            try {
+                return fact.createComponentInstance(configuration);
+            } catch (Exception e) {
+                System.err.println(e.getMessage());
+                e.printStackTrace();
+                return null;
+            }
+        } else {
+            System.err.println("Configuration not accepted by : " + factoryName);
+            return null;
+        }
+    }
+
+    public static ServiceReference[] getServiceReferences(ServiceContext bc, String itf, String filter) {
+        ServiceReference[] refs = null;
+        try {
+            refs = bc.getServiceReferences(itf, filter);
+        } catch (InvalidSyntaxException e) {
+            System.err.println("Invalid Filter : " + filter);
+        }
+        if (refs == null) {
+            return new ServiceReference[0];
+        } else {
+            return refs;
+        }
+    }
+
+    public static ServiceReference getServiceReference(ServiceContext bc, String itf, String filter) {
+        ServiceReference[] refs = null;
+        try {
+            refs = bc.getServiceReferences(itf, filter);
+        } catch (InvalidSyntaxException e) {
+            System.err.println("Invalid Filter : " + filter);
+        }
+        if (refs == null) {
+            return null;
+        } else {
+            return refs[0];
+        }
+    }
+
+    public static ServiceReference getServiceReferenceByName(ServiceContext bc, String itf, String name) {
+        ServiceReference[] refs = null;
+        String filter = null;
+        if (itf.equals(Factory.class.getName()) || itf.equals(ManagedServiceFactory.class.getName())) {
+            filter = "(" + "factory.name" + "=" + name + ")";
+        } else {
+            filter = "(" + "instance.name" + "=" + name + ")";
+        }
+        try {
+            refs = bc.getServiceReferences(itf, filter);
+        } catch (InvalidSyntaxException e) {
+            System.err.println("Invalid Filter : " + filter);
+        }
+        if (refs == null) {
+            return null;
+        } else {
+            return refs[0];
+        }
+    }
+
+    public static Object getServiceObject(ServiceContext bc, String itf, String filter) {
+        ServiceReference ref = getServiceReference(bc, itf, filter);
+        if (ref != null) {
+            return bc.getService(ref);
+        } else {
+            return null;
+        }
+    }
+
+    public static Object[] getServiceObjects(ServiceContext bc, String itf, String filter) {
+        ServiceReference[] refs = getServiceReferences(bc, itf, filter);
+        if (refs != null) {
+            Object[] list = new Object[refs.length];
+            for (int i = 0; i < refs.length; i++) {
+                list[i] = bc.getService(refs[i]);
+            }
+            return list;
+        } else {
+            return new Object[0];
+        }
+    }
+    
+    public static boolean contains(String string, String[] array) {
+        for (int i = 0; array != null && i < array.length; i++) {
+            if (array[i] != null  && array[i].equals(string)) {
+                return true;
+            }
+        }
+        return false;
+    }
+    
+    public static boolean contains(int value, int[] array) {
+        for (int i = 0; array != null && i < array.length; i++) {
+            if (array[i] == value) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+}

Added: felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/resources/metadata.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/resources/metadata.xml?rev=694294&view=auto
==============================================================================
--- felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/resources/metadata.xml (added)
+++ felix/sandbox/clement/filter-injection/tests.filter-injection/src/main/resources/metadata.xml Thu Sep 11 08:23:31 2008
@@ -0,0 +1,26 @@
+<ipojo 
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="org.apache.felix.ipojo http://people.apache.org/~clement/ipojo/schemas/core.xsd 
+	    org.apache.felix.ipojo.handler.temporal http://people.apache.org/~clement/ipojo/schemas/temporal.xsd"
+	xmlns="org.apache.felix.ipojo"
+	xmlns:inj="org.apache.felix.ipojo.handler.filter">
+	<component classname="org.apache.felix.ipojo.test.scenarios.component.CheckServiceProvider" name="FI-CheckServiceProvider">
+		<requires field="fs" id="foo"/>
+		<inj:filter-injector field="filter" id="foo"/>
+		<provides/>
+	</component>
+	
+	<component classname="org.apache.felix.ipojo.test.scenarios.component.MultipleCheckServiceProvider" name="FI-MultipleCheckServiceProvider">
+		<requires field="fs" id="foo"/>
+		<inj:filter-injector field="filter" id="foo"/>
+		<provides/>
+	</component>
+	
+	<component classname="org.apache.felix.ipojo.test.scenarios.component.FooProvider"
+	 name="FI-FooProvider">
+		<provides>
+			<property name="id" field="id"/>
+		</provides>
+	</component>
+	
+</ipojo>
\ No newline at end of file