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))); } } } }
private AssociationBridge CreateCollectionRelationshipBridge(Relationship relationship, RelationshipSorter sorter, Interaction interaction) { RelationshipSorter association = sorter.GetAsRelationshipSorter(relationship); List <PartBridge> list = new List <PartBridge>(); int length = association.GetSingleCollapsedPropertySize(); for (int i = 0; i < length; i++) { list.Add(CreatePartBridge(association, interaction, GetMessagePart(interaction, relationship, null), new BridgeContext(true , i), false)); } // bug 13240 - if empty collection and pop/mand, add a placeholder bridge - this will output a nullflavor element, and a warning for mandatory if (list.IsEmpty() && (ConformanceLevelUtil.IsPopulated(relationship) || ConformanceLevelUtil.IsMandatory(relationship))) { list.Add(CreatePartBridgeFromBean(string.Empty, null, interaction, GetMessagePart(interaction, relationship, null))); } return(new AssociationBridgeImpl(relationship, list)); }