View Javadoc
1   /**
2   The contents of this file are subject to the Mozilla Public License Version 1.1 
3   (the "License"); you may not use this file except in compliance with the License. 
4   You may obtain a copy of the License at http://www.mozilla.org/MPL/ 
5   Software distributed under the License is distributed on an "AS IS" basis, 
6   WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the 
7   specific language governing rights and limitations under the License. 
8   
9   The Original Code is "ConfGen.java".  Description: 
10  "This Class is used to Generate a Class" 
11  
12  The Initial Developer of the Original Code is University Health Network. Copyright (C) 
13  2001.  All Rights Reserved. 
14  
15  Contributor(s): James Agnew
16                  Paul Brohman
17                  Mitch Delachevrotiere
18                  Shawn Dyck
19    				Cory Metcalf
20    				
21  Alternatively, the contents of this file may be used under the terms of the 
22  GNU General Public License (the  ?GPL?), in which case the provisions of the GPL are 
23  applicable instead of those above.  If you wish to allow use of your version of this 
24  file only under the terms of the GPL and not to allow others to use your version 
25  of this file under the MPL, indicate your decision by deleting  the provisions above 
26  and replace  them with the notice and other provisions required by the GPL License.  
27  If you do not delete the provisions above, a recipient may use your version of 
28  this file under either the MPL or the GPL. 
29  
30  */
31  package ca.uhn.hl7v2.conf.classes.generator.builders;
32  
33  import java.io.*;
34  
35  import ca.uhn.hl7v2.conf.classes.exceptions.*;
36  
37  /** This Class is used to Generate a Class
38   * @author <table><tr>James Agnew</tr>
39   *                <tr>Paul Brohman</tr>
40   *                <tr>Mitch Delachevrotiere</tr>
41   *                <tr>Shawn Dyck</tr>
42   * 				  <tr>Cory Metcalf</tr></table>
43   */
44  public class ConfGen {
45  
46     /** this is the main method to start the Conformance Generator 
47      * @param args the command line argument
48      */
49     public static void main(String[] args) {
50  	  ConfGenf/classes/generator/builders/ConfGen.html#ConfGen">ConfGen gc = new ConfGen();
51        CommandParserses/generator/builders/CommandParser.html#CommandParser">CommandParser cp = new CommandParser();
52  
53        cp.parse(args);
54  
55        if (cp.getHelpFlag()) {
56           System.out.println("Usage: ConfGen [-vht] SOURCE DESTINATION PACKAGENAME");
57           return;
58        }
59  
60        if (cp.getErrFlag()) {
61           System.out.println("ConfGen: command line parse error");
62           System.out.println("ConfGen: " + cp.getError());
63           return;
64        }
65  
66        DeploymentManagergenerator/builders/DeploymentManager.html#DeploymentManager">DeploymentManager dm = new DeploymentManager(cp.getDest(), cp.getPackage());
67        if (cp.getTestFlag()) {
68           System.out.println("ConfGen: system test enabled");
69           gc.test();
70           return;
71        }
72        if (cp.getVerbFlag()) {
73           System.out.println("ConfGen: verbose display enabled");
74           dm.setVerbose(true);
75        }
76  
77        System.out.println("Generating Source...");
78        gc.generateConf(dm, cp);
79        System.out.println("Done.");
80     }
81  
82     /** this method generates conformance
83      * @param dm the DeploymentManager
84      * @param cp the CommandParser which parses the command line argument of ConfGen 
85      */
86     public void generateConf(DeploymentManager dm, CommandParser cp) {
87  	  BufferedReader in = null;
88        try {
89           File f = new File(cp.getSource());
90           in = new BufferedReader(new FileReader(f));
91           char[] cbuf = new char[(int) f.length()];
92           in.read(cbuf, 0, (int) f.length());
93           dm.generate(String.valueOf(cbuf));
94        } catch (FileNotFoundException e) {
95           System.out.println("Filenotfoundexception: " + e.toString());
96        } catch (IOException e) {
97           System.out.println("IOexception:\n" + e.toString() + "\n");
98        } catch (ConformanceError e) {
99           System.out.println("ConformanceError:\n" + e.toString() + "\n");
100       } catch (ConformanceException e) {
101       	 System.out.println("ConformanceException:\n" + e.toString() + "\n");
102       } finally {
103     	  if (in != null)
104 			try {
105 				in.close();
106 			} catch (IOException ignored) {
107 			}
108       }
109    }
110 
111    /** this method tests the conformance generator to see if it is working
112     */
113    public void test() {
114       try {
115          System.out.print("Checking for XML Parser:");
116          Class.forName("org.w3c.dom.Element");
117          System.out.println("           PASS");
118       } catch (ClassNotFoundException e) {
119          System.out.println("           FAIL");
120       }
121 
122       try {
123          System.out.print("Checking for Xerces:");
124          Class.forName("com.sun.org.apache.xerces.internal.parsers.DOMParser");
125          System.out.println("               PASS");
126       } catch (ClassNotFoundException e) {
127          System.out.println("               FAIL");
128       }
129 
130       try {
131          System.out.print("Checking for Conformance Classes:");
132          Class.forName("ca.uhn.hl7v2.conf.classes.generator.builders.ConformanceMessageBuilder");
133          System.out.println("  PASS");
134       } catch (ClassNotFoundException e) {
135          System.out.println("  FAIL");
136       }
137 
138       try {
139          System.out.print("Checking for Apache Ant:");
140          Class.forName("org.apache.tools.ant.Main");
141          System.out.println("           PASS");
142       } catch (ClassNotFoundException e) {
143          System.out.println("           FAIL");
144       }
145    }
146 }