コード例 #1
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
            {
                NuGenSegmentDef[] segments = getSegments(message, version);
                //System.out.println("Making: " + message + " with " + segments.length + " segments (not writing message code - just groups)");

                NuGenGroupDef       group    = NuGenGroupGenerator.getGroupDef(segments, null, baseDirectory, version, message);
                NuGenStructureDef[] contents = group.Structures;

                //make base directory
                if (!(baseDirectory.EndsWith("\\") || baseDirectory.EndsWith("/")))
                {
                    baseDirectory = baseDirectory + "/";
                }
                System.IO.FileInfo targetDir = NuGenSourceGenerator.makeDirectory(baseDirectory + NuGenSourceGenerator.getVersionPackagePath(version) + "message");
                System.Console.Out.WriteLine("Writing " + message + " to " + targetDir.FullName);
                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 + ".java", 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(NuGenGroupGenerator.makeAccessor(group, i));
                }

                //add implementation of model.control interface, if any
                //out.write(Control.getImplementation(Control.getInterfaceImplementedBy(message), version));
                out_Renamed.Write("}\r\n");
                out_Renamed.Flush();
                out_Renamed.Close();
            }
            catch (System.Exception)
            {
            }
        }
コード例 #2
0
        /// <summary> Returns header material for the source code of a Message class (including
        /// package, imports, JavaDoc, and class declaration).
        /// </summary>
        public static System.String makePreamble(NuGenStructureDef[] contents, System.String message, System.String chapter, System.String version)
        {
            System.Text.StringBuilder preamble = new System.Text.StringBuilder();
            preamble.Append("package ");
            preamble.Append(NuGenSourceGenerator.getVersionPackageName(version));
            preamble.Append("message;\r\n\r\n");
            preamble.Append("import ");
            preamble.Append(NuGenSourceGenerator.getVersionPackageName(version));
            preamble.Append("group.*;\r\n\r\n");
            preamble.Append("import ");
            preamble.Append(NuGenSourceGenerator.getVersionPackageName(version));
            preamble.Append("segment.*;\r\n\r\n");
            preamble.Append("import Genetibase.NuGenHL7.HL7Exception;\r\n\r\n");
            preamble.Append("import Genetibase.NuGenHL7.parser.ModelClassFactory;\r\n\r\n");
            preamble.Append("import Genetibase.NuGenHL7.parser.DefaultModelClassFactory;\r\n\r\n");
            preamble.Append("import Genetibase.NuGenHL7.model.AbstractMessage;\r\n\r\n");
            preamble.Append("/**\r\n");
            preamble.Append(" * <p>Represents a ");
            preamble.Append(message);
            preamble.Append(" message structure (see chapter ");
            preamble.Append(chapter);
            preamble.Append("). This structure contains the \r\n");
            preamble.Append(" * following elements: </p>\r\n");
            preamble.Append(NuGenGroupGenerator.makeElementsDoc(contents));
            preamble.Append(" */\r\n");
            preamble.Append("public class ");
            preamble.Append(message);
            preamble.Append(" extends AbstractMessage ");

            //implement interface from model.control package if required

            /*Class correspondingControlInterface = Control.getInterfaceImplementedBy(message);
             * if (correspondingControlInterface != null) {
             * preamble.append("implements ");
             * preamble.append(correspondingControlInterface.getName());
             * }*/

            preamble.Append(" {\r\n\r\n");

            return(preamble.ToString());
        }