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 "GeneratedPrimitive.java".  Description: 
10  "This Class adds the necessary functionality to a primitive 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.genclasses;
32  import ca.uhn.hl7v2.conf.classes.generator.builders.*;
33  
34  /** This Class adds the necessary functionality to a primitive Class
35   * @author <table><tr>James Agnew</tr>
36   *                <tr>Paul Brohman</tr>
37   *                <tr>Mitch Delachevrotiere</tr>
38   *                <tr>Shawn Dyck</tr>
39   * 				  <tr>Cory Metcalf</tr></table>
40   */
41  public class GeneratedPrimitive extends GeneratedConformanceContainer {
42     private DocumentationBuilder docBuilder; // The documentation builder
43  
44     private boolean hasConstantValue;
45  
46     /** Genrates a primitive class
47      */
48     public GeneratedPrimitive() {
49        super();
50  
51        docBuilder = DocumentationBuilder.getDocumentationBuilder();
52  
53        hasConstantValue = false;
54  
55        // Set up constructor
56        this.getConstructor().addParam("Primitive hapiPrimitive", "Reference to the underlying HAPI <CODE>Primitive</CODE> data type.");
57        this.getConstructor().addToBody("super( hapiPrimitive );");
58  
59        GeneratedMethod getMaxLength = new GeneratedMethod();
60        getMaxLength.setName("getMaxLength");
61        getMaxLength.addToBody("return MAX_LENGTH;");
62        getMaxLength.setReturnType("long");
63        getMaxLength.setVisibility("public");
64        docBuilder.decorateMaxLength(getMaxLength);
65        this.addMethod(getMaxLength);
66  
67        GeneratedMethod getConstantValue = new GeneratedMethod();
68        getConstantValue.setName("getConstantValue");
69        getConstantValue.addToBody("return CONSTANT_VALUE;");
70        getConstantValue.setReturnType("String");
71        getConstantValue.setVisibility("public");
72        docBuilder.decorateConstantValue(getConstantValue);
73        this.addMethod(getConstantValue);
74  
75     }
76  
77     /** adds the constant value member variable to the primitive class
78      * @param constantValue the value to enforce
79      */
80     public void addConstantValue(String constantValue) {
81        hasConstantValue = true;
82  
83        if (constantValue != null) {
84           constantValue = "\"" + constantValue + "\"";
85        } else
86           constantValue = "null";
87  
88        this.addMemberVariable("private final String CONSTANT_VALUE = " + constantValue + ";");
89     }
90  
91     /** adds the constant member variable to the primitive class representing the maximum length
92      * @param maxLength the maximum length to enforce
93      */
94     public void addMaxLength(long maxLength) {
95        this.addMemberVariable("private final int MAX_LENGTH = " + maxLength + ";");
96     }
97  
98     /** adds the constant value member variable to the primitive class
99      * @return a String representation of the constant value
100     */
101    public String toString() {
102       if (!hasConstantValue)
103          addConstantValue(null);
104 
105       return super.toString();
106    }
107 
108 }