1 19 20 package org.netbeans.modules.j2ee.ejbcore.patterns; 21 22 import java.io.IOException ; 23 import org.netbeans.modules.j2ee.dd.api.ejb.CmpField; 24 import org.netbeans.modules.j2ee.dd.api.ejb.CmrField; 25 import org.netbeans.modules.j2ee.ejbcore.EjbGenerationUtil; 26 import org.openide.filesystems.FileObject; 27 28 32 public class DTOGenerator { 33 private static final String DTO_SUFIX = "DTO"; private int indexField; 35 private DTOHelper dtoHelp; 36 37 41 private static String toFirstUpper(String str){ 43 StringBuffer buffer = new StringBuffer (str); 44 buffer.setCharAt(0, Character.toUpperCase(buffer.charAt(0))); 45 return buffer.toString(); 46 } 47 48 52 private static String getDTOName(String beanName){ 54 return null; 57 } 58 59 63 private static String getDTOFullName(String pkgName, String beanName){ 65 return pkgName + "." + getDTOName(beanName); 66 } 67 68 73 public void generateDTO(DTOHelper dtoHelp, 74 FileObject pkg, 75 boolean generateCmrFields) 76 throws IOException { 77 String pkgName; 78 this.dtoHelp = dtoHelp; 79 if(pkg != null) { 80 pkgName = EjbGenerationUtil.getSelectedPackageName(pkg); 81 } else { 82 pkgName = dtoHelp.getPackage(); 83 pkg = EjbGenerationUtil.getPackageFileObject(dtoHelp.getSourceGroup(),pkgName, dtoHelp.getProject()); 84 } 85 String dtoName = dtoHelp.getEntityName(); 86 } 107 108 113 private void addField(int index, String fieldName, String cmFieldClassName){ 114 } 120 121 124 private void addCmpFields(CmpField[] cmps){ 125 String fieldName; 126 for(int i = 0; i < cmps.length; i++){ 127 if(cmps[i] != null ) { 128 fieldName = cmps[i].getFieldName(); 129 addField(indexField, fieldName, dtoHelp.getFieldType(fieldName)); 130 indexField++; 133 } 134 } 135 } 136 137 140 private void addCmrFields(CmrField[] cmrs){ 141 String fieldName; 142 String fieldClassName; 143 String cmFieldCmrField; 144 boolean isMultiplicity; 145 int fieldIndex; 146 147 for(int i = 0; i < cmrs.length; i++){ 148 if(cmrs[i] != null){ 149 fieldName = cmrs[i].getCmrFieldName(); 150 fieldIndex = indexField++; 151 isMultiplicity = dtoHelp.isMultiple(cmrs[i]); 152 153 if(isMultiplicity){ 154 fieldClassName = dtoHelp.getFieldType(fieldName); 155 cmFieldCmrField = dtoHelp.getOppositeFieldType(cmrs[i]); 156 } else { 157 fieldClassName = getDTOName( 158 dtoHelp.findEntityNameByLocalInt(dtoHelp.getFieldType(fieldName))); 159 cmFieldCmrField = fieldName; 160 } 161 162 addField(fieldIndex, fieldName, fieldClassName); 163 } 171 } 172 } 173 } 174 | Popular Tags |