You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2009/10/21 01:08:06 UTC
svn commit: r827831 - in /tuscany/java/sca:
modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/
modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/
modules/implementation-java/src/main/ja...
Author: rfeng
Date: Tue Oct 20 23:08:05 2009
New Revision: 827831
URL: http://svn.apache.org/viewvc?rev=827831&view=rev
Log:
Fix for otest JCA_800? ...
Modified:
tuscany/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositePolicyBuilderImpl.java
tuscany/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessor.java
tuscany/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java
tuscany/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessorTestCase.java
tuscany/java/sca/otest/newlayout/tuscany-java-caa-test-runner/src/test/resources/tuscany-oasis-sca-tests-errors.properties
tuscany/java/sca/otest/newlayout/tuscany-java-caa-test-runner/src/test/tjava/org/apache/tuscany/sca/otest/TuscanyRuntimeBridge.java
Modified: tuscany/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositePolicyBuilderImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositePolicyBuilderImpl.java?rev=827831&r1=827830&r2=827831&view=diff
==============================================================================
--- tuscany/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositePolicyBuilderImpl.java (original)
+++ tuscany/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositePolicyBuilderImpl.java Tue Oct 20 23:08:05 2009
@@ -112,6 +112,23 @@
}
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 @@
}
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 @@
}
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 @@
// 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 @@
}
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 @@
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);
Modified: tuscany/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessor.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessor.java?rev=827831&r1=827830&r2=827831&view=diff
==============================================================================
--- tuscany/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessor.java (original)
+++ tuscany/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessor.java Tue Oct 20 23:08:05 2009
@@ -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 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 @@
* @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 @@
@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());
- }
+ 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 @@
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 @@
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("");
@@ -173,45 +181,6 @@
}
/**
- * 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
* @param requiredIntents
@@ -237,7 +206,6 @@
}
}
-
/**
* Read policy set annotations on a given interface or class
* @param policySetAnnotation
@@ -265,7 +233,7 @@
/**
* Utility methods
*/
-
+
/**
*
* @param intentName
@@ -285,5 +253,51 @@
}
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);
+ }
+ }
+
}
Modified: tuscany/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java?rev=827831&r1=827830&r2=827831&view=diff
==============================================================================
--- tuscany/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java (original)
+++ tuscany/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java Tue Oct 20 23:08:05 2009
@@ -197,9 +197,11 @@
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) {
Modified: tuscany/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessorTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessorTestCase.java?rev=827831&r1=827830&r2=827831&view=diff
==============================================================================
--- tuscany/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessorTestCase.java (original)
+++ tuscany/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessorTestCase.java Tue Oct 20 23:08:05 2009
@@ -414,12 +414,12 @@
@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;
}
Modified: tuscany/java/sca/otest/newlayout/tuscany-java-caa-test-runner/src/test/resources/tuscany-oasis-sca-tests-errors.properties
URL: http://svn.apache.org/viewvc/tuscany/java/sca/otest/newlayout/tuscany-java-caa-test-runner/src/test/resources/tuscany-oasis-sca-tests-errors.properties?rev=827831&r1=827830&r2=827831&view=diff
==============================================================================
--- tuscany/java/sca/otest/newlayout/tuscany-java-caa-test-runner/src/test/resources/tuscany-oasis-sca-tests-errors.properties (original)
+++ tuscany/java/sca/otest/newlayout/tuscany-java-caa-test-runner/src/test/resources/tuscany-oasis-sca-tests-errors.properties Tue Oct 20 23:08:05 2009
@@ -45,3 +45,12 @@
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
Modified: tuscany/java/sca/otest/newlayout/tuscany-java-caa-test-runner/src/test/tjava/org/apache/tuscany/sca/otest/TuscanyRuntimeBridge.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/otest/newlayout/tuscany-java-caa-test-runner/src/test/tjava/org/apache/tuscany/sca/otest/TuscanyRuntimeBridge.java?rev=827831&r1=827830&r2=827831&view=diff
==============================================================================
--- tuscany/java/sca/otest/newlayout/tuscany-java-caa-test-runner/src/test/tjava/org/apache/tuscany/sca/otest/TuscanyRuntimeBridge.java (original)
+++ tuscany/java/sca/otest/newlayout/tuscany-java-caa-test-runner/src/test/tjava/org/apache/tuscany/sca/otest/TuscanyRuntimeBridge.java Tue Oct 20 23:08:05 2009
@@ -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 @@
// 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)) {