示例#1
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);
        }
示例#2
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);
        }
示例#3
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"
                             );
        }
示例#4
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);
        }
示例#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)));
             }
         }
     }
 }
示例#6
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);
            }
        }
示例#7
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));
        }