001 /** 002 The contents of this file are subject to the Mozilla Public License Version 1.1 003 (the "License"); you may not use this file except in compliance with the License. 004 You may obtain a copy of the License at http://www.mozilla.org/MPL/ 005 Software distributed under the License is distributed on an "AS IS" basis, 006 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the 007 specific language governing rights and limitations under the License. 008 009 The Original Code is "DataTypeDefinition.java". Description: 010 "Contains information about a RIM data type, sufficient to generate source code for it" 011 012 The Initial Developer of the Original Code is University Health Network. Copyright (C) 013 2001. All Rights Reserved. 014 015 Contributor(s): ______________________________________. 016 017 Alternatively, the contents of this file may be used under the terms of the 018 GNU General Public License (the ?GPL?), in which case the provisions of the GPL are 019 applicable instead of those above. If you wish to allow use of your version of this 020 file only under the terms of the GPL and not to allow others to use your version 021 of this file under the MPL, indicate your decision by deleting the provisions above 022 and replace them with the notice and other provisions required by the GPL License. 023 If you do not delete the provisions above, a recipient may use your version of 024 this file under either the MPL or the GPL. 025 026 */ 027 028 package ca.uhn.hl7v3.sourcegen; 029 030 import java.util.StringTokenizer; 031 032 /** 033 * Contains information about a RIM data type, sufficient to generate source code for it. 034 * @author Bryan Tripp 035 */ 036 public class DataTypeDefinition { 037 038 private String name; 039 private String longName; 040 private String description; 041 private String type; 042 private String superClass; 043 private ComponentDefinition[] components; 044 045 /** Creates a new instance of DataTypeDefinition */ 046 public DataTypeDefinition() { 047 } 048 049 public void setName(String name) { 050 if (isInstance(name)) { 051 this.name = mapInstanceName(name); 052 } else { 053 this.name = name; 054 } 055 } 056 public String getName() { 057 return this.name; 058 } 059 060 public void setLongName(String longName) { 061 this.longName = longName; 062 } 063 public String getLongName() { 064 return this.longName; 065 } 066 067 public void setDescription(String description) { 068 this.description = description; 069 } 070 public String getDescription() { 071 return this.description; 072 } 073 074 public void setType(String type) { 075 this.type = type; 076 } 077 public String getType() { 078 return this.type; 079 } 080 081 public void setSuperClass(String superClass) { 082 if (superClass != null && isInstance(superClass)) { 083 this.superClass = mapInstanceName(superClass); 084 } else { 085 this.superClass = superClass; 086 } 087 } 088 public String getSuperClass() { 089 return this.superClass; 090 } 091 092 public void setComponents(ComponentDefinition[] components) { 093 this.components = components; 094 } 095 public ComponentDefinition[] getComponents() { 096 return this.components; 097 } 098 099 /** 100 * Given the name of an Instance RIM data type (i.e. a restriction of a Generic type), 101 * provides the Java class name that will be used to represent it. 102 */ 103 public static String mapInstanceName(String instanceRIMName) { 104 StringTokenizer tok = new StringTokenizer(instanceRIMName.trim(), "<>", false); 105 StringBuffer name = new StringBuffer(); 106 while (tok.hasMoreTokens()) { 107 name.append(tok.nextToken()); 108 if (tok.hasMoreTokens()) name.append("_"); 109 } 110 return name.toString(); 111 } 112 113 /** Performs the reverse mapping to mapInstanceName. */ 114 public static String unmapInstanceName(String instanceJavaName) { 115 return instanceJavaName.replace('_', '<') + ">"; 116 } 117 118 /** 119 * Given a name of the Java class for an Instance RIM data type (i.e. a restriction of a Generic type), 120 * returns the name of the associated Generic class. 121 */ 122 public static String getAssociatedGeneric(String instanceJavaName) { 123 return instanceJavaName.substring(0, instanceJavaName.indexOf('_')); 124 } 125 126 /** Returns true if the given datatype name is an Instance (i.e. specialization of a Generic). */ 127 public static boolean isInstance(String datatypeName) { 128 boolean is = false; 129 if (datatypeName.indexOf('<') > 0) is = true; 130 return is; 131 } 132 133 134 }