Пример #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 Structure tryToInstantiateStructure(System.Type c, System.String name)
        {
            Structure 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(Group), typeof(ModelClassFactory) };
                        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 Structure))
                    {
                        throw new NuGenHL7Exception("Class " + c.FullName + " does not implement " + "ca.on.uhn.hl7.message.Structure", NuGenHL7Exception.APPLICATION_INTERNAL_ERROR);
                    }
                    s = (Structure)o;
                }
            }
            catch (System.Exception e)
            {
                if (e is NuGenHL7Exception)
                {
                    throw (NuGenHL7Exception)e;
                }
                else
                {
                    throw new NuGenHL7Exception("Can't instantiate class " + c.FullName, NuGenHL7Exception.APPLICATION_INTERNAL_ERROR, e);
                }
            }
            return(s);
        }
Пример #2
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 Structure tryToInstantiateStructure(System.Type c, System.String name)
		{
			Structure 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(Group), typeof(ModelClassFactory)};
						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 Structure))
					{
						throw new NuGenHL7Exception("Class " + c.FullName + " does not implement " + "ca.on.uhn.hl7.message.Structure", NuGenHL7Exception.APPLICATION_INTERNAL_ERROR);
					}
					s = (Structure) o;
				}
			}
			catch (System.Exception e)
			{
				if (e is NuGenHL7Exception)
				{
					throw (NuGenHL7Exception) e;
				}
				else
				{
					throw new NuGenHL7Exception("Can't instantiate class " + c.FullName, NuGenHL7Exception.APPLICATION_INTERNAL_ERROR, e);
				}
			}
			return s;
		}