Improve error handling in the ProvidedService handler
Commit test about the exposition of abstract and concrete classes as services.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@744039 13f79535-47bb-0310-9956-ffa450edef68
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 5730806..f73444d 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
@@ -28,6 +28,7 @@
 import org.apache.felix.ipojo.ConfigurationException;
 import org.apache.felix.ipojo.HandlerFactory;
 import org.apache.felix.ipojo.InstanceManager;
+import org.apache.felix.ipojo.Pojo;
 import org.apache.felix.ipojo.PrimitiveHandler;
 import org.apache.felix.ipojo.architecture.ComponentTypeDescription;
 import org.apache.felix.ipojo.architecture.HandlerDescription;
@@ -533,9 +534,11 @@
             if (serviceSpecificationStr != null) {
                 List itfs = ParseUtils.parseArraysAsList(serviceSpecificationStr);
                 for (int j = 0; j < itfs.size(); j++) {
-                    if (! all.contains(itfs.get(j)) && ! parent.equals((String) itfs.get(i))) {
-                        desc.getFactory().getLogger().log(Logger.WARNING, "The specification " + itfs.get(j) + " is not implemented by " + metadata.getAttribute("classname") + 
-                                " it might be a superclass.");
+                    if (! all.contains(itfs.get(j))) {
+                        if (parent == null || (parent != null && ! parent.equals((String) itfs.get(j)))) {
+                            desc.getFactory().getLogger().log(Logger.WARNING, "The specification " + itfs.get(j) + " is not implemented by " + metadata.getAttribute("classname") + 
+                                " it might be a superclass or the class itself.");
+                        }
                     }
                 }
                 all = new HashSet(itfs);
@@ -547,6 +550,7 @@
 
             StringBuffer specs = null;
             Set set = new HashSet(all);
+            set.remove(Pojo.class.getName()); // Remove POJO.
             Iterator iterator = set.iterator(); 
             while (iterator.hasNext()) {
                 String spec = (String) iterator.next();
diff --git a/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/component/inherited/ProcessImplementation4.java b/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/component/inherited/ProcessImplementation4.java
new file mode 100644
index 0000000..d6066de
--- /dev/null
+++ b/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/component/inherited/ProcessImplementation4.java
@@ -0,0 +1,82 @@
+/* 

+ * 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.inherited;

+

+import java.util.Properties;

+

+import org.apache.felix.ipojo.test.scenarios.ps.service.FooService;

+

+public class ProcessImplementation4 extends ProcessImplementation2  implements FooService {

+

+    public void processChild() {

+        // TODO Auto-generated method stub

+

+    }

+

+    public void processParent1() {

+        // TODO Auto-generated method stub

+

+    }

+

+    public void processParentParent() {

+        // TODO Auto-generated method stub

+

+    }

+

+    public void processParent2() {

+        // TODO Auto-generated method stub

+

+    }

+

+    public boolean foo() {

+        // TODO Auto-generated method stub

+        return false;

+    }

+

+    public Properties fooProps() {

+        // TODO Auto-generated method stub

+        return null;

+    }

+

+    public boolean getBoolean() {

+        // TODO Auto-generated method stub

+        return false;

+    }

+

+    public double getDouble() {

+        // TODO Auto-generated method stub

+        return 0;

+    }

+

+    public int getInt() {

+        // TODO Auto-generated method stub

+        return 0;

+    }

+

+    public long getLong() {

+        // TODO Auto-generated method stub

+        return 0;

+    }

+

+    public Boolean getObject() {

+        // TODO Auto-generated method stub

+        return null;

+    }

+

+}

diff --git a/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/ClassTest.java b/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/ClassTest.java
new file mode 100644
index 0000000..de241b9
--- /dev/null
+++ b/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/ClassTest.java
@@ -0,0 +1,94 @@
+/* 

+ * 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.ps;

+

+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.inherited.ProcessParentImplementation;

+import org.apache.felix.ipojo.test.scenarios.ps.service.FooService;

+import org.osgi.framework.ServiceReference;

+

+public class ClassTest extends OSGiTestCase {

+    

+    private Factory pi4, pi5, pi6, pi7;

+    

+    private IPOJOHelper helper;

+    

+    public void setUp() {

+        helper = new IPOJOHelper(this);

+        pi4 = helper.getFactory("PS-PI4");

+        pi5 = helper.getFactory("PS-PI5");

+        pi6 = helper.getFactory("PS-PI6");

+        pi7 = helper.getFactory("PS-PI7");

+    }

+    

+    public void tearDown() {

+        helper.dispose();

+    }

+    

+    

+    public void testIP4() {

+       helper.createComponentInstance( pi4.getName(), "ci");

+        

+       ServiceReference ref1 = helper.getServiceReferenceByName("org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessParentImplementation", "ci");

+       assertNotNull("Check itself", ref1);

+        

+       ProcessParentImplementation itself = (ProcessParentImplementation) getServiceObject(ref1);

+       

+        itself.processChild();

+    }

+    

+    public void testIP5() {

+        helper.createComponentInstance( pi5.getName(), "ci");

+        

+        ServiceReference ref1 = helper.getServiceReferenceByName("org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessParentImplementation", "ci");

+        assertNotNull("Check parent", ref1);

+         

+        ProcessParentImplementation itself = (ProcessParentImplementation) getServiceObject(ref1);

+        

+         itself.processChild();

+        

+    }

+    

+    public void testIP6() {

+        helper.createComponentInstance( pi6.getName(), "ci");

+        

+        ServiceReference ref1 = helper.getServiceReferenceByName("org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessParentImplementation", "ci");

+        assertNotNull("Check parent-parent", ref1);

+         

+        ProcessParentImplementation itself = (ProcessParentImplementation) getServiceObject(ref1);

+        

+         itself.processChild();

+    }

+    

+    public void testIP7() {

+       helper.createComponentInstance( pi7.getName(), "ci");

+        

+        ServiceReference ref1 = helper.getServiceReferenceByName("org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessParentImplementation", "ci");

+        assertNotNull("Check parent-parent", ref1);

+         

+        ProcessParentImplementation itself = (ProcessParentImplementation) getServiceObject(ref1);

+        

+         itself.processChild();

+         

+         ServiceReference ref5 = helper.getServiceReferenceByName( FooService.class.getName(), "ci");

+         assertNotNull("Check FS", ref5);

+    }

+}

diff --git a/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/ProvidedServiceTestSuite.java b/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/ProvidedServiceTestSuite.java
index c5d8866..8bb78e6 100644
--- a/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/ProvidedServiceTestSuite.java
+++ b/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/ProvidedServiceTestSuite.java
@@ -36,6 +36,7 @@
 		ots.addTestSuite(DynamicPropsReconfiguration.class);

 		ots.addTestSuite(InheritedTest.class);

 		ots.addTestSuite(ProvidedServiceArchitectureTest.class);

+		ots.addTestSuite(ClassTest.class);

 		return ots;

 	}

 

diff --git a/ipojo/tests/core/service-providing/src/main/resources/metadata.xml b/ipojo/tests/core/service-providing/src/main/resources/metadata.xml
index 8be6b53..5dcd7c6 100644
--- a/ipojo/tests/core/service-providing/src/main/resources/metadata.xml
+++ b/ipojo/tests/core/service-providing/src/main/resources/metadata.xml
@@ -136,4 +136,27 @@
 		name="PS-PI3" architecture="true">

 		<provides />

 	</component>

+	

+	<!-- Concrete and abstract class -->

+	<component

+		classname="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessParentImplementation"

+		name="PS-PI4" architecture="true">

+		<provides specifications="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessParentImplementation"/>

+	</component>

+	<component

+		classname="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessImplementation2"

+		name="PS-PI5" architecture="true">

+		<provides specifications="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessParentImplementation"/>

+	</component>

+	<component

+		classname="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessImplementation4"

+		name="PS-PI6" architecture="true">

+		<provides specifications="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessParentImplementation"/>

+	</component>

+	<component

+		classname="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessImplementation3"

+		name="PS-PI7" architecture="true">

+		<provides specifications="[org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessParentImplementation, 

+					org.apache.felix.ipojo.test.scenarios.ps.service.FooService]"/>

+	</component>

 </ipojo>