Fix issue FELIX-1906
Provide a 'modified' callback when an injected service is modified.
This commit:
modify the dependency model to support such callback
update the handlers
extends the api
provides the annotation
modify the XSD schema
Add tests
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@885210 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/tests/core/annotations/pom.xml b/ipojo/tests/core/annotations/pom.xml
index d1a05d4..1a1b0e1 100644
--- a/ipojo/tests/core/annotations/pom.xml
+++ b/ipojo/tests/core/annotations/pom.xml
@@ -1,111 +1,111 @@
<!--
- 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
+ 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
+ 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.
+ 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 Annotations Test Suite</name>
- <artifactId>tests.core.annotations</artifactId>
- <groupId>ipojo.tests</groupId>
- <version>1.5.0-SNAPSHOT</version>
- <dependencies>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.ipojo</artifactId>
- <version>${pom.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.ipojo.metadata
- </artifactId>
- <version>${pom.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.osgi.core</artifactId>
- <version>1.0.1</version>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version>
- </dependency>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.ipojo.junit4osgi</artifactId>
- <version>1.1.0-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.ipojo.annotations</artifactId>
- <version>${pom.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.ipojo.handler.eventadmin</artifactId>
- <version>${pom.version}</version>
- </dependency>
- </dependencies>
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>bundle</packaging>
+ <name>iPOJO Annotations Test Suite</name>
+ <artifactId>tests.core.annotations</artifactId>
+ <groupId>ipojo.tests</groupId>
+ <version>1.5.0-SNAPSHOT</version>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo.metadata
+ </artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>1.0.1</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo.junit4osgi</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo.annotations</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo.handler.eventadmin</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.5</source>
- <target>1.5</target>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <version>1.4.3</version>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Export-Package>
- org.apache.felix.ipojo.test.scenarios.annotations.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.annotations.AnnotationsTestSuite
- </Test-Suite>
- </instructions>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-ipojo-plugin</artifactId>
- <version>${pom.version}</version>
- <executions>
- <execution>
- <goals>
- <goal>ipojo-bundle</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>1.4.3</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.apache.felix.ipojo.test.scenarios.annotations.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.annotations.AnnotationsTestSuite
+ </Test-Suite>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-ipojo-plugin</artifactId>
+ <version>${pom.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>ipojo-bundle</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/Dependency.java b/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/Dependency.java
index ddeea7d..f69e76d 100644
--- a/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/Dependency.java
+++ b/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/Dependency.java
@@ -72,6 +72,17 @@
assertEquals("Check fs2 bind", "bindFS2Inv", bind);
assertEquals("Check fs2 unbind", "unbindFS2Inv", unbind);
assertEquals("Check fs2 id", "inv", id);
+
+ // Check mod
+ dep = getDependencyById(deps, "mod");
+ id = dep.getAttribute("id");
+ bind = getBind(dep);
+ unbind = getUnbind(dep);
+ String mod = getModified(dep);
+ assertEquals("Check mod bind", "bindMod", bind);
+ assertEquals("Check mod unbind", "unbindMod", unbind);
+ assertEquals("Check mod modified", "modifiedMod", mod);
+ assertEquals("Check mod id", "mod", id);
}
private Element getDependencyById(Element[] deps, String name) {
@@ -108,5 +119,15 @@
}
return null;
}
+
+ private String getModified(Element dep) {
+ Element[] elem = dep.getElements("callback");
+ for (int i = 0; elem != null && i < elem.length; i++) {
+ if (elem[i].getAttribute("type").equalsIgnoreCase("modified")) {
+ return elem[i].getAttribute("method");
+ }
+ }
+ return null;
+ }
}
diff --git a/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/Dependency.java b/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/Dependency.java
index 97b053f..906fa4f 100644
--- a/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/Dependency.java
+++ b/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/Dependency.java
@@ -2,6 +2,7 @@
import org.apache.felix.ipojo.annotations.Bind;
import org.apache.felix.ipojo.annotations.Component;
+import org.apache.felix.ipojo.annotations.Modified;
import org.apache.felix.ipojo.annotations.Requires;
import org.apache.felix.ipojo.annotations.Unbind;
import org.apache.felix.ipojo.test.scenarios.annotations.service.FooService;
@@ -59,6 +60,21 @@
}
+ @Bind(id="mod")
+ public void bindMod() {
+
+ }
+
+ @Unbind(id="mod")
+ public void unbindMod() {
+
+ }
+
+ @Modified(id="mod")
+ public void modifiedMod() {
+
+ }
+
}