Fix for otest JCA_800? ...
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@827831 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7e3adb0f57
commit
c53bddb7cd
6 changed files with 129 additions and 74 deletions
|
|
@ -112,6 +112,23 @@ public class CompositePolicyBuilderImpl extends BaseBuilderImpl implements Compo
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean checkMutualExclusion(PolicySubject subject, BuilderContext context) {
|
||||
if (subject == null) {
|
||||
return false;
|
||||
}
|
||||
// FIXME: [rfeng] When should the intents be resolved?
|
||||
resolveAndNormalize(subject, context.getDefinitions(), context);
|
||||
for (Intent i1 : subject.getRequiredIntents()) {
|
||||
for (Intent i2 : subject.getRequiredIntents()) {
|
||||
if (i1 != i2 && i1.getExcludedIntents().contains(i2) || i2.getExcludedIntents().contains(i1)) {
|
||||
error(context.getMonitor(), "MutuallyExclusiveIntents", subject, i1, i2);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit the policySets and intents from the implementation hierarchy
|
||||
|
|
@ -298,7 +315,8 @@ public class CompositePolicyBuilderImpl extends BaseBuilderImpl implements Compo
|
|||
}
|
||||
|
||||
protected void computePolicies(Composite composite, Definitions definitions, BuilderContext context) {
|
||||
|
||||
checkMutualExclusion(composite, context);
|
||||
|
||||
// compute policies recursively
|
||||
for (Component component : composite.getComponents()) {
|
||||
Implementation implementation = component.getImplementation();
|
||||
|
|
@ -308,10 +326,16 @@ public class CompositePolicyBuilderImpl extends BaseBuilderImpl implements Compo
|
|||
}
|
||||
|
||||
for (Component component : composite.getComponents()) {
|
||||
checkMutualExclusion(component, context);
|
||||
checkMutualExclusion(component.getImplementation(), context);
|
||||
|
||||
// Check component against implementation
|
||||
checkMutualExclusion(component, component.getImplementation(), context);
|
||||
|
||||
for (ComponentService componentService : component.getServices()) {
|
||||
checkMutualExclusion(componentService, context);
|
||||
checkMutualExclusion(componentService.getService(), context);
|
||||
|
||||
// Check component/service against componentType/service
|
||||
checkMutualExclusion(componentService, componentService.getService(), context);
|
||||
|
||||
|
|
@ -337,6 +361,7 @@ public class CompositePolicyBuilderImpl extends BaseBuilderImpl implements Compo
|
|||
// Find the corresponding binding in the componentType and inherit the intents/policySets
|
||||
if (componentService.getService() != null) {
|
||||
for (Binding binding : componentService.getService().getBindings()) {
|
||||
checkMutualExclusion((PolicySubject) binding, context);
|
||||
if (isEqual(ep.getBinding().getName(), binding.getName()) && (binding instanceof PolicySubject)) {
|
||||
checkMutualExclusion((PolicySubject)ep.getBinding(), (PolicySubject)binding, context);
|
||||
// Inherit from componentType.service.binding
|
||||
|
|
@ -359,6 +384,9 @@ public class CompositePolicyBuilderImpl extends BaseBuilderImpl implements Compo
|
|||
}
|
||||
|
||||
for (ComponentReference componentReference : component.getReferences()) {
|
||||
checkMutualExclusion(componentReference, context);
|
||||
checkMutualExclusion(componentReference.getReference(), context);
|
||||
|
||||
// Check component/reference against componentType/reference
|
||||
checkMutualExclusion(componentReference, componentReference.getReference(), context);
|
||||
|
||||
|
|
@ -388,6 +416,7 @@ public class CompositePolicyBuilderImpl extends BaseBuilderImpl implements Compo
|
|||
for (Binding binding : componentReference.getReference().getBindings()) {
|
||||
if (epr.getBinding() != null && isEqual(epr.getBinding().getName(), binding.getName())
|
||||
&& (binding instanceof PolicySubject)) {
|
||||
checkMutualExclusion((PolicySubject) binding, context);
|
||||
checkMutualExclusion((PolicySubject)epr.getBinding(), (PolicySubject)binding, context);
|
||||
// Inherit from componentType.reference.binding
|
||||
inherit(epr, binding);
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@
|
|||
package org.apache.tuscany.sca.implementation.java.introspect.impl;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.AnnotatedElement;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
|
@ -31,21 +33,19 @@ import javax.xml.namespace.QName;
|
|||
|
||||
import org.apache.tuscany.sca.assembly.AssemblyFactory;
|
||||
import org.apache.tuscany.sca.assembly.Reference;
|
||||
import org.apache.tuscany.sca.assembly.Service;
|
||||
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
|
||||
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
|
||||
import org.apache.tuscany.sca.implementation.java.IntrospectionException;
|
||||
import org.apache.tuscany.sca.implementation.java.JavaElementImpl;
|
||||
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.apache.tuscany.sca.interfacedef.Operation;
|
||||
import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
|
||||
import org.apache.tuscany.sca.interfacedef.java.JavaOperation;
|
||||
import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil;
|
||||
import org.apache.tuscany.sca.policy.Intent;
|
||||
import org.apache.tuscany.sca.policy.PolicyFactory;
|
||||
import org.apache.tuscany.sca.policy.PolicySet;
|
||||
import org.apache.tuscany.sca.policy.PolicySubject;
|
||||
import org.oasisopen.sca.ServiceRuntimeException;
|
||||
import org.oasisopen.sca.annotation.PolicySets;
|
||||
import org.oasisopen.sca.annotation.Qualifier;
|
||||
import org.oasisopen.sca.annotation.Requires;
|
||||
|
|
@ -56,15 +56,17 @@ import org.oasisopen.sca.annotation.Requires;
|
|||
* @version $Rev$ $Date$
|
||||
*/
|
||||
public class PolicyProcessor extends BaseJavaClassVisitor {
|
||||
|
||||
|
||||
private PolicyFactory policyFactory;
|
||||
|
||||
public PolicyProcessor(AssemblyFactory assemblyFactory, PolicyFactory policyFactory, JavaInterfaceFactory javaInterfaceFactory) {
|
||||
public PolicyProcessor(AssemblyFactory assemblyFactory,
|
||||
PolicyFactory policyFactory,
|
||||
JavaInterfaceFactory javaInterfaceFactory) {
|
||||
super(assemblyFactory);
|
||||
this.policyFactory = policyFactory;
|
||||
this.javaInterfaceFactory = javaInterfaceFactory;
|
||||
}
|
||||
|
||||
|
||||
public PolicyProcessor(ExtensionPointRegistry registry) {
|
||||
super(registry);
|
||||
FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class);
|
||||
|
|
@ -73,14 +75,11 @@ public class PolicyProcessor extends BaseJavaClassVisitor {
|
|||
|
||||
@Override
|
||||
public <T> void visitClass(Class<T> clazz, JavaImplementation type) throws IntrospectionException {
|
||||
|
||||
// Read intents on the Java implementation class
|
||||
if ( type instanceof PolicySubject ) {
|
||||
readIntentsAndPolicySets(clazz,
|
||||
((PolicySubject)type).getRequiredIntents(),
|
||||
((PolicySubject)type).getPolicySets());
|
||||
}
|
||||
|
||||
// Read intents on the Java implementation class
|
||||
readPolicySetAndIntents((PolicySubject)type, clazz);
|
||||
|
||||
/*
|
||||
// FIXME: [rfeng] We might want to refactor this out
|
||||
// Find the business methods in the implementation class for all services
|
||||
Set<Method> methods = new HashSet<Method>();
|
||||
|
|
@ -108,27 +107,36 @@ public class PolicyProcessor extends BaseJavaClassVisitor {
|
|||
PolicySubject subject = op;
|
||||
Method method = operation.getJavaMethod();
|
||||
if (subject != null) {
|
||||
readIntents(method.getAnnotation(Requires.class), subject.getRequiredIntents());
|
||||
readSpecificIntents(method.getAnnotations(), subject.getRequiredIntents());
|
||||
readPolicySets(method.getAnnotation(PolicySets.class), subject.getPolicySets());
|
||||
readPolicySetAndIntents(subject, method);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// Start to process annotations on the reference members
|
||||
Map<String, Reference> referenceMap = new HashMap<String, Reference>();
|
||||
for(Reference ref: type.getReferences()) {
|
||||
for (Reference ref : type.getReferences()) {
|
||||
referenceMap.put(ref.getName(), ref);
|
||||
}
|
||||
Map<String, JavaElementImpl> members = type.getReferenceMembers();
|
||||
for(Map.Entry<String, JavaElementImpl> e: members.entrySet()) {
|
||||
for (Map.Entry<String, JavaElementImpl> e : members.entrySet()) {
|
||||
Reference reference = referenceMap.get(e.getKey());
|
||||
readIntents(e.getValue().getAnnotation(Requires.class), reference.getRequiredIntents());
|
||||
readSpecificIntents(e.getValue().getAnnotations(), reference.getRequiredIntents());
|
||||
readPolicySets(e.getValue().getAnnotation(PolicySets.class), reference.getPolicySets());
|
||||
readPolicySetAndIntents(reference, e.getValue().getAnchor());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void readPolicySetAndIntents(PolicySubject subject, AnnotatedElement element) {
|
||||
readIntents(element.getAnnotation(Requires.class), subject.getRequiredIntents());
|
||||
readSpecificIntents(element.getAnnotations(), subject.getRequiredIntents());
|
||||
readPolicySets(element.getAnnotation(PolicySets.class), subject.getPolicySets());
|
||||
}
|
||||
|
||||
private void readPolicySetAndIntents(PolicySubject subject, JavaElementImpl element) {
|
||||
readIntents(element.getAnnotation(Requires.class), subject.getRequiredIntents());
|
||||
readSpecificIntents(element.getAnnotations(), subject.getRequiredIntents());
|
||||
readPolicySets(element.getAnnotation(PolicySets.class), subject.getPolicySets());
|
||||
}
|
||||
|
||||
private void readSpecificIntents(Annotation[] annotations, List<Intent> requiredIntents) {
|
||||
for (Annotation a : annotations) {
|
||||
org.oasisopen.sca.annotation.Intent intentAnnotation =
|
||||
|
|
@ -144,14 +152,14 @@ public class PolicyProcessor extends BaseJavaClassVisitor {
|
|||
qname = new QName(intentAnnotation.targetNamespace(), intentAnnotation.localPart());
|
||||
}
|
||||
Set<String> qualifiers = new HashSet<String>();
|
||||
for(Method m: a.annotationType().getMethods()) {
|
||||
for (Method m : a.annotationType().getMethods()) {
|
||||
Qualifier qualifier = m.getAnnotation(Qualifier.class);
|
||||
if (qualifier != null && m.getReturnType() == String[].class) {
|
||||
try {
|
||||
qualifiers.addAll(Arrays.asList((String[]) m.invoke(a)));
|
||||
qualifiers.addAll(Arrays.asList((String[])m.invoke(a)));
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
qualifiers.remove("");
|
||||
|
|
@ -172,45 +180,6 @@ public class PolicyProcessor extends BaseJavaClassVisitor {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read policy intents on the given interface or class
|
||||
* @param clazz
|
||||
* @param requiredIntents
|
||||
*/
|
||||
private void readIntentsAndPolicySets(Class<?> clazz,
|
||||
List<Intent> requiredIntents,
|
||||
List<PolicySet> policySets) {
|
||||
Requires intentAnnotation = clazz.getAnnotation(Requires.class);
|
||||
if (intentAnnotation != null) {
|
||||
String[] intentNames = intentAnnotation.value();
|
||||
if (intentNames.length != 0) {
|
||||
for (String intentName : intentNames) {
|
||||
|
||||
// Add each intent to the list
|
||||
Intent intent = policyFactory.createIntent();
|
||||
intent.setName(getQName(intentName));
|
||||
requiredIntents.add(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
readSpecificIntents(clazz.getAnnotations(), requiredIntents);
|
||||
|
||||
PolicySets policySetAnnotation = clazz.getAnnotation(PolicySets.class);
|
||||
if (policySetAnnotation != null) {
|
||||
String[] policySetNames = policySetAnnotation.value();
|
||||
if (policySetNames.length != 0) {
|
||||
for (String policySetName : policySetNames) {
|
||||
|
||||
// Add each intent to the list
|
||||
PolicySet policySet = policyFactory.createPolicySet();
|
||||
policySet.setName(getQName(policySetName));
|
||||
policySets.add(policySet);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read intent annotations on the given interface or class
|
||||
* @param intentAnnotation
|
||||
|
|
@ -237,7 +206,6 @@ public class PolicyProcessor extends BaseJavaClassVisitor {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read policy set annotations on a given interface or class
|
||||
* @param policySetAnnotation
|
||||
|
|
@ -265,7 +233,7 @@ public class PolicyProcessor extends BaseJavaClassVisitor {
|
|||
/**
|
||||
* Utility methods
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param intentName
|
||||
|
|
@ -285,5 +253,51 @@ public class PolicyProcessor extends BaseJavaClassVisitor {
|
|||
}
|
||||
return qname;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void visitField(Field field, JavaImplementation type) throws IntrospectionException {
|
||||
// Check if a field that is not an SCA reference has any policySet/intent annotations
|
||||
JavaElementImpl element = new JavaElementImpl(field);
|
||||
if (!type.getReferenceMembers().values().contains(element)) {
|
||||
PolicySubject subject = assemblyFactory.createComponent();
|
||||
readPolicySetAndIntents(subject, field);
|
||||
if (subject.getPolicySets().isEmpty() && subject.getRequiredIntents().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
throw new ServiceRuntimeException(
|
||||
"Field that is not an SCA reference cannot have policySet/intent annotations: " + field);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitConstructorParameter(JavaParameterImpl parameter, JavaImplementation type) {
|
||||
if (!type.getReferenceMembers().values().contains(parameter)) {
|
||||
PolicySubject subject = assemblyFactory.createComponent();
|
||||
readPolicySetAndIntents(subject, parameter);
|
||||
if (subject.getPolicySets().isEmpty() && subject.getRequiredIntents().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
throw new ServiceRuntimeException(
|
||||
"Constructor parameter that is not an SCA reference cannot have policySet/intent annotations: " + parameter);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitMethod(Method method, JavaImplementation type) throws IntrospectionException {
|
||||
Set<AnnotatedElement> annotatedElements = new HashSet<AnnotatedElement>();
|
||||
for (JavaElementImpl element : type.getReferenceMembers().values()) {
|
||||
annotatedElements.add(element.getAnchor());
|
||||
}
|
||||
// Check if a field that is not an SCA reference has any policySet/intent annotations
|
||||
if (!annotatedElements.contains(method)) {
|
||||
PolicySubject subject = assemblyFactory.createComponent();
|
||||
readPolicySetAndIntents(subject, method);
|
||||
if (subject.getPolicySets().isEmpty() && subject.getRequiredIntents().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
throw new ServiceRuntimeException(
|
||||
"Method that is not an SCA reference cannot have policySet/intent annotations: " + method);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -197,9 +197,11 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm
|
|||
if (javaImplementation.getServices().isEmpty()) {
|
||||
javaImplementation.getServices().add(assemblyFactory.createService());
|
||||
}
|
||||
} catch (Throwable e ) {
|
||||
throw new ContributionResolveException( "Resolving Java implementation: " + javaImplementation.getName(), e);
|
||||
} // end try
|
||||
} catch (Throwable e) {
|
||||
throw new ContributionResolveException("Resolving Java implementation: " + javaImplementation.getName()
|
||||
+ ", "
|
||||
+ e.getMessage(), e);
|
||||
} // end try
|
||||
} // end method
|
||||
|
||||
private void checkNoStaticAnnotations(Monitor monitor, JavaImplementation javaImplementation) {
|
||||
|
|
|
|||
|
|
@ -414,12 +414,12 @@ public class PolicyProcessorTestCase {
|
|||
@Service(Interface6.class)
|
||||
@Requires( {"transaction.global.Service6"})
|
||||
private class Service6 implements Interface6 {
|
||||
@Requires( {"transaction.global.Service6.method1"})
|
||||
// @Requires( {"transaction.global.Service6.method1"})
|
||||
public int method1() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Requires( {"transaction.global.Service6.method1"})
|
||||
// @Requires( {"transaction.global.Service6.method1"})
|
||||
public int method2() {
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,3 +45,12 @@ JCA_10050=org.oasisopen.sca.ServiceRuntimeException: [Composite: {http://docs.oa
|
|||
JCA_10051=org.apache.tuscany.sca.contribution.processor.ContributionResolveException: org.apache.tuscany.sca.implementation.java.IntrospectionException: JCA90059 The array of interfaces or classes specified by the value attribute of the @Service annotation
|
||||
JCA_10052=org.apache.tuscany.sca.contribution.processor.ContributionResolveException: org.apache.tuscany.sca.implementation.java.IntrospectionException: JCA90060 The value of each element in the @Service names array MUST be unique amongst all the other element values in the array
|
||||
JCA_11005=* org.apache.tuscany.sca.contribution.processor.ContributionReadException: java.io.FileNotFoundException: C:TuscanySVN2.x-trunkotestnewlayouttuscany-java-caa-test-runner..sca-java-caaJCA_11005targetJCA_11005.zip (The system cannot find the path specified)
|
||||
# Intent and PolicySet related tests
|
||||
JCA_8001=[POL40009] Intent {http://docs.oasis-open.org/ns/opencsa/scatests/200903}testIntent2 and {http://docs.oasis-open.org/ns/opencsa/scatests/200903}testIntent1 are mutually exclusive
|
||||
JCA_8002=Method that is not an SCA reference cannot have policySet/intent annotations
|
||||
JCA_8003=Field that is not an SCA reference cannot have policySet/intent annotations
|
||||
JCA_8004=Constructor parameter that is not an SCA reference cannot have policySet/intent annotations
|
||||
JCA_8006=[POL40009] Intent {http://docs.oasis-open.org/ns/opencsa/scatests/200903}testIntent2 and {http://docs.oasis-open.org/ns/opencsa/scatests/200903}testIntent1 are mutually exclusive
|
||||
JCA_8008=Method that is not an SCA reference cannot have policySet/intent annotations
|
||||
JCA_8009=Field that is not an SCA reference cannot have policySet/intent annotations
|
||||
JCA_8010=Constructor parameter that is not an SCA reference cannot have policySet/intent annotations
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
package org.apache.tuscany.sca.otest;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
|
|
@ -165,8 +166,8 @@ public class TuscanyRuntimeBridge implements RuntimeBridge {
|
|||
// and where the only relevant part is the start of the message - in this case the expected
|
||||
// message only contains the stem section which is unchanging...
|
||||
if( receivedMessage.length() > expectedMessage.length() ) {
|
||||
// Truncate the received message to the length of the expected message
|
||||
receivedMessage = receivedMessage.substring(0, expectedMessage.length() );
|
||||
assertTrue("Received message should contain the expected message", receivedMessage.contains(expectedMessage));
|
||||
return;
|
||||
} // end if
|
||||
|
||||
if (!expectedMessage.equals(receivedMessage)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue