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