Example #1
0
 private AssociationBridge CreateAssociationBridge(Relationship relationship, RelationshipSorter sorter, Interaction interaction
                                                   , MessagePartHolder currentMessagePart, BridgeContext context)
 {
     if (sorter.IsCollapsedRelationship(relationship))
     {
         if (relationship.Cardinality.Multiple)
         {
             return(CreateCollectionRelationshipBridge(relationship, sorter, interaction));
         }
         else
         {
             RelationshipSorter collapsedSorter = sorter.GetAsRelationshipSorter(relationship);
             PartBridge         bridge          = CreatePartBridge(collapsedSorter, interaction, GetMessagePart(interaction, relationship, collapsedSorter
                                                                                                                .GetBean()), new BridgeContext(true, context.GetOriginalIndex()), false);
             return(new AssociationBridgeImpl(relationship, bridge));
         }
     }
     else
     {
         object       o        = sorter.Get(relationship);
         BeanProperty property = (BeanProperty)o;
         object       value    = property.Get();
         if (relationship.Cardinality.Multiple && value is IEnumerable)
         {
             this.log.Debug("Association " + Describer.Describe(currentMessagePart, relationship) + " maps to collection property " +
                            Describer.Describe(sorter.GetBeanType(), property));
             return(CreateCollectionOfCompositeBeanBridges(property.Name, relationship, (IEnumerable)value, interaction));
         }
         else
         {
             if (context.IsIndexed() && property.Collection)
             {
                 this.log.Debug("Association " + Describer.Describe(currentMessagePart, relationship) + " maps to index " + context.GetIndex
                                    () + " of collection property " + Describer.Describe(sorter.GetBeanType(), property));
                 object elementValue = ListElementUtil.GetElement(value, context.GetIndex());
                 // use the indexed object's part instead
                 MessagePartHolder part = GetMessagePart(interaction, relationship, elementValue);
                 return(new AssociationBridgeImpl(relationship, CreatePartBridgeFromBean(property.Name + "[" + context.GetIndex() + "]", elementValue
                                                                                         , interaction, part)));
             }
             else
             {
                 this.log.Debug("Association " + Describer.Describe(currentMessagePart, relationship) + " maps to property " + Describer.Describe
                                    (sorter.GetBeanType(), property));
                 // Bug 13050 - should handle a single cardinality relationship if mapped to a collection
                 if (ListElementUtil.IsCollection(value))
                 {
                     value = ListElementUtil.IsEmpty(value) ? null : ListElementUtil.GetElement(value, 0);
                 }
                 MessagePartHolder part = GetMessagePart(interaction, relationship, value);
                 return(new AssociationBridgeImpl(relationship, CreatePartBridgeFromBean(property.Name, value, interaction, part)));
             }
         }
     }
 }