Commit 78125570 authored by Philippe Merle's avatar Philippe Merle

Changed how Java interfaces implemented by a Java class are reified as SCA services.

Previously, interfaces of @Service xor all implemented interfaces were reified.
Now, interfaces of @Service and only implemented interfaces annotated with @Service are reified.
The issue appeared when running code coverage with Sonar.
parent 45ff34e4
......@@ -24,6 +24,8 @@
package org.ow2.frascati.examples.twitterweather.api;
import org.osoa.sca.annotations.Service;
import org.ow2.frascati.examples.twitterweather.xml.Locations;
/**
......@@ -32,6 +34,7 @@ import org.ow2.frascati.examples.twitterweather.xml.Locations;
* @author Nicolas Dolet
*
*/
@Service
public interface Decoder {
/**
......
......@@ -28,6 +28,8 @@ package org.ow2.frascati.assembly.factory.test;
import org.junit.Test;
import org.osoa.sca.annotations.Service;
import org.objectweb.fractal.api.Component;
import org.ow2.frascati.FraSCAti;
......@@ -36,6 +38,7 @@ import org.ow2.frascati.FraSCAti;
* @author Jonathan Labejof
*
*/
@Service(GenericInterface.class)
public class GenericComponentTest implements GenericInterface<String>
{
......
/**
* OW2 FraSCAti: SCA Parser
* Copyright (C) 2008-2010 INRIA, USTL
* Copyright (C) 2008-2010 INRIA, University of Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -29,7 +29,9 @@ package org.ow2.frascati.parser.resolver;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.stp.sca.Component;
......@@ -102,21 +104,23 @@ public class JavaInterfaceResolver
*/
private void resolveServices(Component component, MetaData<?> cMetaData, ParsingContext parsingContext)
{
// Retrieve service annotation
Service s = cMetaData.getAnnotation(Service.class);
Class<?>[] interfaces = null;
// The list of @Service interfaces implemented by the content class.
List<Class<?>> interfaces = new ArrayList<Class<?>>();
// Retrieve service annotation.
Service s = cMetaData.getAnnotation(Service.class);
// Test if class is annotated with org.osoa.sca.annotations.Service
if (s != null) {
// Array to store interfaces defined in Java file
interfaces = s.interfaces();
if(interfaces.length > 0) {
if(s.interfaces().length > 0) {
if(s.value() != Void.class) {
parsingContext.warning("@" + Service.class.getCanonicalName() +
" applied to class " + cMetaData.getSupportClass().getCanonicalName() +
" must define the field 'value' or 'interfaces'");
} else {
// Add all interfaces of the @Service annotation.
for(Class<?> itf : s.interfaces()) {
interfaces.add(itf);
}
}
} else {
if(s.value() == Void.class) {
......@@ -124,29 +128,26 @@ public class JavaInterfaceResolver
" applied to class " + cMetaData.getSupportClass().getCanonicalName() +
" must define the field 'value' or 'interfaces'");
} else {
interfaces = new Class<?>[1];
interfaces[0] = s.value();
// Add the interface of the @Service annotation.
interfaces.add(s.value());
}
}
}
} else {
// Class not annotated with org.osoa.sca.annotations.Service use
// implemented interfaces instead
// TODO test if implemented interfaces are annotated with @Service
JavaImplementation javaImpl = (JavaImplementation) component
.getImplementation();
try {
Class<?> implementation = parsingContext.loadClass(javaImpl.getClass_());
// TODO: Keep only interfaces annotated with @Service
try {
JavaImplementation javaImpl = (JavaImplementation) component.getImplementation();
Class<?> implementation = parsingContext.loadClass(javaImpl.getClass_());
interfaces = implementation.getInterfaces();
} catch (ClassNotFoundException e) {
// Already reported by the JavaResolver
return;
// Add all implemented interfaces annotated with @Service.
for(Class<?> itf : implementation.getInterfaces()) {
if(itf.getAnnotation(Service.class) != null) {
interfaces.add(itf);
}
}
} catch (ClassNotFoundException e) {
// Already reported by the JavaResolver
return;
}
// create current services map
......@@ -169,10 +170,10 @@ public class JavaInterfaceResolver
// Service is defined without interfaces, need to add if possible
else {
JavaInterface i = ScaFactory.eINSTANCE.createJavaInterface();
i.setInterface(interfaces[0].getCanonicalName());
i.setInterface(interfaces.get(0).getCanonicalName());
componentService.setInterface(i);
// register since just added
serviceMap.put(componentService.getName(), interfaces[0]
serviceMap.put(componentService.getName(), interfaces.get(0)
.getCanonicalName());
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment