Esempio n. 1
0
        /// <summary> Attempts to create an instance of the given class and return
        /// it as a Structure.
        /// </summary>
        /// <param name="c">the Structure implementing class.
        /// </param>
        /// <param name="name">an optional name of the structure (used by Generic structures; may be null).
        /// </param>
        private IStructure TryToInstantiateStructure(Type c, string name)
        {
            IStructure s = null;

            try
            {
                object o = null;
                if (typeof(GenericSegment).IsAssignableFrom(c))
                {
                    s = new GenericSegment(this, name);
                }
                else if (typeof(GenericGroup).IsAssignableFrom(c))
                {
                    s = new GenericGroup(this, name, myFactory);
                }
                else
                {
                    // first try to instantiate using constructor w/ Message arg ...
                    try
                    {
                        var argClasses = new Type[] { typeof(IGroup), typeof(IModelClassFactory) };
                        var argObjects = new object[] { this, myFactory };
                        var con        = c.GetConstructor(argClasses);
                        o = con.Invoke(argObjects);
                    }
                    catch (MethodAccessException)
                    {
                        o = Activator.CreateInstance(c);
                    }

                    if (!(o is IStructure))
                    {
                        throw new HL7Exception(
                                  "Class " + c.FullName + " does not implement " + "ca.on.uhn.hl7.message.Structure",
                                  ErrorCode.APPLICATION_INTERNAL_ERROR);
                    }

                    s = (IStructure)o;
                }
            }
            catch (Exception e)
            {
                if (e is HL7Exception)
                {
                    throw (HL7Exception)e;
                }
                else
                {
                    throw new HL7Exception("Can't instantiate class " + c.FullName, ErrorCode.APPLICATION_INTERNAL_ERROR, e);
                }
            }

            return(s);
        }
Esempio n. 2
0
        /// <summary>
        /// Attempts to create an instance of the given class and return it as a Structure.
        /// </summary>
        ///
        /// <exception cref="HL7Exception"> Thrown when a HL 7 error condition occurs. </exception>
        /// <exception cref="Exception">    Thrown when an exception error condition occurs. </exception>
        ///
        /// <param name="c">    the Structure implementing class. </param>
        /// <param name="name"> an optional name of the structure (used by Generic structures; may be
        ///                     null) </param>
        ///
        /// <returns>   An IStructure. </returns>

        private IStructure tryToInstantiateStructure(System.Type c, System.String name)
        {
            IStructure s = null;

            try
            {
                System.Object o = null;
                if (typeof(GenericSegment).IsAssignableFrom(c))
                {
                    s = new GenericSegment(this, name);
                }
                else if (typeof(GenericGroup).IsAssignableFrom(c))
                {
                    s = new GenericGroup(this, name, this.myFactory);
                }
                else
                {
                    //first try to instantiate using contructor w/ Message arg ...
                    try
                    {
                        System.Type[]   argClasses            = { typeof(IGroup), typeof(IModelClassFactory) };
                        System.Object[] argObjects            = { this, this.myFactory };
                        System.Reflection.ConstructorInfo con = c.GetConstructor(argClasses);
                        o = con.Invoke(argObjects);
                    }
                    catch (System.MethodAccessException)
                    {
                        o = System.Activator.CreateInstance(c);
                    }
                    if (!(o is IStructure))
                    {
                        throw new HL7Exception(
                                  "Class " + c.FullName + " does not implement " + "ca.on.uhn.hl7.message.Structure",
                                  HL7Exception.APPLICATION_INTERNAL_ERROR);
                    }
                    s = (IStructure)o;
                }
            }
            catch (System.Exception e)
            {
                if (e is HL7Exception)
                {
                    throw e;
                }
                throw new HL7Exception(
                          "Can't instantiate class " + c.FullName,
                          HL7Exception.APPLICATION_INTERNAL_ERROR,
                          e);
            }
            return(s);
        }
Esempio n. 3
0
 /// <summary> Attempts to create an instance of the given class and return 
 /// it as a Structure. 
 /// </summary>
 /// <param name="c">the Structure implementing class
 /// </param>
 /// <param name="name">an optional name of the structure (used by Generic structures; may be null)
 /// </param>
 private IStructure tryToInstantiateStructure(System.Type c, System.String name)
 {
     IStructure s = null;
     try
     {
         System.Object o = null;
         if (typeof(GenericSegment).IsAssignableFrom(c))
         {
             s = new GenericSegment(this, name);
         }
         else if (typeof(GenericGroup).IsAssignableFrom(c))
         {
             s = new GenericGroup(this, name, myFactory);
         }
         else
         {
             //first try to instantiate using contructor w/ Message arg ...
             try
             {
                 System.Type[] argClasses = new System.Type[] { typeof(IGroup), typeof(IModelClassFactory) };
                 System.Object[] argObjects = new System.Object[] { this, myFactory };
                 System.Reflection.ConstructorInfo con = c.GetConstructor(argClasses);
                 o = con.Invoke(argObjects);
             }
             catch (System.MethodAccessException)
             {
                 o = System.Activator.CreateInstance(c);
             }
             if (!(o is IStructure))
             {
                 throw new HL7Exception("Class " + c.FullName + " does not implement " + "ca.on.uhn.hl7.message.Structure", HL7Exception.APPLICATION_INTERNAL_ERROR);
             }
             s = (IStructure)o;
         }
     }
     catch (System.Exception e)
     {
         if (e is HL7Exception)
         {
             throw (HL7Exception)e;
         }
         else
         {
             throw new HL7Exception("Can't instantiate class " + c.FullName, HL7Exception.APPLICATION_INTERNAL_ERROR, e);
         }
     }
     return s;
 }