Author: slaws
Date: Tue Jul 27 09:05:26 2010
New Revision: 979597

URL: http://svn.apache.org/viewvc?rev=979597&view=rev
Log:
Some defensive code to avert an NPE that's now causing ASM_8005, ASM_8017, 
ASM_8018 to fail. It's not clear why this code is being hit now when it wasn't 
previously. 

Modified:
    
tuscany/sca-java-2.x/trunk/modules/assembly/src/main/resources/org/apache/tuscany/sca/assembly/builder/assembly-validation-messages.properties
    
tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentBuilderImpl.java

Modified: 
tuscany/sca-java-2.x/trunk/modules/assembly/src/main/resources/org/apache/tuscany/sca/assembly/builder/assembly-validation-messages.properties
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/assembly/src/main/resources/org/apache/tuscany/sca/assembly/builder/assembly-validation-messages.properties?rev=979597&r1=979596&r2=979597&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/assembly/src/main/resources/org/apache/tuscany/sca/assembly/builder/assembly-validation-messages.properties
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/assembly/src/main/resources/org/apache/tuscany/sca/assembly/builder/assembly-validation-messages.properties
 Tue Jul 27 09:05:26 2010
@@ -81,3 +81,5 @@ PropertyValueDoesNotMatchComplexType = [
 PropertyValueDoesNotMatchElement = [ASM50029] The property {0} on component 
{1} has a value which does not match the element {2} with which it is 
associated. Validation reported {3}
 EPRIncompatibleInterface = [BWS20007] The reference interface is incompatible 
with the interface of the reference binding {0}
 EPIncompatibleInterface = [BWS20007] The service interface is incompatible 
with the interface of the service binding {0}
+PromotedCallbackReferenceNotFound = For component {0} and service {1} the 
promoted component {2} does not have a callback reference called {3} which 
should have been created automatically by Tuscany
+PromotedCallbackServiceNotFound = For component {0} and reference {1} the 
promoted component {2} does not have a callback service called {3} which should 
have been created automatically by Tuscany

Modified: 
tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentBuilderImpl.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentBuilderImpl.java?rev=979597&r1=979596&r2=979597&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentBuilderImpl.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentBuilderImpl.java
 Tue Jul 27 09:05:26 2010
@@ -270,7 +270,7 @@ public class ComponentBuilderImpl {
             calculateBindings(component, componentService, 
componentTypeService, context);
 
             // add callback reference model objects
-            createCallbackReference(component, componentService);
+            createCallbackReference(component, componentService, monitor);
         }
     }
 
@@ -312,7 +312,7 @@ public class ComponentBuilderImpl {
             calculateBindings(componentReference, componentTypeReference);
 
             // add callback service model objects
-            createCallbackService(component, componentReference);
+            createCallbackService(component, componentReference, monitor);
 
             // Propagate autowire setting from the component down the 
structural 
             // hierarchy
@@ -1156,12 +1156,12 @@ public class ComponentBuilderImpl {
      * @param component
      * @param service
      */
-    private void createCallbackReference(Component component, ComponentService 
service) {
+    private void createCallbackReference(Component component, ComponentService 
service, Monitor monitor) {
 
         // if the service has a callback interface create a reference
         // to represent the callback 
         if (service.getInterfaceContract() != null && // can be null in unit 
tests
-        service.getInterfaceContract().getCallbackInterface() != null) {
+            service.getInterfaceContract().getCallbackInterface() != null) {
 
             ComponentReference callbackReference = 
assemblyFactory.createComponentReference();
             callbackReference.setForCallback(true);
@@ -1197,7 +1197,19 @@ public class ComponentBuilderImpl {
                     if 
(((CompositeService)implService).getPromotedService().isUnresolved() == false){
                         String referenceName = 
((CompositeService)implService).getPromotedService().getName();
                         ComponentReference promotedReference = 
((CompositeService)implService).getPromotedComponent().getReference(referenceName);
-                        
implCompReference.getPromotedReferences().add(promotedReference);
+                        
+                        if (promotedReference != null){
+                            
implCompReference.getPromotedReferences().add(promotedReference);
+                        } else {
+                            Monitor.error(monitor,
+                                          this,
+                                          Messages.ASSEMBLY_VALIDATION,
+                                          "PromotedCallbackReferenceNotFound",
+                                          component.getName(),
+                                          service.getName(),
+                                          
((CompositeService)implService).getPromotedComponent().getName(),
+                                          referenceName);
+                        }
                     }                 
                     implReference = implCompReference;
                     
@@ -1263,7 +1275,7 @@ public class ComponentBuilderImpl {
      * @param component
      * @param service
      */
-    private void createCallbackService(Component component, ComponentReference 
reference) {
+    private void createCallbackService(Component component, ComponentReference 
reference, Monitor monitor) {
         if (reference.getInterfaceContract() != null && // can be null in unit 
tests
             reference.getInterfaceContract().getCallbackInterface() != null) {
             ComponentService callbackService = 
assemblyFactory.createComponentService();
@@ -1299,7 +1311,19 @@ public class ComponentBuilderImpl {
                     if 
(((CompositeReference)implReference).getPromotedReferences().get(0).isUnresolved()
 == false){
                         String serviceName = 
((CompositeReference)implReference).getPromotedReferences().get(0).getName();
                         ComponentService promotedService = 
((CompositeReference)implReference).getPromotedComponents().get(0).getService(serviceName);
-                        implCompService.setPromotedService(promotedService);
+                        
+                        if (promotedService != null){
+                            
implCompService.setPromotedService(promotedService);
+                        } else {
+                            Monitor.error(monitor,
+                                          this,
+                                          Messages.ASSEMBLY_VALIDATION,
+                                          "PromotedCallbackServiceNotFound",
+                                          component.getName(),
+                                          reference.getName(),
+                                          
((CompositeReference)implReference).getPromotedComponents().get(0).getName(),
+                                          serviceName);
+                        }
                     }
                     
                     implService = implCompService;


Reply via email to