コード例 #1
0
 /// <summary> Returns heading material for class source code (package, imports, JavaDoc, class
 /// declaration).
 /// </summary>
 public static System.String makePreamble(GroupDef group, System.String version)
 {
     System.Text.StringBuilder preamble = new System.Text.StringBuilder();
     preamble.Append("using ca.uhn.hl7v2.parser;\r\n");
     preamble.Append("using ca.uhn.hl7v2;\r\n");
     preamble.Append("using ca.uhn.log;\r\n");
     preamble.Append("using System;\r\n");
     preamble.Append("using ");
     preamble.Append(SourceGenerator.getVersionPackageName(version));
     preamble.Append("segment;\r\n\r\n");
     preamble.Append("using ca.uhn.hl7v2.model;\r\n");
     preamble.Append("/**\r\n");
     preamble.Append(" * <p>Represents the ");
     preamble.Append(group.Name);
     preamble.Append(" Group.  A Group is an ordered collection of message \r\n");
     preamble.Append(" * segments that can repeat together or be optionally in/excluded together.\r\n");
     preamble.Append(" * This Group contains the following elements: </p>\r\n");
     preamble.Append(makeElementsDoc(group.Structures));
     preamble.Append(" */\r\n");
     preamble.Append("namespace ");
     preamble.Append(SourceGenerator.getVersionPackageName(version));
     preamble.Append("group\n");
     preamble.Append("{\r\n");
     preamble.Append("[Serializable]\r\n");
     preamble.Append("public class ");
     preamble.Append(group.Name);
     preamble.Append(" : AbstractGroup {\r\n\r\n");
     return(preamble.ToString());
 }
コード例 #2
0
        /// <summary> <p>Creates source code for a Group and returns a GroupDef object that
        /// describes the Group's name, optionality, repeatability.  The source
        /// code is written under the given directory.</p>
        /// <p>The structures list may contain [] and {} pairs representing
        /// nested groups and their optionality and repeastability.  In these cases
        /// this method is called recursively.</p>
        /// <p>If the given structures list begins and ends with repetition and/or
        /// optionality markers the repetition and optionality of the returned
        /// GroupDef are set accordingly.</p>
        /// </summary>
        /// <param name="structures">a list of the structures that comprise this group - must
        /// be at least 2 long
        /// </param>
        /// <param name="baseDirectory">the directory to which files should be written
        /// </param>
        /// <param name="message">the message to which this group belongs
        /// </param>
        /// <throws>  HL7Exception if the repetition and optionality markers are not  </throws>
        /// <summary>      properly nested.
        /// </summary>
        public static GroupDef writeGroup(StructureDef[] structures, System.String groupName, System.String baseDirectory, System.String version, System.String message)
        {
            //make base directory
            if (!(baseDirectory.EndsWith("\\") || baseDirectory.EndsWith("/")))
            {
                baseDirectory = baseDirectory + "/";
            }
            System.IO.FileInfo targetDir = SourceGenerator.makeDirectory(baseDirectory + SourceGenerator.getVersionPackageDirectory(version) + "group");

            GroupDef group = getGroupDef(structures, groupName, baseDirectory, version, message);

            //UPGRADE_WARNING: At least one expression was used more than once in the target code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1181'"
            //UPGRADE_TODO: Constructor 'java.io.FileWriter.FileWriter' was converted to 'System.IO.StreamWriter' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioFileWriterFileWriter_javalangString_boolean'"
            //UPGRADE_TODO: Class 'java.io.FileWriter' was converted to 'System.IO.StreamWriter' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioFileWriter'"
            using (System.IO.StreamWriter out_Renamed = new System.IO.StreamWriter(targetDir.FullName + "/" + group.Name + ".cs"))
            {
                out_Renamed.Write(makePreamble(group, version));
                out_Renamed.Write(makeConstructor(group, version));

                StructureDef[] shallow = group.Structures;
                for (int i = 0; i < shallow.Length; i++)
                {
                    out_Renamed.Write(makeAccessor(group, i));
                }
                out_Renamed.Write("}\r\n");                 //Closing class
                out_Renamed.Write("}\r\n");                 //Closing namespace
            }
            return(group);
        }
コード例 #3
0
        /// <summary> Returns source code for the contructor for this Group class. </summary>
        public static System.String makeConstructor(GroupDef group, System.String version)
        {
            //UPGRADE_ISSUE: Method 'java.lang.System.getProperty' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangSystem'"
            bool useFactory = ca.uhn.Properties.Settings.Default.useFactory;

            System.Text.StringBuilder source = new System.Text.StringBuilder();

            source.Append("\t/** \r\n");
            source.Append("\t * Creates a new ");
            source.Append(group.Name);
            source.Append(" Group.\r\n");
            source.Append("\t */\r\n");
            source.Append("\tpublic ");
            source.Append(group.Name);
            source.Append("(Group parent, ModelClassFactory factory) : base(parent, factory){\r\n");
            source.Append("\t   try {\r\n");
            StructureDef[] structs    = group.Structures;
            int            numStructs = structs.Length;

            for (int i = 0; i < numStructs; i++)
            {
                StructureDef def = structs[i];

                if (def.Name.Equals("?"))
                {
                    source.Append("\t      this.addNonstandardSegment(\"ANY\");\r\n");
                }
                else
                {
                    if (useFactory)
                    {
                        source.Append("\t      this.add(factory.get");
                        source.Append((def is GroupDef)?"Group":"Segment");
                        source.Append("Class(\"");
                        source.Append(def.Name);
                        source.Append("\", \"");
                        source.Append(version);
                        source.Append("\"), ");
                    }
                    else
                    {
                        source.Append("\t      this.add(typeof(");
                        source.Append(def.Name);
                        source.Append("), ");
                    }

                    source.Append(def.Required.ToString().ToLower());
                    source.Append(", ");
                    source.Append(def.Repeating.ToString().ToLower());
                    source.Append(");\r\n");
                }
            }
            source.Append("\t   } catch(HL7Exception e) {\r\n");
            source.Append("\t      HapiLogFactory.getHapiLog(GetType()).error(\"Unexpected error creating ");
            source.Append(group.Name);
            source.Append(" - this is probably a bug in the source code generator.\", e);\r\n");
            source.Append("\t   }\r\n");
            source.Append("\t}\r\n\r\n");
            return(source.ToString());
        }
コード例 #4
0
        /// <summary> Creates source code for a specific message structure and
        /// writes it under the specified directory.
        /// throws IllegalArgumentException if there is no message structure
        /// for this message in the normative database
        /// </summary>
        public static void  make(System.String message, System.String baseDirectory, System.String chapter, System.String version)
        {
            try
            {
                SegmentDef[] segments = getSegments(message, version);
                //System.out.println("Making: " + message + " with " + segments.length + " segments (not writing message code - just groups)");

                GroupDef       group    = GroupGenerator.getGroupDef(segments, null, baseDirectory, version, message);
                StructureDef[] contents = group.Structures;

                //make base directory
                if (!(baseDirectory.EndsWith("\\") || baseDirectory.EndsWith("/")))
                {
                    baseDirectory = baseDirectory + "/";
                }

                System.IO.FileInfo targetDir = SourceGenerator.makeDirectory(baseDirectory + SourceGenerator.getVersionPackageDirectory(version) + "message");
                System.Console.Out.WriteLine("Writing " + message + " to " + targetDir.FullName);
                //UPGRADE_WARNING: At least one expression was used more than once in the target code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1181'"
                //UPGRADE_TODO: Constructor 'java.io.FileWriter.FileWriter' was converted to 'System.IO.StreamWriter' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioFileWriterFileWriter_javalangString_boolean'"
                //UPGRADE_TODO: Class 'java.io.FileWriter' was converted to 'System.IO.StreamWriter' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioFileWriter'"
                using (System.IO.StreamWriter out_Renamed = new System.IO.StreamWriter(targetDir.FullName + "/" + message + ".cs"))
                {
                    //System.IO.StreamWriter out_Renamed = new System.IO.StreamWriter(new System.IO.StreamWriter(targetDir.FullName + "/" + message + ".java", false, System.Text.Encoding.Default).BaseStream, new System.IO.StreamWriter(targetDir.FullName + "/" + message + ".cs", false, System.Text.Encoding.Default).Encoding);
                    out_Renamed.Write(makePreamble(contents, message, chapter, version));
                    out_Renamed.Write(makeConstructor(contents, message, version));
                    for (int i = 0; i < contents.Length; i++)
                    {
                        out_Renamed.Write(GroupGenerator.makeAccessor(group, i));
                    }
                    out_Renamed.Write(makeVersion(version));
                    //add implementation of model.control interface, if any
                    //out.write(Control.getImplementation(Control.getInterfaceImplementedBy(message), version));
                    out_Renamed.Write("}\r\n");                         //End class
                    out_Renamed.Write("}\r\n");                         //End namespace
                }
            }
            catch (System.Exception e)
            {
                log.error("Error while creating source code", e);

                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Class.getName' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                log.warn("Warning: could not write source code for message structure " + message + " - " + e.GetType().FullName + ": " + e.Message);
            }
        }
コード例 #5
0
        /// <summary> Returns source code for an accessor method for a particular Structure. </summary>
        public static System.String makeAccessor(GroupDef group, int structure)
        {
            System.Text.StringBuilder source = new System.Text.StringBuilder();

            StructureDef def = group.Structures[structure];

            System.String name       = def.Name;
            System.String indexName  = group.getIndexName(name);
            System.String getterName = indexName;
            if (def is GroupDef)
            {
                System.String unqualifiedName = ((GroupDef)def).UnqualifiedName;
                getterName = group.getIndexName(unqualifiedName);
            }

            //make accessor for first (or only) rep ...
            source.Append("\t/**\r\n");
            source.Append("\t * Returns ");
            if (def.Repeating)
            {
                source.Append(" first repetition of ");
            }
            source.Append(indexName);
            source.Append(" (");
            source.Append(def.Description);
            source.Append(") - creates it if necessary\r\n");
            source.Append("\t */\r\n");
            source.Append("\tpublic ");
            source.Append(def.Name);
            source.Append(" ");
            if (def.Repeating)
            {
                source.Append("get");
                source.Append(getterName);
                source.Append("() {\r\n");
            }
            else
            {
                source.Append(getterName);
                source.Append(" { \r\n");
                source.Append("get{\r\n");
            }
            source.Append("\t   ");
            source.Append(def.Name);
            source.Append(" ret = null;\r\n");
            source.Append("\t   try {\r\n");
            source.Append("\t      ret = (");
            source.Append(def.Name);
            source.Append(")this.get_Renamed(\"");
            source.Append(getterName);
            source.Append("\");\r\n");
            source.Append("\t   } catch(HL7Exception e) {\r\n");
            source.Append("\t      HapiLogFactory.getHapiLog(GetType()).error(\"Unexpected error accessing data - this is probably a bug in the source code generator.\", e);\r\n");
            source.Append("\t      throw new System.Exception(\"An unexpected error ocurred\",e);\r\n");
            source.Append("\t   }\r\n");
            source.Append("\t   return ret;\r\n");
            if (!def.Repeating)
            {
                source.Append("\t}\r\n");
            }
            source.Append("\t}\r\n\r\n");

            if (def.Repeating)
            {
                //make accessor for specific rep ...
                source.Append("\t/**\r\n");
                source.Append("\t * Returns a specific repetition of ");
                source.Append(indexName);
                source.Append("\r\n");
                source.Append("\t * (");
                source.Append(def.Description);
                source.Append(") - creates it if necessary\r\n");
                source.Append("\t * throws HL7Exception if the repetition requested is more than one \r\n");
                source.Append("\t *     greater than the number of existing repetitions.\r\n");
                source.Append("\t */\r\n");
                source.Append("\tpublic ");
                source.Append(def.Name);
                source.Append(" get");
                source.Append(getterName);
                source.Append("(int rep) { \r\n");
                source.Append("\t   return (");
                source.Append(def.Name);
                source.Append(")this.get_Renamed(\"");
                source.Append(getterName);
                source.Append("\", rep);\r\n");
                source.Append("\t}\r\n\r\n");

                //make accessor for number of reps
                source.Append("\t/** \r\n");
                source.Append("\t * Returns the number of existing repetitions of ");
                source.Append(indexName);
                source.Append(" \r\n");
                source.Append("\t */ \r\n");
                source.Append("\tpublic int ");
                source.Append(getterName);
                source.Append("Reps { \r\n");
                source.Append("get{\r\n");
                source.Append("\t    int reps = -1; \r\n");
                source.Append("\t    try { \r\n");
                source.Append("\t        reps = this.getAll(\"");
                source.Append(getterName);
                source.Append("\").Length; \r\n");
                source.Append("\t    } catch (HL7Exception e) { \r\n");
                source.Append("\t        string message = \"Unexpected error accessing data - this is probably a bug in the source code generator.\"; \r\n");
                source.Append("\t        HapiLogFactory.getHapiLog(GetType()).error(message, e); \r\n");
                source.Append("\t        throw new System.Exception(message);\r\n");
                source.Append("\t    } \r\n");
                source.Append("\t    return reps; \r\n");
                source.Append("\t}\r\n");
                source.Append("\t} \r\n\r\n");
            }

            return(source.ToString());
        }
コード例 #6
0
        /// <summary> <p>Given a list of structures defining the deep content of a group (as provided in
        /// the normative database, some being pairs of optionality and repetition markers
        /// and segments nested within) returns a GroupDef including a short list of the shallow contents of the
        /// group (including segments and groups that are immediate children).</p>
        /// <p>For example given MSH [PID PV1] {[ERR NTE]}, short list would be something like
        /// MSH PID_GROUP ERR_GROUP (with PID_GROUP marked as optional and ERR_GROUP marked as
        /// optional and repeating).</p>
        /// <p>This method calls writeGroup(...) where necessary in order to create source code for
        /// any nested groups before returning corresponding GroupDefs.</p>
        /// </summary>
        public static GroupDef getGroupDef(StructureDef[] structures, System.String groupName, System.String baseDirectory, System.String version, System.String message)
        {
            GroupDef ret       = null;
            bool     required  = true;
            bool     repeating = false;
            bool     rep_opt   = false;

            int len = structures.Length;

            StructureDef[] shortList        = new StructureDef[len];      //place to put final list of groups/seg's w/o opt & rep markers
            int            currShortListPos = 0;
            int            currLongListPos  = 0;

            try
            {
                //check for rep and opt (see if start & end elements are [] or {} AND they are each others' pair) ...
                //System.out.println(len + " " + structures[0].getName() +structures[1].getName()+ ".." +structures[len-2].getName() + structures[len-1].getName()+ " " + message);
                if (optMarkers(structures[0].Name, structures[len - 1].Name) && (findGroupEnd(structures, 0) == len - 1))
                {
                    required = false;
                }
                if (repMarkers(structures[0].Name, structures[len - 1].Name) && (findGroupEnd(structures, 0) == len - 1))
                {
                    repeating = true;
                }
                if (repoptMarkers(structures[0].Name, structures[len - 1].Name) && (findGroupEnd(structures, 0) == len - 1))
                {
                    rep_opt = true;
                }
                if (repeating || !required)
                {
                    if (optMarkers(structures[1].Name, structures[len - 2].Name) && (findGroupEnd(structures, 1) == len - 2))
                    {
                        required = false;
                    }
                    if (repMarkers(structures[1].Name, structures[len - 2].Name) && (findGroupEnd(structures, 1) == len - 2))
                    {
                        repeating = true;
                    }
                }

                //loop through, recurse nested groups, and build short list of structures for this group
                int skip = 0;
                if (!required)
                {
                    skip++;
                }
                if (repeating)
                {
                    skip++;
                }
                if (rep_opt)
                {
                    skip++;
                }
                currLongListPos = skip;
                while (currLongListPos < len - skip)
                {
                    System.String currSegName = structures[currLongListPos].Name;
                    if (currSegName.Equals("[") || currSegName.Equals("{") || currSegName.Equals("[{"))
                    {
                        //this is the opening of a new group ...
                        System.String  name               = ((SegmentDef)structures[currLongListPos]).GroupName;
                        int            endOfNewGroup      = findGroupEnd(structures, currLongListPos);
                        StructureDef[] newGroupStructures = new StructureDef[endOfNewGroup - currLongListPos + 1];
                        Array.Copy(structures, currLongListPos, newGroupStructures, 0, newGroupStructures.Length);
                        shortList[currShortListPos] = writeGroup(newGroupStructures, name, baseDirectory, version, message);
                        currLongListPos             = endOfNewGroup + 1;
                    }
                    else
                    {
                        //copy verbatim into short list ...
                        shortList[currShortListPos] = structures[currLongListPos];
                        currLongListPos++;
                    }
                    currShortListPos++;
                }
            }
            catch (System.ArgumentException e)
            {
                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Class.getName' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                throw new HL7Exception("Problem creating nested group: " + e.GetType().FullName + ": " + e.Message, HL7Exception.APPLICATION_INTERNAL_ERROR);
            }

            ret = new GroupDef(message, groupName, required, repeating, "a Group object");
            StructureDef[] finalList = new StructureDef[currShortListPos];             //note: incremented after last assignment
            Array.Copy(shortList, 0, finalList, 0, currShortListPos);
            for (int i = 0; i < finalList.Length; i++)
            {
                ret.addStructure(finalList[i]);
            }

            return(ret);
        }
コード例 #7
0
ファイル: GroupGenerator.cs プロジェクト: snosrap/nhapi
 /// <summary> Returns heading material for class source code (package, imports, JavaDoc, class
 /// declaration).
 /// </summary>
 public static System.String makePreamble(GroupDef group, System.String version)
 {
     System.Text.StringBuilder preamble = new System.Text.StringBuilder();
     preamble.Append("using ca.uhn.hl7v2.parser;\r\n");
     preamble.Append("using ca.uhn.hl7v2;\r\n");
     preamble.Append("using ca.uhn.log;\r\n");
     preamble.Append("using System;\r\n");
     preamble.Append("using ");
     preamble.Append(SourceGenerator.getVersionPackageName(version));
     preamble.Append("segment;\r\n\r\n");
     preamble.Append("using ca.uhn.hl7v2.model;\r\n");
     preamble.Append("/**\r\n");
     preamble.Append(" * <p>Represents the ");
     preamble.Append(group.Name);
     preamble.Append(" Group.  A Group is an ordered collection of message \r\n");
     preamble.Append(" * segments that can repeat together or be optionally in/excluded together.\r\n");
     preamble.Append(" * This Group contains the following elements: </p>\r\n");
     preamble.Append(makeElementsDoc(group.Structures));
     preamble.Append(" */\r\n");
     preamble.Append("namespace ");
     preamble.Append(SourceGenerator.getVersionPackageName(version));
     preamble.Append("group\n");
     preamble.Append("{\r\n");
     preamble.Append("[Serializable]\r\n");
     preamble.Append("public class ");
     preamble.Append(group.Name);
     preamble.Append(" : AbstractGroup {\r\n\r\n");
     return preamble.ToString();
 }
コード例 #8
0
ファイル: GroupGenerator.cs プロジェクト: snosrap/nhapi
        /// <summary> Returns source code for the contructor for this Group class. </summary>
        public static System.String makeConstructor(GroupDef group, System.String version)
        {
            //UPGRADE_ISSUE: Method 'java.lang.System.getProperty' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangSystem'"
            bool useFactory = ca.uhn.Properties.Settings.Default.useFactory;

            System.Text.StringBuilder source = new System.Text.StringBuilder();

            source.Append("\t/** \r\n");
            source.Append("\t * Creates a new ");
            source.Append(group.Name);
            source.Append(" Group.\r\n");
            source.Append("\t */\r\n");
            source.Append("\tpublic ");
            source.Append(group.Name);
            source.Append("(Group parent, ModelClassFactory factory) : base(parent, factory){\r\n");
            source.Append("\t   try {\r\n");
            StructureDef[] structs = group.Structures;
            int numStructs = structs.Length;
            for (int i = 0; i < numStructs; i++)
            {
                StructureDef def = structs[i];

                if (def.Name.Equals("?"))
                {
                    source.Append("\t      this.addNonstandardSegment(\"ANY\");\r\n");
                }
                else
                {
                    if (useFactory)
                    {
                        source.Append("\t      this.add(factory.get");
                        source.Append((def is GroupDef)?"Group":"Segment");
                        source.Append("Class(\"");
                        source.Append(def.Name);
                        source.Append("\", \"");
                        source.Append(version);
                        source.Append("\"), ");
                    }
                    else
                    {
                        source.Append("\t      this.add(typeof(");
                        source.Append(def.Name);
                        source.Append("), ");
                    }

                    source.Append(def.Required.ToString().ToLower());
                    source.Append(", ");
                    source.Append(def.Repeating.ToString().ToLower());
                    source.Append(");\r\n");
                }
            }
            source.Append("\t   } catch(HL7Exception e) {\r\n");
            source.Append("\t      HapiLogFactory.getHapiLog(GetType()).error(\"Unexpected error creating ");
            source.Append(group.Name);
            source.Append(" - this is probably a bug in the source code generator.\", e);\r\n");
            source.Append("\t   }\r\n");
            source.Append("\t}\r\n\r\n");
            return source.ToString();
        }
コード例 #9
0
ファイル: GroupGenerator.cs プロジェクト: snosrap/nhapi
        /// <summary> Returns source code for an accessor method for a particular Structure. </summary>
        public static System.String makeAccessor(GroupDef group, int structure)
        {
            System.Text.StringBuilder source = new System.Text.StringBuilder();

            StructureDef def = group.Structures[structure];

            System.String name = def.Name;
            System.String indexName = group.getIndexName(name);
            System.String getterName = indexName;
            if (def is GroupDef)
            {
                System.String unqualifiedName = ((GroupDef) def).UnqualifiedName;
                getterName = group.getIndexName(unqualifiedName);
            }

            //make accessor for first (or only) rep ...
            source.Append("\t/**\r\n");
            source.Append("\t * Returns ");
            if (def.Repeating)
                source.Append(" first repetition of ");
            source.Append(indexName);
            source.Append(" (");
            source.Append(def.Description);
            source.Append(") - creates it if necessary\r\n");
            source.Append("\t */\r\n");
            source.Append("\tpublic ");
            source.Append(def.Name);
            source.Append(" ");
            if(def.Repeating)
            {
                source.Append("get");
                source.Append(getterName);
                source.Append("() {\r\n");
            }
            else
            {
                source.Append(getterName);
                source.Append(" { \r\n");
                source.Append("get{\r\n");
            }
            source.Append("\t   ");
            source.Append(def.Name);
            source.Append(" ret = null;\r\n");
            source.Append("\t   try {\r\n");
            source.Append("\t      ret = (");
            source.Append(def.Name);
            source.Append(")this.get_Renamed(\"");
            source.Append(getterName);
            source.Append("\");\r\n");
            source.Append("\t   } catch(HL7Exception e) {\r\n");
            source.Append("\t      HapiLogFactory.getHapiLog(GetType()).error(\"Unexpected error accessing data - this is probably a bug in the source code generator.\", e);\r\n");
            source.Append("\t      throw new System.Exception(\"An unexpected error ocurred\",e);\r\n");
            source.Append("\t   }\r\n");
            source.Append("\t   return ret;\r\n");
            if(!def.Repeating)
                source.Append("\t}\r\n");
            source.Append("\t}\r\n\r\n");

            if (def.Repeating)
            {
                //make accessor for specific rep ...
                source.Append("\t/**\r\n");
                source.Append("\t * Returns a specific repetition of ");
                source.Append(indexName);
                source.Append("\r\n");
                source.Append("\t * (");
                source.Append(def.Description);
                source.Append(") - creates it if necessary\r\n");
                source.Append("\t * throws HL7Exception if the repetition requested is more than one \r\n");
                source.Append("\t *     greater than the number of existing repetitions.\r\n");
                source.Append("\t */\r\n");
                source.Append("\tpublic ");
                source.Append(def.Name);
                source.Append(" get");
                source.Append(getterName);
                source.Append("(int rep) { \r\n");
                source.Append("\t   return (");
                source.Append(def.Name);
                source.Append(")this.get_Renamed(\"");
                source.Append(getterName);
                source.Append("\", rep);\r\n");
                source.Append("\t}\r\n\r\n");

                //make accessor for number of reps
                source.Append("\t/** \r\n");
                source.Append("\t * Returns the number of existing repetitions of ");
                source.Append(indexName);
                source.Append(" \r\n");
                source.Append("\t */ \r\n");
                source.Append("\tpublic int ");
                source.Append(getterName);
                source.Append("Reps { \r\n");
                source.Append("get{\r\n");
                source.Append("\t    int reps = -1; \r\n");
                source.Append("\t    try { \r\n");
                source.Append("\t        reps = this.getAll(\"");
                source.Append(getterName);
                source.Append("\").Length; \r\n");
                source.Append("\t    } catch (HL7Exception e) { \r\n");
                source.Append("\t        string message = \"Unexpected error accessing data - this is probably a bug in the source code generator.\"; \r\n");
                source.Append("\t        HapiLogFactory.getHapiLog(GetType()).error(message, e); \r\n");
                source.Append("\t        throw new System.Exception(message);\r\n");
                source.Append("\t    } \r\n");
                source.Append("\t    return reps; \r\n");
                source.Append("\t}\r\n");
                source.Append("\t} \r\n\r\n");
            }

            return source.ToString();
        }
コード例 #10
0
ファイル: GroupGenerator.cs プロジェクト: snosrap/nhapi
        /// <summary> <p>Given a list of structures defining the deep content of a group (as provided in 
        /// the normative database, some being pairs of optionality and repetition markers
        /// and segments nested within) returns a GroupDef including a short list of the shallow contents of the 
        /// group (including segments and groups that are immediate children).</p> 
        /// <p>For example given MSH [PID PV1] {[ERR NTE]}, short list would be something like 
        /// MSH PID_GROUP ERR_GROUP (with PID_GROUP marked as optional and ERR_GROUP marked as 
        /// optional and repeating).</p>
        /// <p>This method calls writeGroup(...) where necessary in order to create source code for 
        /// any nested groups before returning corresponding GroupDefs.</p>
        /// </summary>
        public static GroupDef getGroupDef(StructureDef[] structures, System.String groupName, System.String baseDirectory, System.String version, System.String message)
        {
            GroupDef ret = null;
            bool required = true;
            bool repeating = false;
            bool rep_opt = false;

            int len = structures.Length;
            StructureDef[] shortList = new StructureDef[len]; //place to put final list of groups/seg's w/o opt & rep markers
            int currShortListPos = 0;
            int currLongListPos = 0;

            try
            {
                //check for rep and opt (see if start & end elements are [] or {} AND they are each others' pair) ...
                //System.out.println(len + " " + structures[0].getName() +structures[1].getName()+ ".." +structures[len-2].getName() + structures[len-1].getName()+ " " + message);
                if (optMarkers(structures[0].Name, structures[len - 1].Name) && (findGroupEnd(structures, 0) == len - 1))
                    required = false;
                if (repMarkers(structures[0].Name, structures[len - 1].Name) && (findGroupEnd(structures, 0) == len - 1))
                    repeating = true;
                if (repoptMarkers(structures[0].Name, structures[len - 1].Name) && (findGroupEnd(structures, 0) == len - 1))
                    rep_opt = true;
                if (repeating || !required)
                {
                    if (optMarkers(structures[1].Name, structures[len - 2].Name) && (findGroupEnd(structures, 1) == len - 2))
                        required = false;
                    if (repMarkers(structures[1].Name, structures[len - 2].Name) && (findGroupEnd(structures, 1) == len - 2))
                        repeating = true;
                }

                //loop through, recurse nested groups, and build short list of structures for this group
                int skip = 0;
                if (!required)
                    skip++;
                if (repeating)
                    skip++;
                if (rep_opt)
                    skip++;
                currLongListPos = skip;
                while (currLongListPos < len - skip)
                {
                    System.String currSegName = structures[currLongListPos].Name;
                    if (currSegName.Equals("[") || currSegName.Equals("{") || currSegName.Equals("[{"))
                    {
                        //this is the opening of a new group ...
                        System.String name = ((SegmentDef) structures[currLongListPos]).GroupName;
                        int endOfNewGroup = findGroupEnd(structures, currLongListPos);
                        StructureDef[] newGroupStructures = new StructureDef[endOfNewGroup - currLongListPos + 1];
                        Array.Copy(structures, currLongListPos, newGroupStructures, 0, newGroupStructures.Length);
                        shortList[currShortListPos] = writeGroup(newGroupStructures, name, baseDirectory, version, message);
                        currLongListPos = endOfNewGroup + 1;
                    }
                    else
                    {
                        //copy verbatim into short list ...
                        shortList[currShortListPos] = structures[currLongListPos];
                        currLongListPos++;
                    }
                    currShortListPos++;
                }
            }
            catch (System.ArgumentException e)
            {
                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Class.getName' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                throw new HL7Exception("Problem creating nested group: " + e.GetType().FullName + ": " + e.Message, HL7Exception.APPLICATION_INTERNAL_ERROR);
            }

            ret = new GroupDef(message, groupName, required, repeating, "a Group object");
            StructureDef[] finalList = new StructureDef[currShortListPos]; //note: incremented after last assignment
            Array.Copy(shortList, 0, finalList, 0, currShortListPos);
            for (int i = 0; i < finalList.Length; i++)
            {
                ret.addStructure(finalList[i]);
            }

            return ret;
        }