Fixes for JCA90003 - constructor args need to be annotated
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@825841 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
804d7164fd
commit
3873dcffd1
2 changed files with 24 additions and 1 deletions
java/sca/modules/implementation-java/src
main/java/org/apache/tuscany/sca/implementation/java/introspect/impl
test/java/org/apache/tuscany/sca/implementation/java/introspect/impl
|
@ -26,6 +26,8 @@ import org.apache.tuscany.sca.implementation.java.JavaConstructorImpl;
|
|||
import org.apache.tuscany.sca.implementation.java.JavaImplementation;
|
||||
import org.apache.tuscany.sca.implementation.java.JavaParameterImpl;
|
||||
import org.apache.tuscany.sca.implementation.java.introspect.BaseJavaClassVisitor;
|
||||
import org.oasisopen.sca.annotation.Property;
|
||||
import org.oasisopen.sca.annotation.Reference;
|
||||
|
||||
/**
|
||||
* Handles processing of a constructor decorated with
|
||||
|
@ -76,9 +78,30 @@ public class ConstructorProcessor extends BaseJavaClassVisitor {
|
|||
if (!isDefault && value.length != parameters.length) {
|
||||
throw new InvalidConstructorException("Invalid Number of names in @Constructor");
|
||||
}
|
||||
|
||||
for (JavaParameterImpl p : parameters) {
|
||||
if (!hasAnnotation(p)) {
|
||||
throw new InvalidConstructorException("JCA90003 constructor parameters must have @Property or @Reference annotation");
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
parameters[i].setName(i < value.length ? value[i] : "");
|
||||
}
|
||||
type.setConstructor(definition);
|
||||
}
|
||||
|
||||
private boolean hasAnnotation(JavaParameterImpl p) {
|
||||
if (p.getAnnotations() != null && p.getAnnotations().length > 0) {
|
||||
return true;
|
||||
}
|
||||
// TODO: need to verify JCA90003 as it seems like any annotation should be ok not just SCA ref or prop
|
||||
// if (p.getAnnotation(Reference.class) != null) {
|
||||
// return true;
|
||||
// }
|
||||
// if (p.getAnnotation(Property.class) != null) {
|
||||
// return true;
|
||||
// }
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ public class ConstructorProcessorTestCase {
|
|||
|
||||
private static class Foo {
|
||||
@org.oasisopen.sca.annotation.Constructor("foo")
|
||||
public Foo(String foo) {
|
||||
public Foo(@Property String foo) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue