示例#1
0
 internal virtual void Put(Mapping mapping, RelationshipSorter sorter)
 {
     foreach (NamedAndTyped namedAndTyped in mapping.GetAllTypes())
     {
         this.relationships[new RelationshipMap.Key(namedAndTyped)] = sorter;
     }
 }
示例#2
0
        /// <summary>We need to distribute all "common" mappings to every applicable "type-based" mappings</summary>
        /// <param name="mapping"></param>
        /// <param name="beanProperty"></param>
        private void AddDuplicates(Mapping mapping, BeanProperty beanProperty)
        {
            IList <RelationshipMap.Key> allTypeBased = this.map.GetAllTypeBased(mapping.First());

            foreach (RelationshipMap.Key key in allTypeBased)
            {
                object @object = this.map.Get(key);
                if (@object is Ca.Infoway.Messagebuilder.Marshalling.RelationshipSorter)
                {
                    Mapping rest = mapping.Rest();
                    Ca.Infoway.Messagebuilder.Marshalling.RelationshipSorter innerRelationshipSorter = (Ca.Infoway.Messagebuilder.Marshalling.RelationshipSorter
                                                                                                        )@object;
                    if (rest.IsCompound())
                    {
                        innerRelationshipSorter.properties[beanProperty.Name] = beanProperty;
                        // TM - Redmine 10965 - this "if" check fixes bug, might not be sufficient in the long run
                        if (innerRelationshipSorter.map.GetAllTypeBased(rest.First()).IsEmpty())
                        {
                            innerRelationshipSorter.Add(rest, beanProperty);
                        }
                        else
                        {
                            innerRelationshipSorter.AddDuplicates(rest, beanProperty);
                        }
                    }
                    else
                    {
                        // we are at the "bottom" of the chain - now we can add the "duplicate" property to its correct location
                        innerRelationshipSorter.Add(rest, beanProperty);
                    }
                }
            }
        }
示例#3
0
        internal virtual PartBridge CreatePartBridgeFromBean(string propertyPath, object tealBean, Interaction interaction, MessagePartHolder
                                                             currentMessagePart)
        {
            RelationshipSorter sorter = RelationshipSorter.Create(propertyPath, tealBean);

            return(CreatePartBridge(sorter, interaction, currentMessagePart, new BridgeContext(), false));
        }
示例#4
0
        internal static Ca.Infoway.Messagebuilder.Marshalling.RelationshipSorter Create(string propertyName, object tealBean)
        {
            Ca.Infoway.Messagebuilder.Marshalling.RelationshipSorter holder = new Ca.Infoway.Messagebuilder.Marshalling.RelationshipSorter
                                                                                  (propertyName, tealBean == null ? null : tealBean.GetType(), tealBean);
            IDictionary <string, BeanProperty> properties = BeanProperty.GetProperties(tealBean);

            foreach (BeanProperty property in properties.Values)
            {
                IList <Mapping> mappings = Mapping.From(property);
                foreach (Mapping mapping in mappings)
                {
                    holder.Add(mapping, property);
                }
            }
            foreach (BeanProperty property in properties.Values)
            {
                IList <Mapping> mappings = Mapping.From(property);
                foreach (Mapping mapping in mappings)
                {
                    // if this is an inlined "common" mapping, we need to add it to appropriate "type-based" mappings
                    if (mapping.IsCompound() && !mapping.HasPartTypeMappings())
                    {
                        holder.AddDuplicates(mapping, property);
                    }
                }
            }
            return(holder);
        }
示例#5
0
 internal BeanWrapper(object bean)
 {
     this.map           = BeanProperty.GetProperties(bean);
     this.sorter        = RelationshipSorter.Create(string.Empty, bean);
     this.contextName   = null;
     this.parentWrapper = null;
 }
示例#6
0
        public virtual void ShouldHandleInlinedPropertiesWithMapByPartTypeAndWithout()
        {
            RelationshipSorter sorter = RelationshipSorter.Create(string.Empty, new MockMultiplyCompoundNestedMappedMessagePartBean()
                                                                  );
            Relationship organizationInMapByPartTypeRelationship = new Relationship("representedOrganization", "COCT_MT090102CA.Organization"
                                                                                    , Cardinality.Create("1"));
            Relationship organizationNotInMapByPartTypeRelationship = new Relationship("representedOrganization", "MOCK_MT090102CA.Organization"
                                                                                       , Cardinality.Create("1"));
            Relationship assignedOrganizationInMapByPartTypeRelationship = new Relationship("assignedOrganization", "COCT_MT260030CA.Organization"
                                                                                            , Cardinality.Create("1"));
            Relationship nameRelationship    = new Relationship("name", "ST", Cardinality.Create("1"));
            Relationship idRelationship      = new Relationship("id", "II", Cardinality.Create("1"));
            Relationship otherIdRelationship = new Relationship("otherId", "II", Cardinality.Create("1"));
            // >>>>>>>>>>>>>>>>>>
            object @object = sorter.Get(organizationInMapByPartTypeRelationship);

            Assert.IsNotNull(@object, "type exists");
            Assert.IsTrue(@object is RelationshipSorter, "type");
            RelationshipSorter innerSorter = (RelationshipSorter)@object;

            @object = innerSorter.Get(nameRelationship);
            Assert.IsNotNull(@object, "type exists");
            Assert.IsTrue(@object is BeanProperty, "type");
            AssertPropertyNamesEqual("property name", "assignedOrganizationName", @object);
            @object = innerSorter.Get(idRelationship);
            Assert.IsNotNull(@object, "type exists");
            Assert.IsTrue(@object is BeanProperty, "type");
            AssertPropertyNamesEqual("property id", "organizationIdentifier", @object);
            @object = innerSorter.Get(otherIdRelationship);
            Assert.IsNull(@object, "type does not exists");
            // >>>>>>>>>>>>>>>>>>
            @object = sorter.Get(organizationNotInMapByPartTypeRelationship);
            Assert.IsNotNull(@object, "type exists");
            Assert.IsTrue(@object is RelationshipSorter, "type");
            innerSorter = (RelationshipSorter)@object;
            @object     = innerSorter.Get(nameRelationship);
            Assert.IsNull(@object, "type does not exist");
            @object = innerSorter.Get(idRelationship);
            Assert.IsNotNull(@object, "type exists");
            Assert.IsTrue(@object is BeanProperty, "type");
            AssertPropertyNamesEqual("property id", "organizationIdentifier", @object);
            @object = innerSorter.Get(otherIdRelationship);
            Assert.IsNull(@object, "type does not exist");
            // >>>>>>>>>>>>>>>>>>
            @object = sorter.Get(assignedOrganizationInMapByPartTypeRelationship);
            Assert.IsNotNull(@object, "type exists");
            Assert.IsTrue(@object is RelationshipSorter, "type");
            innerSorter = (RelationshipSorter)@object;
            @object     = innerSorter.Get(nameRelationship);
            Assert.IsNotNull(@object, "type exists");
            Assert.IsTrue(@object is BeanProperty, "type");
            AssertPropertyNamesEqual("property name", "assignedOrganizationName", @object);
            @object = innerSorter.Get(idRelationship);
            Assert.IsNull(@object, "type should not exist");
            @object = innerSorter.Get(otherIdRelationship);
            Assert.IsNotNull(@object, "type exists");
            Assert.IsTrue(@object is BeanProperty, "type");
            AssertPropertyNamesEqual("other property id", "otherOrganizationIdentifier", @object);
        }
示例#7
0
 private BeanWrapper(Ca.Infoway.Messagebuilder.Marshalling.BeanWrapper parentWrapper, string contextName, RelationshipSorter
                     sorter)
 {
     this.parentWrapper = parentWrapper;
     this.map           = parentWrapper.map;
     this.sorter        = sorter;
     this.contextName   = Concatenate(parentWrapper.contextName, contextName);
 }
示例#8
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()));
     }
 }
示例#9
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)));
             }
         }
     }
 }
示例#10
0
        private PartBridge CreateNullPartBridge(Relationship relationship, Interaction interaction)
        {
            RelationshipSorter sorter             = RelationshipSorter.Create(relationship.Name, null);
            MessagePartHolder  currentMessagePart = GetMessagePart(interaction, relationship, null);

            if (currentMessagePart != null)
            {
                return(CreatePartBridge(sorter, interaction, currentMessagePart, new BridgeContext(), true));
            }
            else
            {
                return(new PartBridgeImpl(relationship.Name, null, relationship.Type, CollUtils.EmptyList <BaseRelationshipBridge>(), false
                                          , true));
            }
        }
示例#11
0
        public virtual void ShouldHandleCollapsedProperties()
        {
            RelationshipSorter sorter       = RelationshipSorter.Create(string.Empty, new MockMessageBean());
            Relationship       relationship = new Relationship("theType", "MOCK_MT898989CA.SubType", Cardinality.Create("1"));

            Assert.IsNotNull(sorter.Get(relationship), "type exists");
            Assert.IsTrue(sorter.Get(relationship) is BeanProperty, "type");
            sorter       = RelationshipSorter.Create(string.Empty, new MockSubType());
            relationship = new Relationship("component", "MOCK_MT123456CA.Component", Cardinality.Create("1"));
            Assert.IsNotNull(sorter.Get(relationship), "component exists");
            Assert.IsTrue(sorter.Get(relationship) is RelationshipSorter, "component");
            RelationshipSorter deviceSorter = (RelationshipSorter)sorter.Get(relationship);

            Assert.IsNotNull(deviceSorter.Get(new Relationship("subject3", "MOCK_MT123456CA.Subject6", Cardinality.Create("1"))), "id exists"
                             );
        }
示例#12
0
        public virtual void ShouldHandlePropertiesWithMapByPartType()
        {
            RelationshipSorter sorter       = RelationshipSorter.Create(string.Empty, new MockMultiplyMappedMessagePartBean());
            Relationship       relationship = new Relationship("theType", "MOCK_MT898989CA.SubType", Cardinality.Create("1"));
            object             @object      = sorter.Get(relationship);

            Assert.IsNotNull(@object, "type exists");
            Assert.IsTrue(@object is BeanProperty, "type");
            AssertPropertyNamesEqual("property name", "type2", @object);
            Relationship otherRelationship = new Relationship("theType", "MOCK_MT123456CA.SubType", Cardinality.Create("1"));
            object       otherObject       = sorter.Get(otherRelationship);

            Assert.IsNotNull(otherObject, "other type exists");
            Assert.IsTrue(otherObject is BeanProperty, "other type");
            AssertPropertyNamesEqual("other property name", "type", otherObject);
        }
示例#13
0
 private void Add(Mapping mapping, BeanProperty beanProperty)
 {
     this.properties[beanProperty.Name] = beanProperty;
     if (!mapping.IsCompound())
     {
         this.map.Put(mapping, beanProperty);
     }
     else
     {
         if (!this.map.ContainsMapping(mapping.FirstPart()))
         {
             Ca.Infoway.Messagebuilder.Marshalling.RelationshipSorter sorter = new Ca.Infoway.Messagebuilder.Marshalling.RelationshipSorter
                                                                                   (beanProperty.Name, GetBeanType(), GetBean(), true);
             this.map.Put(mapping.FirstPart(), sorter);
         }
         GetAsRelationshipSorter(mapping.FirstPart()).Add(mapping.Rest(), beanProperty);
     }
 }
示例#14
0
        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));
        }
示例#15
0
        public virtual void ShouldHandleCompoundPropertiesWithMapByPartType()
        {
            RelationshipSorter sorter        = RelationshipSorter.Create(string.Empty, new MockMultiplyCompoundMappedMessagePartBean());
            Relationship       relationship1 = new Relationship("theType", "MOCK_MT123458CA.SubTypeA", Cardinality.Create("1"));
            Relationship       relationship2 = new Relationship("theSubType", "MOCK_MT123457CA.SubTypeB", Cardinality.Create("1"));
            Relationship       relationship3 = new Relationship("theSubSubType", "MOCK_MT898989CA.SubType", Cardinality.Create("1"));
            // first level
            object @object = sorter.Get(relationship1);

            Assert.IsNotNull(@object, "exists");
            Assert.IsTrue(@object is RelationshipSorter, "type");
            RelationshipSorter tempSorter = (RelationshipSorter)@object;

            // second level
            @object = tempSorter.Get(relationship2);
            Assert.IsNotNull(@object, "exists");
            Assert.IsTrue(@object is RelationshipSorter, "type");
            tempSorter = (RelationshipSorter)@object;
            // third level
            @object = tempSorter.Get(relationship3);
            Assert.IsNotNull(@object, "type exists");
            Assert.IsTrue(@object is BeanProperty, "type");
            AssertPropertyNamesEqual("property name", "type2", @object);
            Relationship otherRelationship1 = new Relationship("theType", "MOCK_MT123458CA.SubTypeA", Cardinality.Create("1"));
            Relationship otherRelationship2 = new Relationship("theSubType", "MOCK_MT123457CA.SubTypeB", Cardinality.Create("1"));
            Relationship otherRelationship3 = new Relationship("theSubSubType", "MOCK_MT123456CA.SubType", Cardinality.Create("1"));

            // first level
            @object = sorter.Get(otherRelationship1);
            Assert.IsNotNull(@object, "other exists");
            Assert.IsTrue(@object is RelationshipSorter, "other type");
            tempSorter = (RelationshipSorter)@object;
            // second level
            @object = tempSorter.Get(otherRelationship2);
            Assert.IsNotNull(@object, "other exists");
            Assert.IsTrue(@object is RelationshipSorter, "other type");
            tempSorter = (RelationshipSorter)@object;
            // third level
            @object = tempSorter.Get(otherRelationship3);
            Assert.IsNotNull(@object, "other type exists");
            Assert.IsTrue(@object is BeanProperty, "other type");
            AssertPropertyNamesEqual("other property name", "type", @object);
        }
示例#16
0
        private static void DescribeBeanPath(object bean, string xpath, StringBuilder result)
        {
            IList <string> pathParts = ObtainParts(xpath);

            RemovePartType(bean, pathParts);
            result.Append(bean.GetType().Name).Append('.');
            RelationshipSorter sorter = RelationshipSorter.Create(string.Empty, bean);

            foreach (string part in pathParts)
            {
                object sorterObj = sorter.Get(part);
                if (sorterObj is RelationshipSorter)
                {
                    sorter = (RelationshipSorter)sorterObj;
                }
                else
                {
                    if (sorterObj is BeanProperty)
                    {
                        BeanProperty beanProperty = (BeanProperty)sorterObj;
                        //				result.append(beanProperty.getPropertyType().getSimpleName()).append('.');  // BEAN PATH
                        result.Append(beanProperty.Name).Append('.');
                        // ACCESSOR PATH
                        sorter = RelationshipSorter.Create(string.Empty, beanProperty.Get());
                    }
                    else
                    {
                        // if can't find a mapping match then stop here
                        // just append letfover parts? i.e. a.b.c (.leftover1.leftover2)
                        break;
                    }
                }
            }
            if (result[result.Length - 1] == '.')
            {
                result.DeleteCharAt(result.Length - 1);
            }
        }
示例#17
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));
        }
示例#18
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));
 }
示例#19
0
        private IndicatorAssociationBridgeImpl CreateIndicatorAssociationBridge(Relationship relationship, RelationshipSorter sorter
                                                                                , Interaction interaction, BridgeContext context, BeanProperty beanProperty)
        {
            PartBridge partBridge = null;

            if (beanProperty == null || beanProperty.Get() == null)
            {
                partBridge = CreateNullPartBridge(relationship, interaction);
            }
            else
            {
                partBridge = CreatePartBridge(sorter, interaction, GetMessagePart(interaction, relationship, null), new BridgeContext(),
                                              false);
            }
            return(new IndicatorAssociationBridgeImpl(relationship, partBridge, beanProperty));
        }