[savara-commits] savara SVN: r643 - in branches/experimental/2.0.x/bundles/org.savara.pi4soa.cdm/src: test/resources/results/protocol and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Feb 8 17:16:03 EST 2011


Author: objectiser
Date: 2011-02-08 17:16:03 -0500 (Tue, 08 Feb 2011)
New Revision: 643

Modified:
   branches/experimental/2.0.x/bundles/org.savara.pi4soa.cdm/src/main/java/org/savara/pi4soa/cdm/parser/rules/ChoiceConverterRuleImpl.java
   branches/experimental/2.0.x/bundles/org.savara.pi4soa.cdm/src/test/resources/results/protocol/PolicyQuote.spr
Log:
If choice is associated with different roles, then don't generate the from/to roles, and put all content in each path (for now). Might need to determine one particular pair, and use labels for other paths.

Modified: branches/experimental/2.0.x/bundles/org.savara.pi4soa.cdm/src/main/java/org/savara/pi4soa/cdm/parser/rules/ChoiceConverterRuleImpl.java
===================================================================
--- branches/experimental/2.0.x/bundles/org.savara.pi4soa.cdm/src/main/java/org/savara/pi4soa/cdm/parser/rules/ChoiceConverterRuleImpl.java	2011-02-07 23:21:41 UTC (rev 642)
+++ branches/experimental/2.0.x/bundles/org.savara.pi4soa.cdm/src/main/java/org/savara/pi4soa/cdm/parser/rules/ChoiceConverterRuleImpl.java	2011-02-08 22:16:03 UTC (rev 643)
@@ -66,6 +66,9 @@
 		java.util.List<Role> toRoles=new java.util.Vector<Role>();
 		boolean f_when=false;
 		
+		// Check if all paths are associated with the same from and to role
+		boolean f_sameRoles=isSameRoles(context, cdl);
+		
 		// Process all of the activities within the
 		// choreography
 		java.util.Iterator<org.pi4soa.cdl.Activity> actiter=
@@ -87,7 +90,7 @@
 				
 				// If interaction found, then make sure it is ignored when
 				// processing the when path contents
-				if (locator.getInteraction() != null &&
+				if (f_sameRoles && locator.getInteraction() != null &&
 						locator.getInteraction().getExchangeDetails().size() > 0) {
 					context.ignore(locator.getInteraction().getExchangeDetails().get(0));
 				}
@@ -102,11 +105,40 @@
 					 * possibly if same from/to roles.
 					 */
 					if (activity instanceof Choice) {
-						blocks.addAll(((Choice)activity).getWhens());
 						
+						if (f_sameRoles) {
+							blocks.addAll(((Choice)activity).getWhens());
+						} else {
+							When block=new When();
+							
+							// Check if single path in choice
+							Choice c=(Choice)activity;
+							
+							if (c.getWhens().size() == 1) {
+								// Make when message signature back into an interaction
+								org.scribble.protocol.model.Interaction i=
+										new org.scribble.protocol.model.Interaction();
+								i.derivedFrom(c.getWhens().get(0));
+								
+								i.setMessageSignature(c.getWhens().get(0).getMessageSignature());
+								i.setFromRole(c.getFromRole());
+								i.getToRoles().add(c.getToRole());
+								
+								block.getBlock().add(i);
+								
+								// Add contained activities
+								block.getBlock().getContents().addAll(
+											c.getWhens().get(0).getBlock().getContents());
+							} else {
+								block.getBlock().add(activity);
+							}
+							
+							blocks.add(block);
+						} 
+						
 						// TODO: If fromRole not set, use choice one? If fromRole set,
 						// then may need to compare? Same for two roles?
-						if (fromRole == null) {
+						if (fromRole == null && f_sameRoles) {
 							fromRole = ((Choice)activity).getFromRole();
 							
 							if (toRoles.contains(((Choice)activity).getToRole()) == false) {
@@ -117,7 +149,7 @@
 
 						When block=new When();
 						
-						if (locator.getInteraction() != null &&
+						if (f_sameRoles && locator.getInteraction() != null &&
 								locator.getInteraction().getExchangeDetails().size() > 0) {
 							
 							// Get the first exchange details
@@ -202,6 +234,13 @@
 					}
 				}
 			}
+			
+			if (b.getMessageSignature() == null) {
+				// Create label
+				MessageSignature ms=new MessageSignature();
+				ms.setOperation("label"+i);
+				b.setMessageSignature(ms);
+			}
 		}
 		
 		/*
@@ -220,8 +259,10 @@
 			((org.scribble.protocol.model.Choice)ret).
 					getWhens().addAll(blocks);
 			
-			((org.scribble.protocol.model.Choice)ret).
-						setFromRole(new Role(fromRole));
+			if (fromRole != null) {
+				((org.scribble.protocol.model.Choice)ret).
+							setFromRole(new Role(fromRole));
+			}
 			
 			if (toRoles.size() == 1) {
 				((org.scribble.protocol.model.Choice)ret).setToRole(new Role(toRoles.get(0)));
@@ -258,6 +299,87 @@
 		return(ret);
 	}
 	
+	protected boolean isSameRoles(ConverterContext context, org.pi4soa.cdl.Choice cdl) {
+		boolean ret=true;
+		Role fromRole=null;
+		Role toRole=null;
+		
+		for (int i=0; ret == true && i < cdl.getActivities().size(); i++) {
+			org.pi4soa.cdl.Activity act=cdl.getActivities().get(i);
+			Role from=null;
+			Role to=null;
+			
+			ConverterRule rule=ConverterRuleFactory.getConverter(
+					org.scribble.protocol.model.Activity.class, act);
+		
+			if (rule != null) {
+				
+				context.pushState();
+				
+				// Find exchange details for this path
+				InteractionLocator locator=new InteractionLocator(act);
+				
+				act.visit(locator);
+				
+				org.scribble.protocol.model.Activity activity=
+					(org.scribble.protocol.model.Activity)
+					rule.convert(context,
+							org.scribble.protocol.model.Activity.class, act);
+				
+				if (activity instanceof Choice) {
+					from = ((Choice)activity).getFromRole();
+					to = ((Choice)activity).getToRole();
+				} else if (activity != null) {
+
+					if (locator.getInteraction() != null &&
+							locator.getInteraction().getExchangeDetails().size() > 0) {
+							
+						// Get the first exchange details
+						ExchangeDetails ed=locator.getInteraction().getExchangeDetails().get(0);
+						
+						if (ed != null) {
+							
+							from = InteractionConverterRuleImpl.getFromRole(context,
+														ed);
+								
+							to = InteractionConverterRuleImpl.getToRole(context,
+														ed);
+						}
+					}
+				}
+				
+				context.popState();
+			}
+			
+			if (i == 0) {
+				fromRole = from;
+				toRole = to;
+			} else {				
+				if (from != null) {
+					if (fromRole == null) {
+						ret = false;
+					} else {
+						ret = fromRole.equals(from);
+					}
+				} else {
+					ret = (fromRole == null);
+				}
+				
+				if (to != null) {
+					if (toRole == null) {
+						ret = false;
+					} else {
+						ret = toRole.equals(to);
+					}
+				} else {
+					ret = (toRole == null);
+				}
+			}
+		}
+		
+		return(ret);
+	}
+	
 	public static class InteractionLocator implements CDLVisitor {
 
 		private Interaction m_interaction=null;

Modified: branches/experimental/2.0.x/bundles/org.savara.pi4soa.cdm/src/test/resources/results/protocol/PolicyQuote.spr
===================================================================
--- branches/experimental/2.0.x/bundles/org.savara.pi4soa.cdm/src/test/resources/results/protocol/PolicyQuote.spr	2011-02-07 23:21:41 UTC (rev 642)
+++ branches/experimental/2.0.x/bundles/org.savara.pi4soa.cdm/src/test/resources/results/protocol/PolicyQuote.spr	2011-02-08 22:16:03 UTC (rev 643)
@@ -32,9 +32,10 @@
 	[[ Interface(name={http://www.pi4soa.org/PolicyQuote}DrivingRecordCallbackService) ]]
 	receiveDrivingRecord(DrivingRecordResponse) from DrivingRecordService to PolicyQuoteProcessService;
 	[[ SourceComponent(id=//@choreographies.0/@activities.3) ]]
-	choice from PolicyQuoteProcessService to CreditCheckService {
-		[[ Correlation(request=checkCredit) ]]
-		checkCredit(CreditCheckRequest):
+	choice {
+		label0():
+			[[ Correlation(request=checkCredit) ]]
+			checkCredit(CreditCheckRequest) from PolicyQuoteProcessService to CreditCheckService;
 			[[ SourceComponent(id=//@choreographies.0/@activities.3/@activities.0/@activities.0/@activities.0/@exchangeDetails.1) ]]
 			[[ Interface(name={http://www.pi4soa.org/PolicyQuote}CreditCheckService) ]]
 			[[ Correlation(replyTo=checkCredit) ]]
@@ -60,9 +61,10 @@
 			[[ Correlation(replyTo=receivePolicyQuote) ]]
 			receivePolicyQuote(PolicyQuoteReply) from PolicyQuoteProcessService to Driver;
 
-		[[ Fault(name=policyQuoteFault) ]]
-		[[ Correlation(replyTo=receivePolicyQuote) ]]
-		receivePolicyQuote(PolicyQuoteFault):
+		label1():
+			[[ Fault(name=policyQuoteFault) ]]
+			[[ Correlation(replyTo=receivePolicyQuote) ]]
+			receivePolicyQuote(PolicyQuoteFault) from PolicyQuoteProcessService to Driver;
 
 	}
 }



More information about the savara-commits mailing list