Ejemplo n.º 1
0
        private static Relationship FindChoiceOption(Ca.Infoway.Messagebuilder.Xml.Predicate <Relationship> predicate, IList <Relationship
                                                                                                                              > choices)
        {
            Relationship result = null;

            foreach (Relationship option in choices)
            {
                if (option.Choice)
                {
                    result = option.FindChoiceOption(predicate);
                }
                else
                {
                    if (predicate.Apply(option))
                    {
                        result = option;
                    }
                }
                if (result != null)
                {
                    break;
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        private MessagePartHolder GetMessagePart(Interaction interaction, Relationship relationship, object value)
        {
            string typeName = relationship.Type;

            if (relationship.TemplateRelationship)
            {
                Argument argument = interaction.GetArgumentByTemplateParameterName(relationship.TemplateParameterName);
                if (argument.Choice)
                {
                    Ca.Infoway.Messagebuilder.Xml.Predicate <Relationship> predicate = ChoiceSupport.ChoiceOptionTypePredicate(GetTypes(value)
                                                                                                                               );
                    Relationship option = argument.FindChoiceOption(predicate);
                    if (option != null)
                    {
                        typeName = option.Type;
                    }
                    else
                    {
                        // couldn't find a choice type to use (most likely, value is null)
                        // can't leave typeName as null, so just use first choice type from argument
                        typeName = argument.Choices[0].Type;
                    }
                }
                else
                {
                    typeName = argument.Name;
                }
            }
            else
            {
                if (relationship.Choice)
                {
                    Relationship option = relationship.FindChoiceOption(ChoiceSupport.ChoiceOptionTypePredicate(GetTypes(value)));
                    if (option != null)
                    {
                        typeName = option.Type;
                    }
                }
            }
            return(BuildMessagePartHolder(relationship, typeName, interaction));
        }
Ejemplo n.º 4
0
 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);
                 }
             }
         }
     }
 }
Ejemplo n.º 5
0
 /// <summary>Find a specific choice based on some matching strategy defined by the predicate.</summary>
 /// <remarks>Find a specific choice based on some matching strategy defined by the predicate.</remarks>
 /// <param name="predicate">- a class that determines the matching strategy of the choice.</param>
 /// <returns>the selected choice.</returns>
 public virtual Relationship FindChoiceOption(Ca.Infoway.Messagebuilder.Xml.Predicate <Relationship> predicate)
 {
     return(FindChoiceOption(predicate, Choices));
 }