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 "CMPAttributeGenerator.java".  Description: 
010    "Generates EJB code related to RIM class attributes, for an entity bean 
011      with container managed persistence" 
012    
013    The Initial Developer of the Original Code is University Health Network. Copyright (C) 
014    2001.  All Rights Reserved. 
015    
016    Contributor(s): ______________________________________. 
017    
018    Alternatively, the contents of this file may be used under the terms of the 
019    GNU General Public License (the  ?GPL?), in which case the provisions of the GPL are 
020    applicable instead of those above.  If you wish to allow use of your version of this 
021    file only under the terms of the GPL and not to allow others to use your version 
022    of this file under the MPL, indicate your decision by deleting  the provisions above 
023    and replace  them with the notice and other provisions required by the GPL License.  
024    If you do not delete the provisions above, a recipient may use your version of 
025    this file under either the MPL or the GPL. 
026    
027    */
028    
029    package ca.uhn.hl7v3.sourcegen;
030    
031    /**
032     * Generates EJB code related to RIM class attributes, for an entity bean 
033     * with container managed persistence.    
034     * @author Bryan Tripp
035     */
036    public class CMPAttributeGenerator {
037    
038        /** Creates a new instance of AttributeGenerator */
039        public CMPAttributeGenerator() {
040        }
041    
042        /** 
043         * Returns source code for the method signatures that represent the given
044         * attribute in the EJB remote interface.
045         */ 
046        public String makeRemoteCode(AttributeDefinition att) {
047            StringBuffer code = new StringBuffer();
048            code.append(SourceGenerator.makeJavaDocComment(att.getDescription(), 4));
049            code.append("    ");        
050            code.append(SourceGenerator.makeSetterSignature(att));
051            code.append(" throws RemoteException; \r\n");
052            code.append("    ");        
053            code.append(SourceGenerator.makeGetterSignature(att));
054            code.append(" throws RemoteException; \r\n");
055            return code.toString();
056        }
057        
058        /**
059         * Returns source code for the methods that represent the given attribute 
060         * in a CMP Entity EJB implementation. 
061         */ 
062        public String makeBeanCode(AttributeDefinition att) {
063            StringBuffer code = new StringBuffer();
064            code.append(SourceGenerator.makeJavaDocComment(att.getDescription(), 4));
065    
066            code.append("    ");        
067            code.append(SourceGenerator.makeSetterSignature(att));
068            code.append(" { \r\n");
069            code.append("        this.");
070            code.append(att.getName());
071            code.append(" = ");
072            code.append(att.getName());
073            code.append("; \r\n");
074            code.append("    } \r\n");
075            
076            code.append("    ");        
077            code.append(SourceGenerator.makeGetterSignature(att));
078            code.append(" { \r\n");
079            code.append("        return ");
080            code.append(att.getName());
081            code.append("; \r\n");
082            code.append("    } \r\n\r\n");
083                   
084            return code.toString();
085        }
086        
087        /** Returns public attribute declaration associated with this attribute in CMP Entity Bean. */
088        public String makeBeanAttribute(AttributeDefinition att) {
089            StringBuffer code = new StringBuffer();
090            code.append("    public ");
091            code.append(att.getDataType());
092            code.append(" ");
093            code.append(att.getName());
094            code.append("; \r\n");
095            return code.toString();
096        }
097    }