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 "GeneratedConformanceContainer.java".  Description: 
10  "This Class is used to addChildren of types Component, SubComponent and to set min and max reps" 
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.genclasses;
32  
33  import ca.uhn.hl7v2.conf.classes.generator.builders.*;
34  
35  /** This class is used to addChildren of types Component, SubComponent and to set min and max reps
36   * @author <table><tr>James Agnew</tr>
37   *                <tr>Paul Brohman</tr>
38   *                <tr>Mitch Delachevrotiere</tr>
39   *                <tr>Shawn Dyck</tr>
40   * 				  <tr>Cory Metcalf</tr></table>
41   */
42  public class GeneratedConformanceContainer extends GeneratedClass {
43  
44     /** Default constructor */
45     public GeneratedConformanceContainer() {
46     }
47  
48     /** Adds a Component to a conformance Message
49     * adds a line to the constructor to instantiate that member variable
50     * @param profileName this is the profile name associated with this Class
51     * @param componentNumber the number associated with the component in the profile 
52     * @param childGetter adds this line to the constructor to instantiate Conformance Component class
53     */
54     private void addChild(ProfileName profileName, int componentNumber, String childGetter) {
55  
56        // Add member variable to class for holding Conformance Component class
57        this.addMemberVariable("private " + profileName.getClassName() + " " + profileName.getMemberName() + ";");
58  
59        // Add line to constructor to instantiate Conformance Component class
60        this.getConstructor().addToBody(childGetter);
61  
62        // Add method for retrieving Conformance Component Class
63        GeneratedMethodgenclasses/GeneratedMethod.html#GeneratedMethod">GeneratedMethod getChildMethod = new GeneratedMethod();
64        getChildMethod.addToComments("Provides access to the " + profileName.getOriginalName() + " component child");
65        getChildMethod.addToComments("@return " + profileName.getClassName() + " The " + profileName.getOriginalName() + " component child");
66        getChildMethod.setVisibility("public");
67        getChildMethod.setReturnType(profileName.getClassName());
68        getChildMethod.setName(profileName.getAccessorName());
69        getChildMethod.addToBody("return " + profileName.getMemberName() + ";");
70        this.addMethod(getChildMethod);
71     }
72  
73     /** Adds a Component to a conformance Message
74     * adds a line to the constructor to instantiate that member variable
75     * @param profileName this is the profile name associated with this Class
76     */
77     public void addComponent(ProfileName profileName, int componentNumber, boolean hasChildren) {
78        String underlyingType = hasChildren ? "Composite" : "Primitive";
79        String childGetter = "   " + profileName.getMemberName() + " = new " + profileName.getClassName() + "( (" + underlyingType + ")hapiType.getComponent(" + componentNumber + ") );";
80        this.addChild(profileName, componentNumber, childGetter);
81     }
82  
83     /** Adds a SubComponent to a conformance class
84      * adds a line to the constructor to instantiate that member variable
85      * @param profileName this is the profile name associated with this Class
86      * @param subComponentNumber representing the number representing the subComponent to add
87      */
88     public void addSubComponent(ProfileName profileName, int subComponentNumber) {
89        this.addComponent(profileName, subComponentNumber, false);
90     }
91  
92     /** Special case for adding a subcomponent which is a TS type, because the TS
93      * underlying type is represented as a Composite, which shouldn't exist at
94      * the SubComponent level, but does due to ambiguity in the HL7 spec.
95      * @param profileName this is the profile name associated with this Class
96      */
97     public void addTSSubComponent(ProfileName profileName, int componentNumber, String hl7Version) {
98  
99        String componentOneAccessor = "(Primitive)((ca.uhn.hl7v2.model." + hl7Version + ".datatype.TS)(hapiType.getComponent(" + componentNumber + "))).getComponent(0)";
100       String childGetter = "   " + profileName.getMemberName() + " = new " + profileName.getClassName() + "( " + componentOneAccessor + " );";
101       this.addChild(profileName, componentNumber, childGetter);
102    }
103 
104    /**Adds min and max reps to the genrated classes
105    * @param minReps the Minimum Repetitions
106    * @param maxReps Maximum Repetitions
107    */
108    public void setMinMaxReps(short minReps, short maxReps) {
109 
110       GeneratedMethod/genclasses/GeneratedMethod.html#GeneratedMethod">GeneratedMethod maxRepsMethod = new GeneratedMethod();
111       GeneratedMethod/genclasses/GeneratedMethod.html#GeneratedMethod">GeneratedMethod minRepsMethod = new GeneratedMethod();
112 
113       this.addMemberVariable("private final short MAX_REPS = " + maxReps + ";");
114       this.addMemberVariable("private final short MIN_REPS = " + minReps + ";");
115 
116       // Creates the methos to return the maximum number of repitions for the generated Class
117       DocumentationBuilder.getDocumentationBuilder().decorateMaxReps(maxRepsMethod);
118       maxRepsMethod.setVisibility("public");
119       maxRepsMethod.setReturnType("short");
120       maxRepsMethod.setName("getMaxReps");
121       maxRepsMethod.addToBody("return this.MAX_REPS;");
122       this.addMethod(maxRepsMethod);
123 
124       // Creates the method to return the maximum number of repitions for the generated Class
125       DocumentationBuilder.getDocumentationBuilder().decorateMaxReps(minRepsMethod);
126       minRepsMethod.setVisibility("public");
127       minRepsMethod.setReturnType("short");
128       minRepsMethod.setName("getMinReps");
129       minRepsMethod.addToBody("return this.MIN_REPS;");
130       this.addMethod(minRepsMethod);
131    }
132 
133 }