Esempio n. 1
0
 protected virtual BaseRelationshipBridge CreateAttributeBridge(Relationship relationship, BeanProperty property, RelationshipSorter
                                                                sorter, MessagePartHolder currentMessagePart)
 {
     this.log.Debug("Attribute " + Describer.Describe(currentMessagePart, relationship) + " maps to property " + Describer.Describe
                        (sorter.GetBeanType(), property));
     return(new AttributeBridgeImpl(relationship, property));
 }
Esempio n. 2
0
 private void CreateWarningIfPropertyIsNotMapped(RelationshipSorter sorter, MessagePartHolder currentMessagePart, Relationship
                                                 relationship)
 {
     if (sorter.GetBeanType() != null)
     {
         this.log.Debug("Relationship " + Describer.Describe(currentMessagePart, relationship) + " does not appear to be mapped to any property of "
                        + ClassUtils.GetShortClassName(sorter.GetBeanType()));
     }
 }
Esempio n. 3
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)));
             }
         }
     }
 }
Esempio n. 4
0
 private void WriteAssociation(BeanWrapper beanWrapper, Hl7Source source, IList <XmlNode> nodes, Relationship relationship,
                               string traversalName)
 {
     this.log.Debug("Writing association: traversalName=" + traversalName + ", relationshipType=" + relationship.Type);
     // 1. collapsed relationship
     if (relationship.Cardinality.Single && beanWrapper.IsAssociationMappedToSameBean(relationship))
     {
         this.log.Debug("COLLAPSE RECURSE : " + traversalName + " as collapsed relationship to " + beanWrapper.GetWrappedType());
         BeanWrapper childBeanWrapper = beanWrapper.CreateSubWrapper(relationship);
         WriteSpecialAssociation(childBeanWrapper, source, nodes, relationship);
     }
     else
     {
         //1b. trivial collapsed relationship with cardinality change (e.g. "RecordId" collapsed into "Location criteria"
         if (relationship.Cardinality.Multiple && beanWrapper.IsAssociationMappedToSameBean(relationship) && IsTypeWithSingleNonFixedRelationship
                 (relationship, source))
         {
             BeanWrapper childBeanWrapper = beanWrapper.CreateSubWrapper(relationship);
             foreach (XmlNode node in nodes)
             {
                 WriteAssociation(childBeanWrapper, source, (XmlElement)node, relationship);
             }
         }
         else
         {
             // 2. initialized read-only association
             if (relationship.Cardinality.Single && beanWrapper.IsPreInitializedDelegate(relationship))
             {
                 this.log.Debug("READ-ONLY ASSOCIATION: " + traversalName + " as collapsed relationship to " + beanWrapper.GetWrappedType(
                                    ));
                 BeanWrapper childBeanWrapper = new BeanWrapper(beanWrapper.GetInitializedReadOnlyAssociation(relationship));
                 WriteSpecialAssociation(childBeanWrapper, source, nodes, relationship);
             }
             else
             {
                 // 3a. non-collapsed, multiple-cardinality choice or single-cardinality choice with node name same as choice name
                 if (IsCdaChoice(nodes, relationship, source))
                 {
                     IList <object> convertedBeans = HandleCdaChoice(nodes, traversalName, relationship, source);
                     if (relationship.Cardinality.Multiple)
                     {
                         this.log.Debug("Special choice handling: WRITING MULTIPLE-CARDINALITY CHOICE: " + beanWrapper.GetWrappedType() + " property with annotation="
                                        + traversalName + " - values=" + convertedBeans);
                         beanWrapper.Write(relationship, convertedBeans);
                     }
                     else
                     {
                         if (relationship.Cardinality.Single && convertedBeans.IsEmpty())
                         {
                             throw new MarshallingException("Special choice handling: Why is this empty? : " + relationship.Name + " on " + source.Type
                                                            );
                         }
                         else
                         {
                             this.log.Debug("Special choice handling: WRITING SINGLE: " + beanWrapper.GetWrappedType() + " property with annotation="
                                            + traversalName + " - value=" + convertedBeans[0]);
                             // may need to ignore values beyond the first; an error will have been logged
                             beanWrapper.Write(relationship, convertedBeans[0]);
                         }
                     }
                 }
                 else
                 {
                     // 3. non-collapsed (including choice, specializationChild, and template type, handling for which is encapsulated in
                     //			Source.createChildSource())
                     if (relationship.TemplateRelationship || relationship.Choice || MessageBeanRegistry.GetInstance().IsMessagePartDefined(source
                                                                                                                                            .GetVersion(), relationship.Type))
                     {
                         IList <object> convertedBeans = new List <object>();
                         foreach (XmlNode node in nodes)
                         {
                             XmlElement    childNode   = (XmlElement)node;
                             Hl7PartSource childSource = source.CreatePartSource(relationship, childNode);
                             this.log.Debug("RECURSE for node=" + source.GetCurrentElement().Name + " - relationship=" + relationship.Name + ", tarversalName="
                                            + traversalName + ", of type: " + childSource.Type);
                             object tealChild = MapPartSourceToTeal(childSource, relationship);
                             convertedBeans.Add(tealChild);
                         }
                         if (relationship.Cardinality.Multiple)
                         {
                             this.log.Debug("WRITING MULTIPLE: " + beanWrapper.GetWrappedType() + " property with annotation=" + traversalName + " - values="
                                            + convertedBeans);
                             beanWrapper.Write(relationship, convertedBeans);
                         }
                         else
                         {
                             if (relationship.Cardinality.Single && convertedBeans.IsEmpty())
                             {
                                 throw new MarshallingException("Why is this empty? : " + relationship.Name + " on " + source.Type);
                             }
                             else
                             {
                                 this.log.Debug("WRITING SINGLE: " + beanWrapper.GetWrappedType() + " property with annotation=" + traversalName + " - value="
                                                + convertedBeans[0]);
                                 // may need to ignore values beyond the first; an error will have been logged
                                 beanWrapper.Write(relationship, convertedBeans[0]);
                             }
                         }
                     }
                     else
                     {
                         if (!ConformanceLevelUtil.IsOptional(relationship) && !IsFullyFixedType(relationship, source))
                         {
                             this.log.Info("IGNORING: HL7 type " + relationship.Type + " with traversalName=" + traversalName + "(" + Describer.Describe
                                               (source.GetMessagePartName(), relationship) + ") cannot be mapped to any teal bean");
                         }
                     }
                 }
             }
         }
     }
 }