tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1210165 [2/2] - in /tuscany/sca-java-1.x/trunk: itest/serialization-ws-basicauth/ itest/serialization-ws-basicauth/src/ itest/serialization-ws-basicauth/src/main/ itest/serialization-ws-basicauth/src/main/java/ itest/serialization-ws-basic...
Date Sun, 04 Dec 2011 18:10:29 GMT
Modified: tuscany/sca-java-1.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-1.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java?rev=1210165&r1=1210164&r2=1210165&view=diff
==============================================================================
--- tuscany/sca-java-1.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java
(original)
+++ tuscany/sca-java-1.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java
Sun Dec  4 18:10:28 2011
@@ -24,6 +24,8 @@ import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.UUID;
 
 import javax.xml.stream.XMLStreamReader;
@@ -32,11 +34,16 @@ import org.apache.tuscany.sca.assembly.B
 import org.apache.tuscany.sca.assembly.Component;
 import org.apache.tuscany.sca.assembly.ComponentService;
 import org.apache.tuscany.sca.assembly.CompositeService;
+import org.apache.tuscany.sca.assembly.ConfiguredOperation;
+import org.apache.tuscany.sca.assembly.OperationsConfigurator;
 import org.apache.tuscany.sca.assembly.OptimizableBinding;
 import org.apache.tuscany.sca.assembly.Reference;
 import org.apache.tuscany.sca.assembly.SCABinding;
 import org.apache.tuscany.sca.assembly.Service;
 import org.apache.tuscany.sca.assembly.builder.BindingBuilderExtension;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ResolverExtension;
+import org.apache.tuscany.sca.core.assembly.BusinessInterfaceImpl;
 import org.apache.tuscany.sca.core.assembly.CompositeActivator;
 import org.apache.tuscany.sca.core.assembly.CompositeActivatorImpl;
 import org.apache.tuscany.sca.core.assembly.EndpointReferenceImpl;
@@ -50,6 +57,9 @@ import org.apache.tuscany.sca.core.invoc
 import org.apache.tuscany.sca.interfacedef.Interface;
 import org.apache.tuscany.sca.interfacedef.InterfaceContract;
 import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+import org.apache.tuscany.sca.runtime.BusinessInterface;
 import org.apache.tuscany.sca.runtime.EndpointReference;
 import org.apache.tuscany.sca.runtime.ReferenceParameters;
 import org.apache.tuscany.sca.runtime.RuntimeComponent;
@@ -291,10 +301,13 @@ public class CallableReferenceImpl<B> im
                 this.reference.setComponent(this.component);
                 clonedRef = reference;
                 ReferenceParameters parameters = null;
+                BusinessInterface businessInterfaceExt = null;
                 for (Object ext : reference.getExtensions()) {
                     if (ext instanceof ReferenceParameters) {
                         parameters = (ReferenceParameters)ext;
-                        break;
+                    } else if (ext instanceof BusinessInterface) {
+                        // this extension will always be present
+                        businessInterfaceExt = (BusinessInterface)ext;
                     }
                 }
                 if (parameters != null) {
@@ -344,6 +357,10 @@ public class CallableReferenceImpl<B> im
                         binding = reference.getBindings().get(0);
                     }
                 }
+
+                ModelResolver resolver = ((ResolverExtension)ComponentContextHelper.getCurrentComponent()).getModelResolver();
+                componentContextHelper.resolveInterfaceContract(reference.getInterfaceContract(),
resolver);
+
                 Interface i = reference.getInterfaceContract().getInterface();
                 if (i instanceof JavaInterface) {
                     JavaInterface javaInterface = (JavaInterface)i;
@@ -360,10 +377,38 @@ public class CallableReferenceImpl<B> im
                                                                                        javaInterface.getJavaClass());
                         //FIXME: If the interface needs XSDs to be loaded (e.g., for static
SDO),
                         // this needs to be done here.  We usually search for XSDs in the
current
-                        // contribution at resolve time.  Is it possible to locate the current
-                        // contribution at runtime?
-                        }
+                        // contribution at resolve time.  If we need to add code here to
do this,
+                        // we can resolve XSDs using the model resolver for the current component.
+                    }
                     this.businessInterface = (Class<B>)javaInterface.getJavaClass();
+                } else {
+                    // Allow privileged access to get ClassLoader. Requires RuntimePermission
in
+                    // security policy.
+                    ClassLoader classLoader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
{
+                        public ClassLoader run() {
+                            return Thread.currentThread().getContextClassLoader();
+                        }
+                    });
+                    businessInterface = (Class<B>)classLoader.loadClass(businessInterfaceExt.getInterface());
+                    reference.setReference(componentContextHelper.createReference(businessInterface));
+                }
+
+                componentContextHelper.resolveBinding(binding, resolver);
+                if (binding instanceof PolicySetAttachPoint) {
+                    PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)binding;
+                    List<PolicySet> policySets = policiedBinding.getPolicySets();
+                    resolvePolicySets(policySets, resolver);
+                    List<PolicySet> applicablePolicySets = policiedBinding.getApplicablePolicySets();
+                    applicablePolicySets.addAll(policySets);
+                }
+                if (binding instanceof OperationsConfigurator) {
+                    OperationsConfigurator opConfigurator = (OperationsConfigurator)binding;
+                    for (ConfiguredOperation confOp : opConfigurator.getConfiguredOperations())
{
+                        List<PolicySet> policySets = confOp.getPolicySets();
+                        resolvePolicySets(policySets, resolver);
+                        List<PolicySet> applicablePolicySets = confOp.getApplicablePolicySets();
+                        applicablePolicySets.addAll(policySets);
+                    }
                 }
                 if (binding instanceof BindingBuilderExtension) {
                     ((BindingBuilderExtension)binding).getBuilder().build(component, reference,
binding, null);
@@ -377,6 +422,26 @@ public class CallableReferenceImpl<B> im
             }
         }
     }
+
+    /**
+     * Resolve policy sets attached to a specific SCA Construct
+     * @param policySets list of attached policy sets
+     * @param resolver
+     */
+    private void resolvePolicySets(List<PolicySet> policySets, ModelResolver resolver)
{
+        List<PolicySet> resolvedPolicySets = new ArrayList<PolicySet>();
+        PolicySet resolvedPolicySet = null;
+        for (PolicySet policySet : policySets) {
+            if (policySet.isUnresolved()) {
+                resolvedPolicySet = resolver.resolveModel(PolicySet.class, policySet);
+                resolvedPolicySets.add(resolvedPolicySet);
+            } else {
+                resolvedPolicySets.add(policySet);
+            }
+        }
+        policySets.clear();
+        policySets.addAll(resolvedPolicySets);
+    }
     
     /**
      * Follow a service promotion chain down to the inner most (non composite)
@@ -432,6 +497,9 @@ public class CallableReferenceImpl<B> im
                 } catch (CloneNotSupportedException e) {
                     // will not happen
                 }
+                BusinessInterface bizInterface = new BusinessInterfaceImpl();
+                bizInterface.setInterface(businessInterface.getName());
+                clonedRef.getExtensions().add(bizInterface);
             }
             if (refParams == null) {
                 refParams = new ReferenceParametersImpl();
@@ -443,7 +511,6 @@ public class CallableReferenceImpl<B> im
                         toRemove = extension;
                     }
                 }
-               
                 if (toRemove != null){
                     clonedRef.getExtensions().remove(toRemove);
                 }

Modified: tuscany/sca-java-1.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextHelper.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-1.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextHelper.java?rev=1210165&r1=1210164&r2=1210165&view=diff
==============================================================================
--- tuscany/sca-java-1.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextHelper.java
(original)
+++ tuscany/sca-java-1.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextHelper.java
Sun Dec  4 18:10:28 2011
@@ -45,6 +45,7 @@ import org.apache.tuscany.sca.assembly.R
 import org.apache.tuscany.sca.assembly.Service;
 import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
 import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
 import org.apache.tuscany.sca.core.assembly.CompositeActivator;
 import org.apache.tuscany.sca.core.invocation.ThreadMessageContext;
 import org.apache.tuscany.sca.interfacedef.Interface;
@@ -260,6 +261,34 @@ public class ComponentContextHelper {
         return read(streamReader);
     }
 
+    public void resolveInterfaceContract(InterfaceContract interfaceContract, ModelResolver
resolver) throws Exception {
+        StAXArtifactProcessor processor = staxProcessors.getProcessor(interfaceContract.getClass());
+        processor.resolve(interfaceContract, resolver);
+    }
+
+    public void resolveBinding(Binding binding, ModelResolver resolver) throws Exception
{
+        StAXArtifactProcessor processor = staxProcessors.getProcessor(binding.getClass());
+        processor.resolve(binding, resolver);
+    }
+
+    public Reference createReference(Class<?> businessInterface) throws InvalidInterfaceException
{
+        InterfaceContract interfaceContract = createJavaInterfaceContract(businessInterface);
+        Reference reference = assemblyFactory.createReference();
+        reference.setInterfaceContract(interfaceContract);
+        return reference;
+    }
+
+    private InterfaceContract createJavaInterfaceContract(Class<?> businessInterface)
throws InvalidInterfaceException {
+        InterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
+        JavaInterface callInterface = javaInterfaceFactory.createJavaInterface(businessInterface);
+        interfaceContract.setInterface(callInterface);
+        if (callInterface.getCallbackClass() != null) {
+            interfaceContract.setCallbackInterface(javaInterfaceFactory.createJavaInterface(
+                callInterface.getCallbackClass()));
+        }
+        return interfaceContract;
+    }
+
     public static RuntimeComponent getCurrentComponent() {
         Message message = ThreadMessageContext.getMessageContext();
         if (message != null) {

Modified: tuscany/sca-java-1.x/trunk/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
URL: http://svn.apache.org/viewvc/tuscany/sca-java-1.x/trunk/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor?rev=1210165&r1=1210164&r2=1210165&view=diff
==============================================================================
--- tuscany/sca-java-1.x/trunk/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
(original)
+++ tuscany/sca-java-1.x/trunk/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
Sun Dec  4 18:10:28 2011
@@ -17,3 +17,4 @@
 
 # Implementation class for the artifact processor extension
 org.apache.tuscany.sca.core.assembly.ReferenceParameterProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#referenceParameters,model=org.apache.tuscany.sca.runtime.ReferenceParameters
+org.apache.tuscany.sca.core.assembly.BusinessInterfaceProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#businessInterface,model=org.apache.tuscany.sca.runtime.BusinessInterface



Mime
View raw message