Exemplo n.º 1
0
        /// <summary>Parses a segment profile </summary>
        private Seg parseSegmentProfile(System.Xml.XmlElement elem)
        {
            Seg segment = new Seg();

            parseProfileStuctureData(segment, elem);

            int childIndex = 1;

            System.Xml.XmlNodeList children = elem.ChildNodes;
            for (int i = 0; i < children.Count; i++)
            {
                System.Xml.XmlNode n = children.Item(i);
                if (System.Convert.ToInt16(n.NodeType) == (short)System.Xml.XmlNodeType.Element)
                {
                    System.Xml.XmlElement child = (System.Xml.XmlElement)n;
                    if (child.Name.ToUpper().Equals("Field".ToUpper()))
                    {
                        Field field = parseFieldProfile(child);
                        segment.setField(childIndex++, field);
                    }
                }
            }

            return(segment);
        }
Exemplo n.º 2
0
        /// <summary>Parses a field profile </summary>
        private Field parseFieldProfile(System.Xml.XmlElement elem)
        {
            Field field = new Field();

            field.Usage = elem.GetAttribute("Usage");
            System.String itemNo = elem.GetAttribute("ItemNo");
            System.String min    = elem.GetAttribute("Min");
            System.String max    = elem.GetAttribute("Max");

            try
            {
                if (itemNo.Length > 0)
                {
                    field.ItemNo = System.Int16.Parse(itemNo);
                }
            }
            catch (System.FormatException e)
            {
                throw new NuGenProfileException("Invalid ItemNo: " + itemNo + "( for name " + elem.GetAttribute("Name") + ")", e);
            }             // try-catch

            try
            {
                field.Min = System.Int16.Parse(min);
                if (max.IndexOf('*') >= 0)
                {
                    field.Max = (short)(-1);
                }
                else
                {
                    field.Max = System.Int16.Parse(max);
                }
            }
            catch (System.FormatException e)
            {
                throw new NuGenProfileException("Min and max must be short integers: " + min + ", " + max, e);
            }

            parseAbstractComponentData(field, elem);

            int childIndex = 1;

            System.Xml.XmlNodeList children = elem.ChildNodes;
            for (int i = 0; i < children.Count; i++)
            {
                System.Xml.XmlNode n = children.Item(i);
                if (System.Convert.ToInt16(n.NodeType) == (short)System.Xml.XmlNodeType.Element)
                {
                    System.Xml.XmlElement child = (System.Xml.XmlElement)n;
                    if (child.Name.ToUpper().Equals("Component".ToUpper()))
                    {
                        Component comp = (Component)parseComponentProfile(child, false);
                        field.setComponent(childIndex++, comp);
                    }
                }
            }

            return(field);
        }
Exemplo n.º 3
0
		/// <summary>Parses a field profile </summary>
		private Field parseFieldProfile(System.Xml.XmlElement elem)
		{
			Field field = new Field();
			
			field.Usage = elem.GetAttribute("Usage");
			System.String itemNo = elem.GetAttribute("ItemNo");
			System.String min = elem.GetAttribute("Min");
			System.String max = elem.GetAttribute("Max");
			
			try
			{
				if (itemNo.Length > 0)
				{
					field.ItemNo = System.Int16.Parse(itemNo);
				}
			}
			catch (System.FormatException e)
			{
				throw new NuGenProfileException("Invalid ItemNo: " + itemNo + "( for name " + elem.GetAttribute("Name") + ")", e);
			} // try-catch
			
			try
			{
				field.Min = System.Int16.Parse(min);
				if (max.IndexOf('*') >= 0)
				{
					field.Max = (short) (- 1);
				}
				else
				{
					field.Max = System.Int16.Parse(max);
				}
			}
			catch (System.FormatException e)
			{
				throw new NuGenProfileException("Min and max must be short integers: " + min + ", " + max, e);
			}
			
			parseAbstractComponentData(field, elem);
			
			int childIndex = 1;
			System.Xml.XmlNodeList children = elem.ChildNodes;
			for (int i = 0; i < children.Count; i++)
			{
				System.Xml.XmlNode n = children.Item(i);
				if (System.Convert.ToInt16(n.NodeType) == (short) System.Xml.XmlNodeType.Element)
				{
					System.Xml.XmlElement child = (System.Xml.XmlElement) n;
					if (child.Name.ToUpper().Equals("Component".ToUpper()))
					{
						Component comp = (Component) parseComponentProfile(child, false);
						field.setComponent(childIndex++, comp);
					}
				}
			}
			
			return field;
		}
Exemplo n.º 4
0
        /// <summary>This method will build a primitive conformance class (ST, NM, etc) which is
        /// a Field.
        /// </summary>
        public virtual void  buildClass(Genetibase.NuGenHL7.conf.spec.message.Field primitive, System.String parentUnderlyingType, ProfileName profileName)
        {
            GeneratedPrimitive genClass = new GeneratedPrimitive();

            // Check for possible snags in the Runtime Profile Component
            if (primitive.Name == null || primitive.Name.Length < 1)
            {
                throw new ConformanceError("Error building ConformanceSegment: Runtime AbstractComponent does not contain a name.");
            }

            GeneratedMethod theConstructor = new GeneratedMethod();

            genClass.Constructor = theConstructor;
            genClass.addClassImport("Genetibase.NuGenHL7.model.*");

            UnderlyingAccessor underlyingAccessor = new UnderlyingAccessor(parentUnderlyingType, profileName.AccessorName);

            theConstructor.addParam(parentUnderlyingType + " parentSeg", "The parent underlying data type");
            theConstructor.addParam("int rep", "The desired repetition");
            theConstructor.Name       = profileName.ClassName;
            theConstructor.Visibility = "public ";
            theConstructor.addToThrows("Genetibase.NuGenHL7.HL7Exception");
            theConstructor.addToBody("super( (Primitive)parentSeg." + underlyingAccessor + " );");
            theConstructor.addToBody("if ( parentSeg." + underlyingAccessor + " == null )");
            theConstructor.addToBody("   throw new Genetibase.NuGenHL7.HL7Exception( \"Error accussing underlying object. This is a bug.\", 0 );");

            // Set up class
            genClass.ClassPackage = packageName;
            //genClass.addClassImport("Genetibase.NuGenHL7.model.*");
            genClass.addClassImport("Genetibase.NuGenHL7.conf.classes.abs.*");
            //genClass.addClassImport( "Genetibase.NuGenHL7.conf.classes.exceptions.*" );
            genClass.Properties = "extends AbstractConformanceDataType implements Repeatable";

            // Add min and max reps stuff
            genClass.setMinMaxReps(primitive.Min, primitive.Max);

            genClass.Name = profileName.ClassName;
            docBuilder.decorateConstructor(genClass.Constructor, profileName.ClassName);

            // Add constant value constraints if there are any, if not, add a setter method
            if (primitive.ConstantValue != null && primitive.ConstantValue.Length > 0)
            {
                genClass.addConstantValue(primitive.ConstantValue);
            }
            else
            {
                GeneratedMethod setter = new GeneratedMethod();
                setter.addParam("java.lang.String value");
                setter.addToThrows("ConfDataException");
                setter.addToBody("super.setValue( value );");
                setter.ReturnType = "void";
                setter.Visibility = "public";
                setter.Name       = "setValue";
                docBuilder.decorateSetValue(setter, primitive.Length);
                genClass.addMethod(setter);

                genClass.addClassImport("Genetibase.NuGenHL7.conf.classes.exceptions.*");
            }
            genClass.addMaxLength(primitive.Length);

            // Decorate with comments
            docBuilder.decoratePrimitive(genClass, primitive);
            if (depManager.Verbose)
            {
                System.Console.Out.WriteLine("Generating Primitive: " + packageName + "." + genClass.Name);
            }

            depManager.generateFile(genClass, packageName, genClass.Name);
        }