private void AddChoiceAnnotation(PartBridge part, Relationship relationship) { NamedAndTyped choiceOptionRelationship = null; string choiceType = relationship.Type; if (relationship.Choice) { choiceOptionRelationship = BeanBridgeChoiceRelationshipResolver.ResolveChoice(part, relationship); } else { if (relationship.TemplateRelationship) { Argument argument = this.interaction.GetArgumentByTemplateParameterName(relationship.TemplateParameterName); if (argument != null && argument.Choice) { Ca.Infoway.Messagebuilder.Xml.Predicate <Relationship> predicate = ChoiceSupport.ChoiceOptionTypePredicate(new string[] { part.GetTypeName() }); choiceOptionRelationship = argument.FindChoiceOption(predicate); choiceType = argument.Name; } } } if (choiceOptionRelationship != null) { CurrentBuffer().AddInfo("Selected option " + choiceOptionRelationship.Type + " (" + choiceOptionRelationship.Name + ") from choice " + choiceType); } }
private string DetermineXmlName(PartBridge tealBean, Relationship relationship) { if (!relationship.Choice && !relationship.TemplateRelationship) { return(relationship.Name); } else { if (relationship.TemplateRelationship) { Argument argument = this.interaction.GetArgumentByTemplateParameterName(relationship.TemplateParameterName); if (argument == null) { throw new RenderingException("Cannot determine the template/choice parameter type : " + relationship.Name); } else { if (argument.Choice) { Ca.Infoway.Messagebuilder.Xml.Predicate <Relationship> predicate = ChoiceSupport.ChoiceOptionTypePredicate(new string[] { tealBean.GetTypeName() }); Relationship option = argument.FindChoiceOption(predicate); if (option == null) { throw new RenderingException("Cannot determine the choice type of template argument : " + argument.Name); } else { return(option.Name); } } else { return(argument.TraversalName); } } } else { if (tealBean.IsEmpty()) { return(relationship.Choices[0].Name); } else { if (relationship.Cardinality.Multiple) { return(relationship.Name); } Relationship option = BeanBridgeChoiceRelationshipResolver.ResolveChoice(tealBean, relationship); if (option == null) { // log an error instead? throw new RenderingException("Cannot determine the choice type of relationship : " + relationship.Name); } else { return(option.Name); } } } } }
internal static Relationship ResolveChoice(PartBridge tealBean, Relationship relationship) { return(relationship.FindChoiceOption(ChoiceSupport.ChoiceOptionTypePredicate(new string[] { tealBean.GetTypeName() }))); }