Esempio n. 1
0
 /// <summary>Instantiate a bean that models the part under question.</summary>
 /// <remarks>Instantiate a bean that models the part under question.</remarks>
 /// <param name="version">- the version code</param>
 /// <param name="type">- the part type</param>
 /// <returns>an instance of a bean that represents the part type</returns>
 public virtual object InstantiateMessagePartBean(VersionNumber version, string type, Interaction interaction)
 {
     try
     {
         Type partClass = MessageBeanRegistry.GetInstance().GetMessagePartClass(version, type);
         if (partClass == null)
         {
             throw CreateMarshallingException("Did not find", version, type);
         }
         else
         {
             if (!ClassUtil.IsGeneric(partClass))
             {
                 this.log.Debug("Instantiating bean: " + partClass.FullName);
                 return(System.Activator.CreateInstance(partClass));
             }
             else
             {
                 this.log.Debug("Instantiating parameterized bean: " + partClass.FullName);
                 return(GenericClassUtil.Instantiate(partClass, CreateParameterMap(interaction, version)));
             }
         }
     }
     catch (MemberAccessException e)
     {
         throw CreateMarshallingException("Error instantiating", version, type, e);
     }
     catch (Exception e)
     {
         throw CreateMarshallingException("Error instantiating", version, type, e);
     }
 }
Esempio n. 2
0
 private static void InitializeInstance()
 {
     if (instance == null)
     {
         var registry = new MessageBeanRegistry();
         registry.Initialize();
         instance = registry;
     }
 }
Esempio n. 3
0
 public virtual XmlToModelResult MapToTeal(Hl7MessageSource hl7MessageSource)
 {
     if (hl7MessageSource.GetInteraction() != null)
     {
         Type        messageBeanType = MessageBeanRegistry.GetInstance().GetInteractionBeanType(hl7MessageSource.GetMessageTypeKey());
         object      messageBean     = BeanUtil.Instantiate <object>(messageBeanType);
         BeanWrapper wrapper         = new BeanWrapper(messageBean);
         MapToTeal(hl7MessageSource, wrapper, null);
         hl7MessageSource.GetResult().SetMessageObject(messageBean);
         CreateBeanPathOnErrorMessages(hl7MessageSource.GetResult(), messageBean);
     }
     return(hl7MessageSource.GetResult());
 }
Esempio n. 4
0
 public MessageBeanTransformerImpl(MessageDefinitionService service, RenderMode renderMode, TimeZoneInfo dateTimeZone, TimeZoneInfo
                                   dateTimeTimeZone, bool performAdditionalCdaValidationWhenUnmarshalling)
 {
     this.service          = service;
     this.renderMode       = renderMode;
     this.dateTimeZone     = dateTimeZone;
     this.dateTimeTimeZone = dateTimeTimeZone;
     this.performAdditionalCdaValidationWhenUnmarshalling = performAdditionalCdaValidationWhenUnmarshalling;
     if (this.service != null)
     {
         this.service.Initialize();
     }
     MessageBeanRegistry.GetInstance();
 }
Esempio n. 5
0
        public void shouldFindMessageBeanType()
        {
            // NOTE: MessageBeanRegistry will look into assemblies deployed in the same folder as the app

            // I've copied the assembly 'message-builder-test-assembly.dll' product of the message-builder-test-assembly project to
            // this project's /bin/Debug/ folder so MessageBeanRegistry will load it from there and this test passes.
            // A different approach probably will be needed in the build server

            var messageDescriptions = new[] { CR, CERX, COMMON };

            var messageBeanRegistry = MessageBeanRegistry.GetInstance();

            foreach (var description in messageDescriptions)
            {
                var interactionBeanType =
                    messageBeanRegistry.GetInteractionBeanType(new MessageTypeKey(MockVersionNumber.MOCK_NEWFOUNDLAND, description.getInteractionId()));

                Assert.AreEqual(description.getMessageType(), interactionBeanType.Name, "type");
            }
        }
Esempio n. 6
0
        public static void Initialize()
        {
            if (!initialized)
            {
                MessageBeanRegistry.GetInstance().RegisterClass(typeof(MockMessageBean), MockVersionNumber.MOCK_NEWFOUNDLAND);
                MessageBeanRegistry.GetInstance().RegisterClass(typeof(MockSubType), MockVersionNumber.MOCK_NEWFOUNDLAND);
                MessageBeanRegistry.GetInstance().RegisterClass(typeof(FindCandidatesQueryMessageBean), MockVersionNumber.MOCK_NEWFOUNDLAND);
                MessageBeanRegistry.GetInstance().RegisterClass(typeof(FindCandidatesCriteria), MockVersionNumber.MOCK_NEWFOUNDLAND);
                MessageBeanRegistry.GetInstance().RegisterClass(typeof(GenericResponseMessageBean), MockVersionNumber.MOCK_NEWFOUNDLAND);
                MessageBeanRegistry.GetInstance().RegisterClass(typeof(UpdatePasswordRequestMessageBean), MockVersionNumber.MOCK_NEWFOUNDLAND);
                MessageBeanRegistry.GetInstance().RegisterClass(typeof(RegistrationControlActEventBean <>), MockVersionNumber.MOCK_NEWFOUNDLAND);
                MessageBeanRegistry.GetInstance().RegisterClass(typeof(PasswordChangeBean), MockVersionNumber.MOCK_NEWFOUNDLAND);
                MessageBeanRegistry.GetInstance().RegisterClass(typeof(AcknowledgementBean), MockVersionNumber.MOCK_NEWFOUNDLAND);
                MessageBeanRegistry.GetInstance().RegisterClass(typeof(AcknowledgementDetailBean), MockVersionNumber.MOCK_NEWFOUNDLAND);
                MessageBeanRegistry.GetInstance().RegisterClass(typeof(AssignedDeviceBean), MockVersionNumber.MOCK_NEWFOUNDLAND);
                MessageBeanRegistry.GetInstance().RegisterClass(typeof(AssignedPersonBean), MockVersionNumber.MOCK_NEWFOUNDLAND);
                MessageBeanRegistry.GetInstance().RegisterClass(typeof(AuthorBean), MockVersionNumber.MOCK_NEWFOUNDLAND);
                MessageBeanRegistry.GetInstance().RegisterClass(typeof(RegistrationRequestBean <>), MockVersionNumber.MOCK_NEWFOUNDLAND);
                MessageBeanRegistry.GetInstance().RegisterClass(typeof(RecordDispenseProcessingRequestMessageBean), MockVersionNumber.MOCK_NEWFOUNDLAND
                                                                );
                MessageBeanRegistry.GetInstance().RegisterClass(typeof(RegistrationControlActEventBean <>), MockVersionNumber.MOCK_NEWFOUNDLAND);
                MessageBeanRegistry.GetInstance().RegisterClass(typeof(QueryControlActEventBean <>), MockVersionNumber.MOCK_NEWFOUNDLAND);
                MessageBeanRegistry.GetInstance().RegisterClass(typeof(Sender), MockVersionNumber.MOCK_NEWFOUNDLAND);
                MessageBeanRegistry.GetInstance().RegisterClass(typeof(ServiceDeliveryLocationBean), MockVersionNumber.MOCK_NEWFOUNDLAND);
                MessageBeanRegistry.GetInstance().RegisterClass(typeof(Receiver), MockVersionNumber.MOCK_NEWFOUNDLAND);
                MessageBeanRegistry.GetInstance().RegisterClass(typeof(QueryByParameterBean <>), MockVersionNumber.MOCK_NEWFOUNDLAND);
                MessageBeanRegistry.GetInstance().RegisterClass(typeof(BeanA), MockVersionNumber.MOCK_NEWFOUNDLAND);
                MessageBeanRegistry.GetInstance().RegisterClass(typeof(BeanB), MockVersionNumber.MOCK_NEWFOUNDLAND);
                MessageBeanRegistry.GetInstance().RegisterClass(typeof(SimpleInteraction), MockVersionNumber.MOCK_NEWFOUNDLAND);

                MessageBeanRegistry.GetInstance().RegisterClass(typeof(QuantityObservationEventBean), MockVersionNumber.MOCK_NEWFOUNDLAND);
                MessageBeanRegistry.GetInstance().RegisterClass(typeof(InFulfillmentOfBean), MockVersionNumber.MOCK_MR2009);

                initialized = true;
            }
        }
Esempio n. 7
0
 public static void Reset()
 {
     instance = null;
 }
Esempio n. 8
0
        public virtual Interaction GetInteraction(IInteraction tealBean)
        {
            MessageTypeKey type = MessageBeanRegistry.GetInstance().GetMessageTypeKey(this.version, tealBean);

            return(this.service.GetInteraction(this.version, type.GetMessageId()));
        }
Esempio n. 9
0
 public virtual void SetUp()
 {
     MessageBeanRegistry.Reset();
     Assembly.LoadFrom("../../TestResource/message-builder-release-mock-mr2009.dll");
     CodeResolverRegistry.Register(new TrivialCodeResolver());
 }
Esempio n. 10
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");
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 11
0
 private void CreateParameterMap(VersionNumber version, IDictionary <string, Type> map, IList <Argument> arguments)
 {
     foreach (Argument argument in arguments)
     {
         map[TemplateVariableNameUtil.Transform(argument.TemplateParameterName)] = MessageBeanRegistry.GetInstance().GetMessagePartClass
                                                                                       (version, argument.Name);
         CreateParameterMap(version, map, argument.Arguments);
     }
 }