You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by js...@apache.org on 2007/04/16 08:53:31 UTC

svn commit: r529146 - in /incubator/tuscany/java/sca/modules: assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/ binding-ws-xml/src/main/java/org/apache/tuscany/binding/ws/xml/ core-spring/src/test/java/test/model/variant/ host-embedded/src/ma...

Author: jsdelfino
Date: Sun Apr 15 23:53:28 2007
New Revision: 529146

URL: http://svn.apache.org/viewvc?view=rev&rev=529146
Log:
Fixed policy support. Policy intents are now read on Java implementations and WS bindings. Also added a policy annotation processor to read @Requires annotations on implementation classes, interfaces and methods, equivalent to the patch contributed in TUSCANY-1204.

Added:
    incubator/tuscany/java/sca/modules/implementation-java-xml/src/main/java/org/apache/tuscany/implementation/java/introspect/impl/PolicyProcessor.java   (with props)
    incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/PolicyProcessorTestCase.java   (with props)
Modified:
    incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/BaseArtifactProcessor.java
    incubator/tuscany/java/sca/modules/binding-ws-xml/src/main/java/org/apache/tuscany/binding/ws/xml/WebServiceBindingProcessor.java
    incubator/tuscany/java/sca/modules/core-spring/src/test/java/test/model/variant/VariantRuntimeContext.java
    incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/host/embedded/SimpleRuntimeImpl.java
    incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/implementation/java/module/JavaRuntimeModuleActivator.java
    incubator/tuscany/java/sca/modules/implementation-java-xml/src/main/java/org/apache/tuscany/implementation/java/xml/JavaImplementationProcessor.java

Modified: incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/BaseArtifactProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/BaseArtifactProcessor.java?view=diff&rev=529146&r1=529145&r2=529146
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/BaseArtifactProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/BaseArtifactProcessor.java Sun Apr 15 23:53:28 2007
@@ -72,7 +72,7 @@
  * 
  * @version $Rev$ $Date$
  */
-abstract class BaseArtifactProcessor implements Constants {
+public abstract class BaseArtifactProcessor implements Constants {
 
     protected AssemblyFactory factory;
     protected PolicyFactory policyFactory;
@@ -86,7 +86,7 @@
     /**
      * Constructs a new BaseArtifactProcessor.
      */
-    BaseArtifactProcessor() {
+    public BaseArtifactProcessor() {
     }
 
     /**
@@ -95,7 +95,7 @@
      * @param policyFactory
      */
     @SuppressWarnings("unchecked")
-    BaseArtifactProcessor(AssemblyFactory factory, PolicyFactory policyFactory, StAXArtifactProcessor extensionProcessor) {
+    public BaseArtifactProcessor(AssemblyFactory factory, PolicyFactory policyFactory, StAXArtifactProcessor extensionProcessor) {
         this.factory = factory;
         this.policyFactory = policyFactory;
         this.extensionProcessor = (StAXArtifactProcessor<Object>)extensionProcessor;
@@ -252,7 +252,7 @@
     }
     
     /**
-     * Read list of refence targets
+     * Read list of reference targets
      * @param reference
      * @param reader
      */

Modified: incubator/tuscany/java/sca/modules/binding-ws-xml/src/main/java/org/apache/tuscany/binding/ws/xml/WebServiceBindingProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-ws-xml/src/main/java/org/apache/tuscany/binding/ws/xml/WebServiceBindingProcessor.java?view=diff&rev=529146&r1=529145&r2=529146
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-ws-xml/src/main/java/org/apache/tuscany/binding/ws/xml/WebServiceBindingProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/binding-ws-xml/src/main/java/org/apache/tuscany/binding/ws/xml/WebServiceBindingProcessor.java Sun Apr 15 23:53:28 2007
@@ -28,6 +28,9 @@
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 
+import org.apache.tuscany.assembly.AssemblyFactory;
+import org.apache.tuscany.assembly.impl.DefaultAssemblyFactory;
+import org.apache.tuscany.assembly.xml.BaseArtifactProcessor;
 import org.apache.tuscany.assembly.xml.Constants;
 import org.apache.tuscany.binding.ws.WebServiceBinding;
 import org.apache.tuscany.binding.ws.WebServiceBindingFactory;
@@ -40,17 +43,22 @@
 import org.apache.tuscany.contribution.service.ContributionWriteException;
 import org.apache.tuscany.interfacedef.wsdl.WSDLDefinition;
 import org.apache.tuscany.interfacedef.wsdl.impl.DefaultWSDLFactory;
+import org.apache.tuscany.policy.PolicyFactory;
+import org.apache.tuscany.policy.impl.DefaultPolicyFactory;
 
-public class WebServiceBindingProcessor implements StAXArtifactProcessor<WebServiceBinding>, WebServiceConstants {
+public class WebServiceBindingProcessor extends BaseArtifactProcessor implements StAXArtifactProcessor<WebServiceBinding>, WebServiceConstants {
 
     private WebServiceBindingFactory wsFactory;
 
-    public WebServiceBindingProcessor(WebServiceBindingFactory wsFactory) {
+    public WebServiceBindingProcessor(AssemblyFactory assemblyFactory,
+                                      PolicyFactory policyFactory,
+                                      WebServiceBindingFactory wsFactory) {
+        super(assemblyFactory, policyFactory, null);
         this.wsFactory = wsFactory;
     }
     
     public WebServiceBindingProcessor() {
-        this(new DefaultWebServiceBindingFactory());
+        this(new DefaultAssemblyFactory(), new DefaultPolicyFactory(), new DefaultWebServiceBindingFactory());
     }
 
     public WebServiceBinding read(XMLStreamReader reader) throws ContributionReadException {
@@ -59,6 +67,9 @@
             // Read a <binding.ws>
             WebServiceBinding wsBinding = wsFactory.createWebServiceBinding();
             wsBinding.setUnresolved(true);
+            
+            // Read policies
+            readPolicies(wsBinding, reader);
 
             // Read URI
             wsBinding.setURI(reader.getAttributeValue(null, Constants.URI));

Modified: incubator/tuscany/java/sca/modules/core-spring/src/test/java/test/model/variant/VariantRuntimeContext.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core-spring/src/test/java/test/model/variant/VariantRuntimeContext.java?view=diff&rev=529146&r1=529145&r2=529146
==============================================================================
--- incubator/tuscany/java/sca/modules/core-spring/src/test/java/test/model/variant/VariantRuntimeContext.java (original)
+++ incubator/tuscany/java/sca/modules/core-spring/src/test/java/test/model/variant/VariantRuntimeContext.java Sun Apr 15 23:53:28 2007
@@ -66,7 +66,8 @@
         staxProcessors.addExtension(new ComponentTypeProcessor(assemblyFactory, policyFactory, staxProcessors));
         staxProcessors.addExtension(new ConstrainingTypeProcessor(staxProcessors));
         staxProcessors.addExtension(new JavaInterfaceProcessor());
-        staxProcessors.addExtension(new JavaImplementationProcessor(javaImplementationFactory, new DefaultJavaClassIntrospector()));
+        staxProcessors.addExtension(new JavaImplementationProcessor(
+            assemblyFactory, policyFactory, javaImplementationFactory, new DefaultJavaClassIntrospector()));
         
         // Create a resolver
         DefaultArtifactResolver resolver = new DefaultArtifactResolver();

Modified: incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/host/embedded/SimpleRuntimeImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/host/embedded/SimpleRuntimeImpl.java?view=diff&rev=529146&r1=529145&r2=529146
==============================================================================
--- incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/host/embedded/SimpleRuntimeImpl.java (original)
+++ incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/host/embedded/SimpleRuntimeImpl.java Sun Apr 15 23:53:28 2007
@@ -51,6 +51,7 @@
 import org.apache.tuscany.contribution.service.util.FileHelper;
 import org.apache.tuscany.core.bootstrap.ExtensionPointRegistryImpl;
 import org.apache.tuscany.core.component.SimpleWorkContext;
+import org.apache.tuscany.core.component.WorkContextImpl;
 import org.apache.tuscany.core.runtime.AbstractRuntime;
 import org.apache.tuscany.host.runtime.InitializationException;
 import org.apache.tuscany.spi.Scope;
@@ -139,7 +140,8 @@
         new FolderContributionProcessor(packageProcessors);
 
         // Create a work context
-        WorkContext workContext = new SimpleWorkContext();
+        //WorkContext workContext = new SimpleWorkContext();
+        WorkContext workContext = new WorkContextImpl();
         workContext.setIdentifier(Scope.COMPOSITE, DEFAULT_COMPOSITE);
         WorkContextTunnel.setThreadWorkContext(workContext);
 

Modified: incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/implementation/java/module/JavaRuntimeModuleActivator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/implementation/java/module/JavaRuntimeModuleActivator.java?view=diff&rev=529146&r1=529145&r2=529146
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/implementation/java/module/JavaRuntimeModuleActivator.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/implementation/java/module/JavaRuntimeModuleActivator.java Sun Apr 15 23:53:28 2007
@@ -38,6 +38,7 @@
 import org.apache.tuscany.implementation.java.introspect.impl.EagerInitProcessor;
 import org.apache.tuscany.implementation.java.introspect.impl.HeuristicPojoProcessor;
 import org.apache.tuscany.implementation.java.introspect.impl.InitProcessor;
+import org.apache.tuscany.implementation.java.introspect.impl.PolicyProcessor;
 import org.apache.tuscany.implementation.java.introspect.impl.PropertyProcessor;
 import org.apache.tuscany.implementation.java.introspect.impl.ReferenceProcessor;
 import org.apache.tuscany.implementation.java.introspect.impl.ResourceProcessor;
@@ -79,23 +80,21 @@
 
         JavaClassIntrospectorExtensionPoint classIntrospector = extensionPointRegistry
             .getExtensionPoint(JavaClassIntrospectorExtensionPoint.class);
-        BaseJavaClassIntrospectorExtension[] extensions = new BaseJavaClassIntrospectorExtension[] {new ConstructorProcessor(),
-                                                                                                    new AllowsPassByReferenceProcessor(),
-                                                                                                    new ContextProcessor(),
-                                                                                                    new ConversationProcessor(),
-                                                                                                    new DestroyProcessor(),
-                                                                                                    new EagerInitProcessor(),
-                                                                                                    new InitProcessor(),
-                                                                                                    new PropertyProcessor(),
-                                                                                                    new ReferenceProcessor(
-                                                                                                                           interfaceIntrospector),
-                                                                                                    new ResourceProcessor(),
-                                                                                                    new ScopeProcessor(),
-                                                                                                    new ServiceProcessor(
-                                                                                                                         interfaceIntrospector),
-                                                                                                    new HeuristicPojoProcessor(
-                                                                                                                               interfaceIntrospector)
-
+        BaseJavaClassIntrospectorExtension[] extensions = new BaseJavaClassIntrospectorExtension[] {
+            new ConstructorProcessor(),
+            new AllowsPassByReferenceProcessor(),
+            new ContextProcessor(),
+            new ConversationProcessor(),
+            new DestroyProcessor(),
+            new EagerInitProcessor(),
+            new InitProcessor(),
+            new PropertyProcessor(),
+            new ReferenceProcessor(interfaceIntrospector),
+            new ResourceProcessor(),
+            new ScopeProcessor(),
+            new ServiceProcessor(interfaceIntrospector),
+            new HeuristicPojoProcessor(interfaceIntrospector),
+            new PolicyProcessor()
         };
         for (JavaClassIntrospectorExtension e : extensions) {
             classIntrospector.addExtension(e);

Added: incubator/tuscany/java/sca/modules/implementation-java-xml/src/main/java/org/apache/tuscany/implementation/java/introspect/impl/PolicyProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-xml/src/main/java/org/apache/tuscany/implementation/java/introspect/impl/PolicyProcessor.java?view=auto&rev=529146
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-xml/src/main/java/org/apache/tuscany/implementation/java/introspect/impl/PolicyProcessor.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-java-xml/src/main/java/org/apache/tuscany/implementation/java/introspect/impl/PolicyProcessor.java Sun Apr 15 23:53:28 2007
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.implementation.java.introspect.impl;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.assembly.Callback;
+import org.apache.tuscany.assembly.Service;
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.introspect.BaseJavaClassIntrospectorExtension;
+import org.apache.tuscany.implementation.java.introspect.IntrospectionException;
+import org.apache.tuscany.interfacedef.InterfaceContract;
+import org.apache.tuscany.interfacedef.Operation;
+import org.apache.tuscany.interfacedef.java.JavaInterface;
+import org.apache.tuscany.interfacedef.java.JavaInterfaceContract;
+import org.apache.tuscany.policy.Intent;
+import org.apache.tuscany.policy.PolicyFactory;
+import org.apache.tuscany.policy.impl.DefaultPolicyFactory;
+import org.osoa.sca.annotations.Requires;
+
+/**
+ * Processes an {@link org.osoa.sca.annotations.Requires} annotation
+ * 
+ * @version $Rev:
+ */
+public class PolicyProcessor extends BaseJavaClassIntrospectorExtension {
+
+    private PolicyFactory policyFactory;
+
+    public PolicyProcessor() {
+        this.policyFactory = new DefaultPolicyFactory();
+    }
+
+    private QName getQName(String intentName) {
+        QName qname;
+        if (intentName.startsWith("{")) {
+            int i = intentName.indexOf('}');
+            if (i != -1) {
+                qname = new QName(intentName.substring(1, i), intentName.substring(i + 1));
+            } else {
+                qname = new QName("", intentName);
+            }
+        } else {
+            qname = new QName("", intentName);
+        }
+        return qname;
+    }
+
+    /**
+     * Read policy intents on the given interface or class 
+     * @param clazz
+     * @param requiredIntents
+     */
+    private void readIntents(Class<?> clazz, List<Intent> requiredIntents) {
+        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);
+                }
+            }
+        }
+    }
+    
+    private void readIntents(Method method, List<Intent> requiredIntents) {
+        Requires intentAnnotation = method.getAnnotation(Requires.class);
+        if (intentAnnotation != null) {
+            String[] intentNames = intentAnnotation.value();
+            if (intentNames.length != 0) {
+                Operation operation = factory.createOperation();
+                operation.setName(method.getName());
+                operation.setUnresolved(true);
+                for (String intentName : intentNames) {
+
+                    // Add each intent to the list, associated with the
+                    // operation corresponding to the annotated method
+                    Intent intent = policyFactory.createIntent();
+                    intent.setName(getQName(intentName));
+                    intent.getOperations().add(operation);
+                    requiredIntents.add(intent);
+                }
+            }
+        }
+    }
+
+    public <T> void visitClass(Class<T> clazz, JavaImplementationDefinition type) throws IntrospectionException {
+        
+        // Read intents on the Java implementation class
+        readIntents(clazz, type.getRequiredIntents());
+        
+        // Process annotations on the service interfaces
+        //TODO This will have to move to a JavaInterface introspector later
+        for (Service service: type.getServices()) {
+            InterfaceContract interfaceContract = service.getInterfaceContract();
+            if (interfaceContract instanceof JavaInterfaceContract) {
+                JavaInterfaceContract javaInterfaceContract = (JavaInterfaceContract)interfaceContract;
+
+                // Read intents on the service interface
+                if (javaInterfaceContract.getInterface() != null) {
+                    JavaInterface javaInterface = (JavaInterface)javaInterfaceContract.getInterface();
+                    if (javaInterface.getJavaClass() != null) {
+                        readIntents(javaInterface.getJavaClass(), service.getRequiredIntents());
+
+                        // Read intents on the service interface methods 
+                        Method[] methods = javaInterface.getJavaClass().getMethods();
+                        for (Method method: methods) {
+                            readIntents(method, service.getRequiredIntents());
+                        }
+                    }
+                    
+                }
+                
+                // Read intents on the callback interface 
+                if (javaInterfaceContract.getCallbackInterface() != null) {
+                    JavaInterface javaCallbackInterface = (JavaInterface)javaInterfaceContract.getCallbackInterface();
+                    if (javaCallbackInterface.getJavaClass() != null) {
+                        Callback callback = service.getCallback();
+                        if (callback == null) {
+                            callback = factory.createCallback();
+                            service.setCallback(callback);
+                        }
+                        readIntents(javaCallbackInterface.getJavaClass(), callback.getRequiredIntents());
+
+                        // Read intents on the callback interface methods 
+                        Method[] methods = javaCallbackInterface.getJavaClass().getMethods();
+                        for (Method method: methods) {
+                            readIntents(method, callback.getRequiredIntents());
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    public void visitMethod(Method method, JavaImplementationDefinition type) throws IntrospectionException {
+        
+        // Read the intents specified on the given implementation method
+        readIntents(method, type.getRequiredIntents());
+    }
+}

Propchange: incubator/tuscany/java/sca/modules/implementation-java-xml/src/main/java/org/apache/tuscany/implementation/java/introspect/impl/PolicyProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-java-xml/src/main/java/org/apache/tuscany/implementation/java/introspect/impl/PolicyProcessor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/modules/implementation-java-xml/src/main/java/org/apache/tuscany/implementation/java/xml/JavaImplementationProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-xml/src/main/java/org/apache/tuscany/implementation/java/xml/JavaImplementationProcessor.java?view=diff&rev=529146&r1=529145&r2=529146
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-xml/src/main/java/org/apache/tuscany/implementation/java/xml/JavaImplementationProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-java-xml/src/main/java/org/apache/tuscany/implementation/java/xml/JavaImplementationProcessor.java Sun Apr 15 23:53:28 2007
@@ -26,8 +26,10 @@
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 
+import org.apache.tuscany.assembly.AssemblyFactory;
 import org.apache.tuscany.assembly.impl.DefaultAssemblyFactory;
 import org.apache.tuscany.assembly.impl.ServiceImpl;
+import org.apache.tuscany.assembly.xml.BaseArtifactProcessor;
 import org.apache.tuscany.assembly.xml.Constants;
 import org.apache.tuscany.contribution.processor.StAXArtifactProcessor;
 import org.apache.tuscany.contribution.resolver.ArtifactResolver;
@@ -41,24 +43,36 @@
 import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
 import org.apache.tuscany.implementation.java.introspect.DefaultJavaClassIntrospector;
 import org.apache.tuscany.implementation.java.introspect.JavaClassIntrospectorExtensionPoint;
+import org.apache.tuscany.policy.PolicyFactory;
+import org.apache.tuscany.policy.impl.DefaultPolicyFactory;
 
-public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaImplementation>,
+public class JavaImplementationProcessor extends BaseArtifactProcessor implements StAXArtifactProcessor<JavaImplementation>,
     JavaImplementationConstants {
 
     private JavaImplementationFactory javaFactory;
     private JavaClassIntrospectorExtensionPoint introspector;
 
-    public JavaImplementationProcessor(JavaImplementationFactory javaFactory, JavaClassIntrospectorExtensionPoint introspector) {
+    public JavaImplementationProcessor(AssemblyFactory assemblyFactory,
+                                       PolicyFactory policyFactory,
+                                       JavaImplementationFactory javaFactory,
+                                       JavaClassIntrospectorExtensionPoint introspector) {
+        super(assemblyFactory, policyFactory, null);
         this.javaFactory = javaFactory;
         this.introspector = introspector;
     }
 
     public JavaImplementationProcessor(JavaClassIntrospectorExtensionPoint introspector) {
-        this(new DefaultJavaImplementationFactory(new DefaultAssemblyFactory()), introspector);
+        this(new DefaultAssemblyFactory(),
+             new DefaultPolicyFactory(),
+             new DefaultJavaImplementationFactory(new DefaultAssemblyFactory()),
+             introspector);
     }
 
     public JavaImplementationProcessor() {
-        this(new DefaultJavaImplementationFactory(new DefaultAssemblyFactory()), new DefaultJavaClassIntrospector());
+        this(new DefaultAssemblyFactory(),
+             new DefaultPolicyFactory(),
+             new DefaultJavaImplementationFactory(new DefaultAssemblyFactory()),
+             new DefaultJavaClassIntrospector());
     }
 
     public JavaImplementation read(XMLStreamReader reader) throws ContributionReadException {
@@ -69,6 +83,9 @@
             JavaImplementation javaImplementation = javaFactory.createJavaImplementation();
             javaImplementation.setUnresolved(true);
             javaImplementation.setName(reader.getAttributeValue(null, CLASS));
+            
+            // Read policies
+            readPolicies(javaImplementation, reader);
 
             // Skip to end element
             while (reader.hasNext()) {

Added: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/PolicyProcessorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/PolicyProcessorTestCase.java?view=auto&rev=529146
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/PolicyProcessorTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/PolicyProcessorTestCase.java Sun Apr 15 23:53:28 2007
@@ -0,0 +1,397 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.implementation.java.introspect.impl;
+
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.interfacedef.Operation;
+import org.apache.tuscany.interfacedef.java.introspect.DefaultJavaInterfaceIntrospector;
+import org.apache.tuscany.policy.Intent;
+import org.osoa.sca.annotations.Requires;
+import org.osoa.sca.annotations.Service;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class PolicyProcessorTestCase extends TestCase {
+    private ServiceProcessor serviceProcessor;
+    private PolicyProcessor policyProcessor;
+    private JavaImplementationDefinition type;
+
+    // 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 {
+        serviceProcessor.visitClass(Service1.class, type);
+        policyProcessor.visitClass(Service1.class, type);
+        verifyIntents(Service1.class, type);
+    }
+
+    public void testMultipleInterfacesWithIntentsOnInterfaceAtInterfaceLevel() throws Exception {
+        serviceProcessor.visitClass(Service2.class, type);
+        policyProcessor.visitClass(Service2.class, type);
+        verifyIntents(Service2.class, type);
+    }
+
+    public void testSingleInterfaceWithIntentsOnImplAtClassLevel() throws Exception {
+        serviceProcessor.visitClass(Service3.class, type);
+        policyProcessor.visitClass(Service3.class, type);
+        verifyIntents(Service3.class, type);
+    }
+
+    public void testMultipleInterfacesWithIntentsOnImplAtClassLevel() throws Exception {
+        serviceProcessor.visitClass(Service4.class, type);
+        policyProcessor.visitClass(Service4.class, type);
+        verifyIntents(Service4.class, type);
+    }
+
+    public void testSingleInterfaceWithIntentsOnInterfaceAtMethodLevel() throws Exception {
+        serviceProcessor.visitClass(Service5.class, type);
+        policyProcessor.visitClass(Service5.class, type);
+        verifyIntents(Service5.class, type);
+    }
+
+    public void testSingleInterfaceWithIntentsOnServiceAndInterfaceAtImplAndInertfaceAndMethodLevel() throws Exception {
+        serviceProcessor.visitClass(Service6.class, type);
+        policyProcessor.visitClass(Service6.class, type);
+        for (Method method : Service6.class.getDeclaredMethods()) {
+            policyProcessor.visitMethod(method, type);
+        }
+        verifyIntents(Service6.class, type);
+    }
+
+    private void verifyIntents(Class serviceImplClass, JavaImplementationDefinition type) {
+
+        Requires serviceImplIntentAnnotation = (Requires)serviceImplClass.getAnnotation(Requires.class);
+        if (serviceImplIntentAnnotation != null) {
+            String[] serviceImplIntents = serviceImplIntentAnnotation.value();
+            List<Intent> requiredIntents = type.getRequiredIntents();
+            if (serviceImplIntents.length > 0) {
+                if (requiredIntents == null || requiredIntents.size() == 0) {
+                    fail("No Intents on the service ");
+                }
+                Map<String, Intent> intentMap = new HashMap<String, Intent>();
+                for (Intent intent : requiredIntents) {
+                    intentMap.put(intent.getName().getLocalPart(), intent);
+                }
+                for (String intent : serviceImplIntents) {
+                    assertTrue("ComponentType for Service class " + serviceImplClass.getName()
+                        + " did not contain Service Implementation intent "
+                        + intent, intentMap.containsKey(intent));
+                }
+            }
+        }
+
+        // This should match what was specified on @Service for a Service Implementation
+        // If we use these to get the Service names and we get a null Service
+        // name then it would seem that wrong values were put on the @Service annotation
+        // or the wrong interfaces were specified on the implements list of the class
+        // statement?
+        Map<String, org.apache.tuscany.assembly.Service> serviceMap = new HashMap<String, org.apache.tuscany.assembly.Service>();
+        for (org.apache.tuscany.assembly.Service service: type.getServices()) {
+            serviceMap.put(service.getName(), service);
+        }
+        for (Class interfaceClass : serviceImplClass.getInterfaces()) {
+            Requires interfaceIntentAnnotation = (Requires)interfaceClass.getAnnotation(Requires.class);
+            org.apache.tuscany.assembly.Service service = serviceMap.get(interfaceClass.getSimpleName());
+            if (service == null) {
+                fail("No service defined for interface " + interfaceClass.getSimpleName()
+                    + " on Service Implementation "
+                    + serviceImplClass.getName());
+            }
+
+            if (interfaceIntentAnnotation != null) {
+                String[] interfaceIntents = interfaceIntentAnnotation.value();
+                List<Intent> requiredIntents = service.getRequiredIntents();
+                if (interfaceIntents.length > 0) {
+                    if (requiredIntents == null || requiredIntents.size() == 0) {
+                        fail("No Intents on the service " + service.getName());
+                    }
+                    Map<String, Intent> intentMap = new HashMap<String, Intent>();
+                    for (Intent intent : requiredIntents) {
+                        intentMap.put(intent.getName().getLocalPart(), intent);
+                    }
+                    for (String intent : interfaceIntents) {
+                        assertTrue("Interface " + service.getName()
+                            + " did not contain Service Interface intent "
+                            + intent, intentMap.containsKey(intent));
+                    }
+                }
+            }
+
+            for (Method method : interfaceClass.getDeclaredMethods()) {
+                Requires methodIntentAnnotation = method.getAnnotation(Requires.class);
+
+                // Verify that each of the Intents on each of the Service
+                // Interface Methods exist on their associated operation.
+                if (methodIntentAnnotation != null) {
+                    String[] methodIntents = methodIntentAnnotation.value();
+                    if (methodIntents.length > 0) {
+                        List<Intent> requiredIntents = service.getRequiredIntents();
+                        if (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)
+                                    break;
+                            }
+                            assertTrue("Operation " + method.getName()
+                                + " did not contain Service Interface method intent "
+                                + intent, found);
+                        }
+                    }
+                }
+            }
+
+            for (Method method : serviceImplClass.getDeclaredMethods()) {
+                Requires methodIntentAnnotation = method.getAnnotation(Requires.class);
+
+                // Verify that each of the Intents on each of the Service
+                // Implementation Methods exist on their associated
+                // operation.
+                if (methodIntentAnnotation != null) {
+                    String[] methodIntents = methodIntentAnnotation.value();
+                    if (methodIntents.length > 0) {
+                        List<Intent> requiredIntents = type.getRequiredIntents();
+                        if (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)
+                                    break;
+                            }
+                            assertTrue("Operation " + method.getName()
+                                + " did not contain Service Interface method intent "
+                                + intent, found);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        DefaultJavaInterfaceIntrospector introspector = new DefaultJavaInterfaceIntrospector();
+        serviceProcessor = new ServiceProcessor(introspector);
+        policyProcessor = new PolicyProcessor();
+        type = new JavaImplementationDefinition();
+    }
+
+    // @Remotable
+    @Requires( {"transaction.global"})
+    private interface Interface1 {
+        int method1();
+
+        int method2();
+
+        int method3();
+
+        int method4();
+    }
+
+    @Service(Interface1.class)
+    private class Service1 implements Interface1 {
+        public int method1() {
+            return 0;
+        }
+
+        public int method2() {
+            return 0;
+        }
+
+        public int method3() {
+            return 0;
+        }
+
+        public int method4() {
+            return 0;
+        }
+    }
+
+    // @Remotable
+    @Requires( {"transaction.local"})
+    private interface Interface2 {
+        int method5();
+
+        int method6();
+    }
+
+    @Service(interfaces = {Interface1.class, Interface2.class})
+    private class Service2 implements Interface1, Interface2 {
+        public int method1() {
+            return 0;
+        }
+
+        public int method2() {
+            return 0;
+        }
+
+        public int method3() {
+            return 0;
+        }
+
+        public int method4() {
+            return 0;
+        }
+
+        public int method5() {
+            return 0;
+        }
+
+        public int method6() {
+            return 0;
+        }
+    }
+
+    // @Remotable
+    private interface Interface3 {
+        int method1();
+
+        int method2();
+
+        int method3();
+
+        int method4();
+    }
+
+    @Service(Interface3.class)
+    @Requires( {"transaction.global"})
+    private class Service3 implements Interface3 {
+        public int method1() {
+            return 0;
+        }
+
+        public int method2() {
+            return 0;
+        }
+
+        public int method3() {
+            return 0;
+        }
+
+        public int method4() {
+            return 0;
+        }
+    }
+
+    // @Remotable
+    private interface Interface4 {
+        int method5();
+
+        int method6();
+    }
+
+    @Service(interfaces = {Interface3.class, Interface4.class})
+    @Requires( {"transaction.local"})
+    private class Service4 implements Interface3, Interface4 {
+        public int method1() {
+            return 0;
+        }
+
+        public int method2() {
+            return 0;
+        }
+
+        public int method3() {
+            return 0;
+        }
+
+        public int method4() {
+            return 0;
+        }
+
+        public int method5() {
+            return 0;
+        }
+
+        public int method6() {
+            return 0;
+        }
+    }
+
+    private interface Interface5 {
+        @Requires( {"transaction.global"})
+        int method1();
+
+        @Requires( {"transaction.local"})
+        int method2();
+    }
+
+    @Service(Interface5.class)
+    private class Service5 implements Interface5 {
+        public int method1() {
+            return 0;
+        }
+
+        public int method2() {
+            return 0;
+        }
+    }
+
+    @Requires( {"transaction.global.Interface6"})
+    private interface Interface6 {
+        @Requires( {"transaction.global.Interface6.method1"})
+        int method1();
+
+        @Requires( {"transaction.local.Interface6.method2"})
+        int method2();
+    }
+
+    @Service(Interface6.class)
+    @Requires( {"transaction.global.Service6"})
+    private class Service6 implements Interface6 {
+        @Requires( {"transaction.global.Service6.method1"})
+        public int method1() {
+            return 0;
+        }
+
+        @Requires( {"transaction.global.Service6.method1"})
+        public int method2() {
+            return 0;
+        }
+    }
+
+}

Propchange: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/PolicyProcessorTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/PolicyProcessorTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org