You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by sv...@apache.org on 2007/12/20 18:01:58 UTC
svn commit: r605979 - in /incubator/tuscany/java/sca/modules:
assembly/src/main/java/org/apache/tuscany/sca/assembly/
assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/
implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implemen...
Author: svkrish
Date: Thu Dec 20 09:01:57 2007
New Revision: 605979
URL: http://svn.apache.org/viewvc?rev=605979&view=rev
Log:
consolidating introspection of policy annotatations
Modified:
incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Callback.java
incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/OperationsConfigurator.java
incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CallbackImpl.java
incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/PolicyHandlingInterceptor.java
incubator/tuscany/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessor.java
incubator/tuscany/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessorTestCase.java
Modified: incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Callback.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Callback.java?rev=605979&r1=605978&r2=605979&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Callback.java (original)
+++ incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Callback.java Thu Dec 20 09:01:57 2007
@@ -28,7 +28,7 @@
*
* @version $Rev$ $Date$
*/
-public interface Callback extends Base, Extensible, IntentAttachPoint, PolicySetAttachPoint {
+public interface Callback extends Base, Extensible, IntentAttachPoint, PolicySetAttachPoint, OperationsConfigurator {
/**
* Returns the bindings supported for callbacks.
Modified: incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/OperationsConfigurator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/OperationsConfigurator.java?rev=605979&r1=605978&r2=605979&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/OperationsConfigurator.java (original)
+++ incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/OperationsConfigurator.java Thu Dec 20 09:01:57 2007
@@ -30,5 +30,4 @@
public interface OperationsConfigurator {
List<ConfiguredOperation> getConfiguredOperations();
- void setConfiguredOperations(List<ConfiguredOperation> cofiguredOps);
}
Modified: incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CallbackImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CallbackImpl.java?rev=605979&r1=605978&r2=605979&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CallbackImpl.java (original)
+++ incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CallbackImpl.java Thu Dec 20 09:01:57 2007
@@ -24,6 +24,7 @@
import org.apache.tuscany.sca.assembly.Binding;
import org.apache.tuscany.sca.assembly.Callback;
+import org.apache.tuscany.sca.assembly.ConfiguredOperation;
import org.apache.tuscany.sca.policy.Intent;
import org.apache.tuscany.sca.policy.IntentAttachPointType;
import org.apache.tuscany.sca.policy.PolicySet;
@@ -37,6 +38,8 @@
private List<Binding> bindings = new ArrayList<Binding>();
private List<Intent> requiredIntents = new ArrayList<Intent>();
private List<PolicySet> policySets = new ArrayList<PolicySet>();
+ private List<ConfiguredOperation> configuredOperations = new ArrayList<ConfiguredOperation>();
+
public List<PolicySet> getPolicySets() {
return policySets;
@@ -66,6 +69,10 @@
public void setRequiredIntents(List<Intent> intents) {
this.requiredIntents = intents;
+ }
+
+ public List<ConfiguredOperation> getConfiguredOperations() {
+ return configuredOperations;
}
}
Modified: incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/PolicyHandlingInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/PolicyHandlingInterceptor.java?rev=605979&r1=605978&r2=605979&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/PolicyHandlingInterceptor.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/PolicyHandlingInterceptor.java Thu Dec 20 09:01:57 2007
@@ -45,9 +45,7 @@
applyPreInvocationPolicies(targetOperation, msg);
msg = next.invoke(msg);
} finally {
- if ( !msg.isFault() ) {
- applyPostInvocationPolices(targetOperation, msg);
- }
+ applyPostInvocationPolices(targetOperation, msg);
}
return msg;
}
Modified: incubator/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/incubator/tuscany/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessor.java?rev=605979&r1=605978&r2=605979&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessor.java Thu Dec 20 09:01:57 2007
@@ -18,6 +18,7 @@
*/
package org.apache.tuscany.sca.implementation.java.introspect.impl;
+import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.List;
@@ -25,11 +26,13 @@
import org.apache.tuscany.sca.assembly.AssemblyFactory;
import org.apache.tuscany.sca.assembly.Callback;
+import org.apache.tuscany.sca.assembly.ConfiguredOperation;
+import org.apache.tuscany.sca.assembly.OperationsConfigurator;
+import org.apache.tuscany.sca.assembly.Reference;
import org.apache.tuscany.sca.assembly.Service;
import org.apache.tuscany.sca.implementation.java.IntrospectionException;
import org.apache.tuscany.sca.implementation.java.JavaImplementation;
import org.apache.tuscany.sca.interfacedef.InterfaceContract;
-import org.apache.tuscany.sca.interfacedef.Operation;
import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
import org.apache.tuscany.sca.policy.Intent;
@@ -105,14 +108,14 @@
}
}
- private void readIntents(Method method, List<Intent> requiredIntents) {
- Requires intentAnnotation = method.getAnnotation(Requires.class);
+ private void readIntents(Requires intentAnnotation, List<Intent> requiredIntents) {
+ //Requires intentAnnotation = method.getAnnotation(Requires.class);
if (intentAnnotation != null) {
String[] intentNames = intentAnnotation.value();
if (intentNames.length != 0) {
- Operation operation = assemblyFactory.createOperation();
- operation.setName(method.getName());
- operation.setUnresolved(true);
+ //Operation operation = assemblyFactory.createOperation();
+ //operation.setName(method.getName());
+ //operation.setUnresolved(true);
for (String intentName : intentNames) {
// Add each intent to the list, associated with the
@@ -125,6 +128,25 @@
}
}
}
+
+ private void readPolicySets(PolicySets policySetAnnotation, List<PolicySet> policySets) {
+ if (policySetAnnotation != null) {
+ String[] policySetNames = policySetAnnotation.value();
+ if (policySetNames.length != 0) {
+ //Operation operation = assemblyFactory.createOperation();
+ //operation.setName(method.getName());
+ //operation.setUnresolved(true);
+ for (String policySetName : policySetNames) {
+ // Add each intent to the list, associated with the
+ // operation corresponding to the annotated method
+ PolicySet policySet = policyFactory.createPolicySet();
+ policySet.setName(getQName(policySetName));
+ //intent.getOperations().add(operation);
+ policySets.add(policySet);
+ }
+ }
+ }
+ }
@Override
public <T> void visitClass(Class<T> clazz, JavaImplementation type) throws IntrospectionException {
@@ -153,8 +175,14 @@
// Read intents on the service interface methods
Method[] methods = javaInterface.getJavaClass().getMethods();
+ ConfiguredOperation confOp = null;
for (Method method: methods) {
- readIntents(method, service.getRequiredIntents());
+ confOp = assemblyFactory.createConfiguredOperation();
+ confOp.setName(method.getName());
+ confOp.setContractName(service.getName());
+ service.getConfiguredOperations().add(confOp);
+ readIntents(method.getAnnotation(Requires.class), confOp.getRequiredIntents());
+ readPolicySets(method.getAnnotation(PolicySets.class), confOp.getPolicySets());
}
}
@@ -175,8 +203,13 @@
// Read intents on the callback interface methods
Method[] methods = javaCallbackInterface.getJavaClass().getMethods();
+ ConfiguredOperation confOp = null;
for (Method method: methods) {
- readIntents(method, callback.getRequiredIntents());
+ confOp = assemblyFactory.createConfiguredOperation();
+ confOp.setName(method.getName());
+ callback.getConfiguredOperations().add(confOp);
+ readIntents(method.getAnnotation(Requires.class), confOp.getRequiredIntents());
+ readPolicySets(method.getAnnotation(PolicySets.class), confOp.getPolicySets());
}
}
}
@@ -184,12 +217,69 @@
}
}
+ private Reference getReference(Method method, JavaImplementation type) {
+ //since the ReferenceProcessor is called ahead of the PolicyProcessor the type should have
+ //picked up the reference setter method
+ org.osoa.sca.annotations.Reference annotation =
+ method.getAnnotation(org.osoa.sca.annotations.Reference.class);
+ if (annotation != null) {
+ if (JavaIntrospectionHelper.isSetter(method)) {
+ String name = annotation.name();
+ if ("".equals(name)) {
+ name = JavaIntrospectionHelper.toPropertyName(method.getName());
+ }
+ return getReferenceByName(name, type);
+ }
+ }
+ return null;
+ }
+
+ private Reference getReferenceByName(String name, JavaImplementation type) {
+ for ( Reference reference : type.getReferences() ) {
+ if ( reference.getName().equals(name) ) {
+ return reference;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public void visitField(Field field, JavaImplementation type) throws IntrospectionException {
+ org.osoa.sca.annotations.Reference annotation =
+ field.getAnnotation( org.osoa.sca.annotations.Reference.class);
+ if (annotation == null) {
+ return;
+ }
+ String name = annotation.name();
+ if ("".equals(name)) {
+ name = field.getName();
+ }
+
+ Reference reference = null;
+ if ( (reference = getReferenceByName(name, type)) != null ) {
+ readIntents(field.getAnnotation(Requires.class), reference.getRequiredIntents());
+ readPolicySets(field.getAnnotation(PolicySets.class), reference.getPolicySets());
+ }
+ }
+
@Override
public void visitMethod(Method method, JavaImplementation type) throws IntrospectionException {
-
- // Read the intents specified on the given implementation method
- if ( type instanceof PolicySetAttachPoint ) {
- readIntents(method, ((PolicySetAttachPoint)type).getRequiredIntents());
+ Reference reference = null;
+ if ( (reference = getReference(method, type)) != null ) {
+ readIntents(method.getAnnotation(Requires.class), reference.getRequiredIntents());
+ readPolicySets(method.getAnnotation(PolicySets.class), reference.getPolicySets());
+ } else {
+ if ( type instanceof OperationsConfigurator ) {
+ ConfiguredOperation confOp = assemblyFactory.createConfiguredOperation();
+ confOp.setName(method.getName());
+ ((OperationsConfigurator)type).getConfiguredOperations().add(confOp);
+
+ // Read the intents specified on the given implementation method
+ if ( type instanceof PolicySetAttachPoint ) {
+ readIntents(method.getAnnotation(Requires.class), confOp.getRequiredIntents());
+ readPolicySets(method.getAnnotation(PolicySets.class), confOp.getPolicySets());
+ }
+ }
}
}
}
Modified: incubator/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/incubator/tuscany/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessorTestCase.java?rev=605979&r1=605978&r2=605979&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessorTestCase.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessorTestCase.java Thu Dec 20 09:01:57 2007
@@ -25,7 +25,9 @@
import junit.framework.TestCase;
+import org.apache.tuscany.sca.assembly.ConfiguredOperation;
import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.assembly.OperationsConfigurator;
import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
import org.apache.tuscany.sca.implementation.java.JavaImplementation;
import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
@@ -47,31 +49,31 @@
// This actually is a test for PolicyJavaInterfaceProcessor. It will get
// invoked via the call to ImplementationProcessorServiceImpl.createService in
// ServiceProcessor. Of course ServiceProcessor class has to be working.
- public void testSingleInterfaceWithIntentsOnInterfaceAtInterfaceLevel() throws Exception {
+ public void stestSingleInterfaceWithIntentsOnInterfaceAtInterfaceLevel() throws Exception {
serviceProcessor.visitClass(Service1.class, type);
policyProcessor.visitClass(Service1.class, type);
verifyIntents(Service1.class, type);
}
- public void testMultipleInterfacesWithIntentsOnInterfaceAtInterfaceLevel() throws Exception {
+ public void stestMultipleInterfacesWithIntentsOnInterfaceAtInterfaceLevel() throws Exception {
serviceProcessor.visitClass(Service2.class, type);
policyProcessor.visitClass(Service2.class, type);
verifyIntents(Service2.class, type);
}
- public void testSingleInterfaceWithIntentsOnImplAtClassLevel() throws Exception {
+ public void stestSingleInterfaceWithIntentsOnImplAtClassLevel() throws Exception {
serviceProcessor.visitClass(Service3.class, type);
policyProcessor.visitClass(Service3.class, type);
verifyIntents(Service3.class, type);
}
- public void testMultipleInterfacesWithIntentsOnImplAtClassLevel() throws Exception {
+ public void stestMultipleInterfacesWithIntentsOnImplAtClassLevel() throws Exception {
serviceProcessor.visitClass(Service4.class, type);
policyProcessor.visitClass(Service4.class, type);
verifyIntents(Service4.class, type);
}
- public void testSingleInterfaceWithIntentsOnInterfaceAtMethodLevel() throws Exception {
+ public void stestSingleInterfaceWithIntentsOnInterfaceAtMethodLevel() throws Exception {
serviceProcessor.visitClass(Service5.class, type);
policyProcessor.visitClass(Service5.class, type);
verifyIntents(Service5.class, type);
@@ -147,7 +149,7 @@
}
}
- /*for (Method method : interfaceClass.getDeclaredMethods()) {
+ for (Method method : interfaceClass.getDeclaredMethods()) {
Requires methodIntentAnnotation = method.getAnnotation(Requires.class);
// Verify that each of the Intents on each of the Service
@@ -155,23 +157,24 @@
if (methodIntentAnnotation != null) {
String[] methodIntents = methodIntentAnnotation.value();
if (methodIntents.length > 0) {
- List<Intent> requiredIntents = service.getRequiredIntents();
- if (requiredIntents.size() == 0) {
+ List<Intent> requiredIntents = null;
+ for ( ConfiguredOperation confOp : service.getConfiguredOperations() ) {
+ if ( confOp.getName().equals(method.getName()) &&
+ confOp.getContractName().equals(service.getName()) ) {
+ requiredIntents = confOp.getRequiredIntents();
+ }
+ }
+
+ if (requiredIntents == null || requiredIntents.size() == 0) {
fail("No Intents on operation " + method.getName());
}
for (String intent : methodIntents) {
boolean found = false;
for (Intent requiredIntent: requiredIntents) {
if (requiredIntent.getName().getLocalPart().equals(intent)) {
- for (Operation operation: requiredIntent.getOperations()) {
- if (operation.getName().equals(method.getName())) {
- found = true;
- break;
- }
- }
- }
- if (found)
+ found = true;
break;
+ }
}
assertTrue("Operation " + method.getName()
+ " did not contain Service Interface method intent "
@@ -180,7 +183,7 @@
}
}
}
- */
+
for (Method method : serviceImplClass.getDeclaredMethods()) {
Requires methodIntentAnnotation = method.getAnnotation(Requires.class);
@@ -190,28 +193,29 @@
if (methodIntentAnnotation != null) {
String[] methodIntents = methodIntentAnnotation.value();
if (methodIntents.length > 0) {
- List<Intent> requiredIntents = ((PolicySetAttachPoint)type).getRequiredIntents();
- if (requiredIntents.size() == 0) {
+ List<Intent> requiredIntents = null;
+ for ( ConfiguredOperation confOp : ((OperationsConfigurator)type).getConfiguredOperations() ) {
+ if ( confOp.getName().equals(method.getName()) ) {
+ requiredIntents = confOp.getRequiredIntents();
+ }
+ }
+
+ if (requiredIntents == null || requiredIntents.size() == 0) {
fail("No Intents on operation " + method.getName());
}
- /*for (String intent : methodIntents) {
+
+ for (String intent : methodIntents) {
boolean found = false;
for (Intent requiredIntent: requiredIntents) {
if (requiredIntent.getName().getLocalPart().equals(intent)) {
- for (Operation operation: requiredIntent.getOperations()) {
- if (operation.getName().equals(method.getName())) {
- found = true;
- break;
- }
- }
- }
- if (found)
+ found = true;
break;
+ }
}
assertTrue("Operation " + method.getName()
- + " did not contain Service Interface method intent "
+ + " did not contain Implementation method intent "
+ intent, found);
- }*/
+ }
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org