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 "DBTableRepository.java".  Description: 
10  "Implements TableRepository by looking up values from the default HL7
11    normative database" 
12  
13  The Initial Developer of the Original Code is University Health Network. Copyright (C) 
14  2001.  All Rights Reserved. 
15  
16  Contributor(s): James Agnew
17                  Paul Brohman
18                  Mitch Delachevrotiere
19                  Shawn Dyck
20    				Cory Metcalf
21    				
22  Alternatively, the contents of this file may be used under the terms of the 
23  GNU General Public License (the  ?GPL?), in which case the provisions of the GPL are 
24  applicable instead of those above.  If you wish to allow use of your version of this 
25  file only under the terms of the GPL and not to allow others to use your version 
26  of this file under the MPL, indicate your decision by deleting  the provisions above 
27  and replace  them with the notice and other provisions required by the GPL License.  
28  If you do not delete the provisions above, a recipient may use your version of 
29  this file under either the MPL or the GPL. 
30  
31  */ 
32  package ca.uhn.hl7v2.conf.classes.generator.builders;
33  
34  import ca.uhn.hl7v2.conf.spec.message.*;
35  import ca.uhn.hl7v2.conf.spec.*;
36  import ca.uhn.hl7v2.conf.classes.generator.genclasses.*;
37  
38  /** This method builds the Conformance Message Class
39   * @author <table><tr>James Agnew</tr>
40   *                <tr>Paul Brohman</tr>
41   *                <tr>Mitch Delachevrotiere</tr>
42   *                <tr>Shawn Dyck</tr>
43   * 				  <tr>Cory Metcalf</tr></table>
44   */
45  public class ConformanceMessageBuilder {
46     private GeneratedConformanceMessage confMsg;
47     private StaticDef msg;
48     private final String packageName;
49  
50     /** This constructor will create a new ConformanceMessageBuilder
51      * @param packageName the name of the package
52      */
53     public ConformanceMessageBuilder(String packageName) {
54        this.packageName = packageName;
55     }
56  
57     /** This method builds a Conformance Message Class
58      * @param runtimeProfile the profile which to genrate Conformance Classes for
59      * @param depManager the DeploymentManager
60      */
61     public void buildClass(RuntimeProfile runtimeProfile, DeploymentManager depManager){
62        this.msg = runtimeProfile.getMessage();
63        this.confMsg = new GeneratedConformanceMessage();
64           
65        ProfileNameerator/builders/ProfileName.html#ProfileName">ProfileName profileName = new ProfileName(msg.getMsgStructID(), ProfileName.PS_MSG);
66  
67        String version = "v" + runtimeProfile.getHL7Version().replaceAll("\\.", "");
68        String underlyingDataType = "ca.uhn.hl7v2.model." + version + ".message." + msg.getMsgStructID();
69  
70        ConformanceSegmentBuilderonformanceSegmentBuilder.html#ConformanceSegmentBuilder">ConformanceSegmentBuilder confSegBuilder = new ConformanceSegmentBuilder(packageName, version, depManager);
71        ConformanceSegGroupBuilderanceSegGroupBuilder.html#ConformanceSegGroupBuilder">ConformanceSegGroupBuilder confSegGroupBuilder = new ConformanceSegGroupBuilder(packageName, version, depManager, msg.getMsgStructID());
72        DocumentationBuilder docBuilder = DocumentationBuilder.getDocumentationBuilder();
73  
74        // Add class package and imports
75        confMsg.setClassPackage(packageName);
76        confMsg.addClassImport("ca.uhn.hl7v2.conf.classes.abs.*");
77        confMsg.addClassImport("ca.uhn.hl7v2.conf.classes.exceptions.*");
78  
79        // Set class properties
80        confMsg.setName(profileName.getClassName());
81        confMsg.setProperties("extends AbstractConformanceContainer");
82  
83        // Decorate the class with comments
84        docBuilder.decorateConformanceMessage(confMsg, runtimeProfile);
85        docBuilder.decorateConstructor( confMsg.getConstructor(), msg.getMsgType() );
86  
87        // add hapi message
88        confMsg.addHAPIMessage(underlyingDataType);
89  
90        for (int i = 1; i <= msg.getChildren(); i++) {
91  		 //don't build not supported, backward, or unknown types
92  		 String usage = msg.getChild(i).getUsage();
93  		 if( usage.equals("X") || usage.equals("B") || usage.equals("U") )
94  			continue;
95  			
96           if (msg.getChild(i) instanceof Seg) {
97              ProfileName childProfileName = profileName.newInstance(msg.getChild(i).getName(), ProfileName.PS_SEG);
98  
99              // Add the member variable vector to hold them
100             confMsg.addMemberVariable("private FiniteList " + childProfileName.getMemberName() + ";");
101             confMsg.getConstructor().addToBody(childProfileName.getMemberName() + " = new FiniteList( " + childProfileName.getClassName() + ".class, hapiMessage );");
102 
103 				UnderlyingAccessor childAccessor = new UnderlyingAccessor(underlyingDataType, childProfileName.getAccessorName());
104             GeneratedRepGetterr/genclasses/GeneratedRepGetter.html#GeneratedRepGetter">GeneratedRepGetter repGetter = new GeneratedRepGetter(childProfileName, childAccessor.getAcceptsRep());
105 
106             docBuilder.decorateRepGetter(repGetter, msg.getChild(i), childProfileName.getAccessorName());
107 
108             confMsg.addMethod(repGetter);
109             if (depManager.getVerbose())
110                System.out.println("Generating Segment: " + packageName + "." + confMsg.getName());
111 
112             confSegBuilder.buildClass((Seg) msg.getChild(i), underlyingDataType, childProfileName.clearNameMap());
113 
114          } else if (msg.getChild(i) instanceof SegGroup) {
115                ProfileName childProfileName = profileName.newInstance(msg.getChild(i).getName(), ProfileName.PS_SEGG);
116 
117                // Add the member variable vector to hold them
118                confMsg.addMemberVariable("private FiniteList " + childProfileName.getMemberName() + ";");
119                confMsg.getConstructor().addToBody(childProfileName.getMemberName() + " = new FiniteList( " + childProfileName.getClassName() + ".class, hapiMessage );");
120 
121 					String underlyingAccessorName = "get" + msg.getMsgStructID() + "_" + ConformanceSegGroupBuilder.generateSegGroupName((SegGroup)msg.getChild(i));
122 					UnderlyingAccessor childAccessor = new UnderlyingAccessor(underlyingDataType, underlyingAccessorName);
123                GeneratedRepGetterr/genclasses/GeneratedRepGetter.html#GeneratedRepGetter">GeneratedRepGetter repGetter = new GeneratedRepGetter(childProfileName, childAccessor.getAcceptsRep());
124 
125                docBuilder.decorateRepGetter(repGetter, msg.getChild(i), childProfileName.getOriginalName());
126                confMsg.addMethod(repGetter);
127                if (depManager.getVerbose())
128                   System.out.println("Generating SegGroup: " + packageName + "." + confMsg.getName());
129 
130                confSegGroupBuilder.buildClass((SegGroup) msg.getChild(i), underlyingDataType, childProfileName.clearNameMap());
131             }
132 
133       }
134 
135       depManager.generateFile(confMsg, packageName, profileName.getClassName());
136    }
137 }