Author: slaws
Date: Mon Mar  8 12:00:38 2010
New Revision: 920287

URL: http://svn.apache.org/viewvc?rev=920287&view=rev
Log:
Switch binder interface over to throwing exceptions rather than returning 
booleans. Allows the full details of a missmatch to be retrieved in the runtime 
case as well as the build time case. Update the matching test case to take 
advantage of the extra information.

Modified:
    
tuscany/sca-java-2.x/trunk/itest/policy/matching/src/test/java/org/apache/tuscany/sca/policy/matching/MatchingTestCase.java
    
tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointReferenceBinder.java
    
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java
    
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java

Modified: 
tuscany/sca-java-2.x/trunk/itest/policy/matching/src/test/java/org/apache/tuscany/sca/policy/matching/MatchingTestCase.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/itest/policy/matching/src/test/java/org/apache/tuscany/sca/policy/matching/MatchingTestCase.java?rev=920287&r1=920286&r2=920287&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/itest/policy/matching/src/test/java/org/apache/tuscany/sca/policy/matching/MatchingTestCase.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/itest/policy/matching/src/test/java/org/apache/tuscany/sca/policy/matching/MatchingTestCase.java
 Mon Mar  8 12:00:38 2010
@@ -20,6 +20,8 @@
 package org.apache.tuscany.sca.policy.matching;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import org.apache.tuscany.sca.node.Contribution;
 import org.apache.tuscany.sca.node.Node;
@@ -56,8 +58,9 @@
         HelloWorld helloWorld = node.getService(HelloWorld.class, 
"HelloWorldClientMutuallyExclusiveIntents");
         try {
             helloWorld.getGreetings("petra");
+            fail("Exception expected");
         } catch (Exception ex) {
-            assertEquals("Unable to bind", ex.getMessage().substring(0, 14));
+            assertTrue(ex.getMessage().indexOf("No match because the following 
intents are mutually exclusive 
{http://tuscany.apache.org/xmlns/sca/1.1}testIntent3 
{http://tuscany.apache.org/xmlns/sca/1.1}testIntent1";) > -1);
         }
     }
     
@@ -72,8 +75,9 @@
         HelloWorld helloWorld = node.getService(HelloWorld.class, 
"HelloUnresolvedIntentsOnReference");
         try {
             helloWorld.getGreetings("petra");
+            fail("Exception expected");
         } catch (Exception ex) {
-            assertEquals("Unable to bind", ex.getMessage().substring(0, 14));
+            assertTrue(ex.getMessage().indexOf("No match because there are 
unresolved intents [{http://tuscany.apache.org/xmlns/sca/1.1}testIntent2]";) > 
-1);
         }
     }   
        
@@ -90,9 +94,10 @@
     public void testSomePoliciesOnOneSideButNoneOnTheOther() throws Exception {
         try {
             HelloWorld helloWorld = node.getService(HelloWorld.class, 
"HelloWorldClientSomePoliciesOnOneSideButNoneOnTheOther");
-            assertEquals("Hello petra", helloWorld.getGreetings("petra")); 
+            helloWorld.getGreetings("petra");
+            fail("Exception expected");
         } catch (Exception ex) {
-            assertEquals("Unable to bind", ex.getMessage().substring(0, 14));
+            assertTrue(ex.getMessage().indexOf("No match because there are 
policy sets at the endpoint but not at the endpoint reference") > -1);
         }
     } 
     
@@ -106,9 +111,10 @@
     public void testDifferentPolicyLanguage() throws Exception {
         try {
             HelloWorld helloWorld = node.getService(HelloWorld.class, 
"HelloWorldClientDifferentPolicyLanguage");
-            assertEquals("Hello petra", helloWorld.getGreetings("petra"));     
   
+            helloWorld.getGreetings("petra");
+            fail("Exception expected");
         } catch (Exception ex) {
-            assertEquals("Unable to bind", ex.getMessage().substring(0, 14));
+            assertTrue(ex.getMessage().indexOf("No match because the policy 
sets on either side have policies in differnt languages 
{http://schemas.xmlsoap.org/ws/2004/09/policy}ExactlyOne and 
{http://tuscany.apache.org/xmlns/sca/1.1}jdkLogger";) > -1);
         }    
     } 
     

Modified: 
tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointReferenceBinder.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointReferenceBinder.java?rev=920287&r1=920286&r2=920287&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointReferenceBinder.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointReferenceBinder.java
 Mon Mar  8 12:00:38 2010
@@ -32,7 +32,7 @@
      * @param endpointReference
      * @return
      */
-    boolean bindBuildTime(EndpointRegistry endpointRegistry, EndpointReference 
endpointReference);
+    void bindBuildTime(EndpointRegistry endpointRegistry, EndpointReference 
endpointReference);
 
     
     /**
@@ -40,7 +40,7 @@
      * @param endpointReference
      * @return
      */
-    boolean bindRunTime(EndpointRegistry endpointRegistry, EndpointReference 
endpointReference);
+    void bindRunTime(EndpointRegistry endpointRegistry, EndpointReference 
endpointReference);
     
     /**
      * 

Modified: 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java?rev=920287&r1=920286&r2=920287&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java
 Mon Mar  8 12:00:38 2010
@@ -302,10 +302,7 @@
     private void resolveEndpointReference() {
         resolve();
 
-        boolean ok = eprBinder.bindRunTime(endpointRegistry, this);
-        if (!ok) {
-            throw new ServiceRuntimeException("Unable to bind " + this);
-        }
+        eprBinder.bindRunTime(endpointRegistry, this);
 
         // start the binding provider
         final ReferenceBindingProvider bindingProvider = getBindingProvider();

Modified: 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java?rev=920287&r1=920286&r2=920287&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java
 Mon Mar  8 12:00:38 2010
@@ -49,6 +49,7 @@
 import org.apache.tuscany.sca.policy.Qualifier;
 import org.apache.tuscany.sca.runtime.EndpointReferenceBinder;
 import org.apache.tuscany.sca.runtime.EndpointRegistry;
+import org.oasisopen.sca.ServiceRuntimeException;
 
 /**
  * A builder that takes endpoint references and resolves them. It either finds 
local
@@ -92,9 +93,9 @@
      * @param endpointRegistry
      * @param endpointReference
      */
-    public boolean bindBuildTime(EndpointRegistry endpointRegistry, 
+    public void bindBuildTime(EndpointRegistry endpointRegistry, 
                                  EndpointReference endpointReference) {
-       return bind(endpointRegistry, endpointReference, false);
+       bind(endpointRegistry, endpointReference, false);
     }
     
     /**
@@ -104,9 +105,9 @@
      * @param endpointRegistry
      * @param endpointReference
      */
-    public boolean bindRunTime(EndpointRegistry endpointRegistry,
+    public void bindRunTime(EndpointRegistry endpointRegistry,
                                EndpointReference endpointReference) {
-        return bind(endpointRegistry, endpointReference, true);
+        bind(endpointRegistry, endpointReference, true);
     }
     
     /**
@@ -116,7 +117,7 @@
      * @param endpointReference
      * @param runtime set true if called from the runtime 
      */
-    public boolean bind(EndpointRegistry endpointRegistry,  
+    public void bind(EndpointRegistry endpointRegistry,  
                         EndpointReference endpointReference,
                         boolean runtime){
         
@@ -183,7 +184,8 @@
                                   "endpoint-validation-messages",
                                   "NoComponentReferenceTarget",
                                   endpointReference.getReference().getName());
-                    return false;
+                    throw new ServiceRuntimeException("Unable to bind " +
+                                                      
monitor.getLastProblem().toString());
                 }
             }
             
@@ -242,7 +244,8 @@
                                   "endpoint-validation-messages", 
                                   "NoEndpointsFound", 
                                   endpointReference.toString()); 
-                    return false;
+                    throw new ServiceRuntimeException("Unable to bind " + 
+                                                      
monitor.getLastProblem().toString());
                 }
             }            
 
@@ -277,10 +280,9 @@
                                 endpointReference.toString());
             }
                
-            return false;
+            throw new ServiceRuntimeException("Unable to bind " + 
+                                               
monitor.getLastProblem().toString());
         }
-       
-        return true;
     }    
    
     /**


Reply via email to