Fix FELIX-2781 Expose the implementation class as service when no interfaces are found in the hierachy
Update the changelog
Add tests to check FELIX-2781
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1059383 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/core/doc/changelog.txt b/ipojo/core/doc/changelog.txt
index 7a02735..bb0f693 100644
--- a/ipojo/core/doc/changelog.txt
+++ b/ipojo/core/doc/changelog.txt
@@ -5,6 +5,7 @@
* [FELIX-2716] - [iPOJO] Failure when creating proxies for classes in java.* packages
** Improvement
+ * [FELIX-2781] - Expose the implementation class as service when no interfaces are found in the hierarchy
* [FELIX-1424] - Constructor Injection
* [FELIX-1428] - Constructor injection of Configuration properties
* [FELIX-2461] - Allow specifying the targeted service interface in the @ServiceController
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java
index e91beab..9a40430 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java
@@ -596,7 +596,8 @@
}
if (all.isEmpty()) {
- throw new ConfigurationException("Service Providing: Cannot instantiate a provided service : no specifications found (no interfaces implemented by the pojo)");
+ warn("No service interface found in the class hierarchy, use the implementation class");
+ all.add(desc.getFactory().getClassName());
}
StringBuffer specs = null;
diff --git a/ipojo/tests/core/service-providing/src/main/ipojo/concrete-abstract.xml b/ipojo/tests/core/service-providing/src/main/ipojo/concrete-abstract.xml
index 25366c8..843e17a 100644
--- a/ipojo/tests/core/service-providing/src/main/ipojo/concrete-abstract.xml
+++ b/ipojo/tests/core/service-providing/src/main/ipojo/concrete-abstract.xml
@@ -25,4 +25,9 @@
<provides specifications="[org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessParentImplementation, org.apache.felix.ipojo.test.scenarios.ps.service.FooService]"/>
</component>
+ <component
+ classname="org.apache.felix.ipojo.test.scenarios.component.SimpleClass">
+ <provides/>
+ </component>
+
</ipojo>
diff --git a/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/component/SimpleClass.java b/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/component/SimpleClass.java
new file mode 100644
index 0000000..5761947
--- /dev/null
+++ b/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/component/SimpleClass.java
@@ -0,0 +1,11 @@
+package org.apache.felix.ipojo.test.scenarios.component;
+
+public class SimpleClass {
+
+ // This class do not implement any interface, it will be exposed as SimpleClass
+
+ public String hello() {
+ return "Hello";
+ }
+
+}
diff --git a/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/SimplePS.java b/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/SimplePS.java
index 24ba6af..044fc38 100644
--- a/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/SimplePS.java
+++ b/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/SimplePS.java
@@ -1,4 +1,4 @@
-/*
+/*
* 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
@@ -18,50 +18,62 @@
*/
package org.apache.felix.ipojo.test.scenarios.ps;
+import org.apache.felix.ipojo.ComponentInstance;
import org.apache.felix.ipojo.Factory;
import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
import org.apache.felix.ipojo.junit4osgi.helpers.IPOJOHelper;
+import org.apache.felix.ipojo.test.scenarios.component.SimpleClass;
import org.apache.felix.ipojo.test.scenarios.ps.service.FooService;
import org.osgi.framework.ServiceReference;
public class SimplePS extends OSGiTestCase {
-
+
public void testPS() {
IPOJOHelper helper = new IPOJOHelper(this);
-
+
String factName = "PS-FooProviderType-1";
String compName = "FooProvider-1";
ServiceReference ref = null;
-
+
// Check that no Foo Service are available
ref = getServiceReference(FooService.class.getName());
-
+
assertNull("FS already available", ref);
-
+
// Get the factory to create a component instance
Factory fact = helper.getFactory(factName);
assertNotNull("Cannot find the factory FooProvider-1", fact);
-
+
helper.createComponentInstance(factName, compName);
-
+
// Get a FooService provider
ref = getServiceReference(FooService.class.getName(), "(" + "instance.name" + "=" + compName + ")");
assertNotNull("FS not available", ref);
-
+
// Test foo invocation
FooService fs = (FooService) getServiceObject(ref);
assertTrue("FooService invocation failed", fs.foo());
-
+
helper.dispose();
-
+
// Check that there is no more FooService
ref = getServiceReference(FooService.class.getName(), null);
-
-
+
+
assertNull("FS available, but component instance stopped", ref);
-
+
+ }
+
+ public void testWhenNoInterface() {
+ IPOJOHelper helper = new IPOJOHelper(this);
+ String factoryName = "org.apache.felix.ipojo.test.scenarios.component.SimpleClass";
+ ComponentInstance ci = helper.createComponentInstance(factoryName);
+ waitForService(SimpleClass.class.getName(), null, 5000);
+ SimpleClass simple = (SimpleClass) getServiceObject(SimpleClass.class.getName(), null);
+ assertEquals("Hello", simple.hello());
+ ci.dispose();
}
}