Exemple #1
0
 internal virtual int GetSingleCollapsedPropertySize()
 {
     if (PropertyCount() != 1)
     {
         throw new MarshallingException(ToString() + " with cardinality changes cannot handle " + PropertyCount() + " collapsed properties"
                                        );
     }
     else
     {
         BeanProperty property = (BeanProperty) new List <BeanProperty>(this.properties.Values)[0];
         object       value    = property.Get();
         if (value == null)
         {
             return(0);
         }
         else
         {
             if (ListElementUtil.IsCollection(value))
             {
                 return(ListElementUtil.Count(value));
             }
             else
             {
                 return(1);
             }
         }
     }
 }
Exemple #2
0
        public virtual object GetInitializedReadOnlyAssociation(NamedAndTyped relationshipName)
        {
            object       @object;
            BeanProperty beanProperty = FindBeanProperty(relationshipName);

            if (beanProperty == null)
            {
                @object = null;
            }
            else
            {
                if (!beanProperty.Readable)
                {
                    @object = null;
                }
                else
                {
                    if (ListElementUtil.IsCollection((Type)beanProperty.PropertyType))
                    {
                        //Initialized collections don't count
                        @object = null;
                    }
                    else
                    {
                        @object = beanProperty.Get();
                    }
                }
            }
            return(@object);
        }
Exemple #3
0
 private void WriteNonDataType(string relationshipName, BeanProperty property, object @object)
 {
     if (property.Collection)
     {
         if (ListElementUtil.IsCollection(@object))
         {
             ListElementUtil.AddAllElements(property.Get(), @object);
         }
         else
         {
             this.log.Info("Warning mapping HL7 single property to Teal collection. Property=" + relationshipName);
             ListElementUtil.AddElement(property.Get(), @object);
         }
     }
     else
     {
         if (property.Writable)
         {
             if (@object != null)
             {
                 property.Set(@object);
             }
         }
         else
         {
             throw new MarshallingException("Cannot write to " + property.Name + " of " + this.sorter.GetBean().GetType());
         }
     }
 }
Exemple #4
0
 protected virtual bool IsEmptyCollection(V value)
 {
     if (ListElementUtil.IsCollection(value))
     {
         return(ListElementUtil.IsEmpty(value));
     }
     return(false);
 }
Exemple #5
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)));
             }
         }
     }
 }
Exemple #6
0
 internal static bool IsEmpty(object value)
 {
     if (value == null)
     {
         return(true);
     }
     else
     {
         if (ListElementUtil.IsCollection(value))
         {
             return(0 == ListElementUtil.Count(value));
         }
         else
         {
             return(false);
         }
     }
 }
Exemple #7
0
 private bool Hl7ValueHasContent(BareANY hl7Value)
 {
     if (hl7Value.BareValue != null)
     {
         // there's a value; if it's a list, check if it is empty
         if (ListElementUtil.IsCollection(hl7Value.BareValue))
         {
             return(!ListElementUtil.IsEmpty(hl7Value.BareValue));
         }
         else
         {
             return(true);
         }
     }
     else
     {
         // contains no value, but perhaps has a null flavor
         return(hl7Value.HasNullFlavor());
     }
 }
Exemple #8
0
        private PartBridge CreatePartBridge(RelationshipSorter sorter, Interaction interaction, MessagePartHolder currentMessagePart
                                            , BridgeContext context, bool nullPart)
        {
            IList <BaseRelationshipBridge> relationships = new List <BaseRelationshipBridge>();

            foreach (Relationship relationship in currentMessagePart.GetRelationships())
            {
                object o = sorter.Get(relationship);
                if (relationship.Attribute && relationship.HasFixedValue())
                {
                    relationships.Add(new FixedValueAttributeBeanBridge(relationship, (BareANY)null));
                }
                else
                {
                    if (relationship.Attribute)
                    {
                        if (o == null)
                        {
                            CreateWarningIfPropertyIsNotMapped(sorter, currentMessagePart, relationship);
                            relationships.Add(new AttributeBridgeImpl(relationship, null));
                        }
                        else
                        {
                            if (context.IsIndexed())
                            {
                                CreateWarningIfConformanceLevelIsNotAllowed(relationship);
                                object field = sorter.GetField(relationship);
                                if (ListElementUtil.IsCollection(field))
                                {
                                    relationships.Add(new CollapsedAttributeBridge(((BeanProperty)o).Name, relationship, ListElementUtil.GetElement(field, context
                                                                                                                                                    .GetIndex())));
                                }
                                else
                                {
                                    throw new MarshallingException("Expected relationship " + relationship.Name + " on " + sorter + " to resolve to a List because we think it's a collapsed "
                                                                   + " attribute");
                                }
                            }
                            else
                            {
                                CreateWarningIfConformanceLevelIsNotAllowed(relationship);
                                relationships.Add(CreateAttributeBridge(relationship, (BeanProperty)o, sorter, currentMessagePart));
                            }
                        }
                    }
                    else
                    {
                        if (IsIndicator(relationship))
                        {
                            CreateWarningIfConformanceLevelIsNotAllowed(relationship);
                            relationships.Add(CreateIndicatorAssociationBridge(relationship, sorter, interaction, context, (BeanProperty)o));
                        }
                        else
                        {
                            if (o == null)
                            {
                                CreateWarningIfPropertyIsNotMapped(sorter, currentMessagePart, relationship);
                                if (ConformanceLevelUtil.IsMandatory(relationship) || ConformanceLevelUtil.IsPopulated(relationship))
                                {
                                    relationships.Add(new AssociationBridgeImpl(relationship, CreateNullPartBridge(relationship, interaction)));
                                }
                            }
                            else
                            {
                                CreateWarningIfConformanceLevelIsNotAllowed(relationship);
                                relationships.Add(CreateAssociationBridge(relationship, sorter, interaction, currentMessagePart, context));
                            }
                        }
                    }
                }
            }
            //		if (sorter.getPropertyName() == null || sorter.getPropertyName().equals("null")) {
            //			System.out.println("not correct");
            //		}
            return(new PartBridgeImpl(sorter.GetPropertyName(), sorter.GetBean(), currentMessagePart.GetName(), relationships, context
                                      .IsCollapsed(), nullPart));
        }
Exemple #9
0
        public void ShouldDetectCollectionOnCollapsedType()
        {
            IList <PersonName> list = new RawListWrapper <PN, PersonName>(new List <PN>(), typeof(PNImpl));

            Assert.IsTrue(ListElementUtil.IsCollection(list), "is list");
        }
Exemple #10
0
        public void ShouldDetectCollection()
        {
            IList <String> list = new List <String>();

            Assert.IsTrue(ListElementUtil.IsCollection(list), "is list");
        }