1 19 package org.netbeans.modules.j2ee.ejbcore.api.methodcontroller; 20 21 import java.util.Collection ; 22 import java.util.Set ; 23 import org.netbeans.modules.j2ee.common.method.MethodModel; 24 import org.netbeans.modules.j2ee.ejbcore.api.methodcontroller.MethodType.BusinessMethodType; 25 import org.netbeans.modules.j2ee.ejbcore.api.methodcontroller.MethodType.CreateMethodType; 26 import org.netbeans.modules.j2ee.ejbcore.api.methodcontroller.MethodType.FinderMethodType; 27 import org.netbeans.modules.j2ee.ejbcore.api.methodcontroller.MethodType.HomeMethodType; 28 29 34 class EntityGenerateFromImplVisitor implements MethodType.MethodTypeVisitor, AbstractMethodController.GenerateFromImpl { 35 36 private MethodModel intfMethod; 37 private String destination; 38 private String home; 39 private String component; 40 41 public EntityGenerateFromImplVisitor() { 42 } 43 44 public void getInterfaceMethodFromImpl(MethodType methodType, String home, String component) { 45 this.home = home; 46 this.component = component; 47 methodType.accept(this); 48 } 49 50 public MethodModel getInterfaceMethod() { 51 return intfMethod; 52 } 53 54 public String getDestinationInterface() { 55 return destination; 56 } 57 58 public void visit(BusinessMethodType bmt) { 59 intfMethod = bmt.getMethodElement(); 60 destination = component; 61 } 62 63 public void visit(CreateMethodType cmt) { 64 intfMethod = cmt.getMethodElement(); 65 String origName = intfMethod.getName(); 66 String newName = null; 67 if (origName.startsWith("ejbPostCreate")) { 68 newName = chopAndUpper(origName,"ejbPost"); } else { 70 newName = chopAndUpper(origName,"ejb"); } 72 intfMethod = MethodModel.create( 73 newName, 74 intfMethod.getReturnType(), 75 intfMethod.getBody(), 76 intfMethod.getParameters(), 77 intfMethod.getExceptions(), 78 intfMethod.getModifiers() 79 ); 80 destination = home; 81 } 82 83 public void visit(HomeMethodType hmt) { 84 intfMethod = hmt.getMethodElement(); 85 String origName = intfMethod.getName(); 86 String newName = chopAndUpper(origName,"ejbHome"); intfMethod = MethodModel.create( 88 newName, 89 intfMethod.getReturnType(), 90 intfMethod.getBody(), 91 intfMethod.getParameters(), 92 intfMethod.getExceptions(), 93 intfMethod.getModifiers() 94 ); 95 destination = home; 96 } 97 98 public void visit(FinderMethodType fmt) { 99 intfMethod = fmt.getMethodElement(); 100 String origName = intfMethod.getName(); 101 String newName = chopAndUpper(origName,"ejb"); String fqn = intfMethod.getReturnType(); 103 boolean changeType = false; 104 if (!fqn.equals(Collection .class.getName()) || !fqn.equals(Set .class.getName())) { 105 changeType = true; 106 } 107 intfMethod = MethodModel.create( 108 newName, 109 changeType ? component : intfMethod.getReturnType(), 110 intfMethod.getBody(), 111 intfMethod.getParameters(), 112 intfMethod.getExceptions(), 113 intfMethod.getModifiers() 114 ); 115 destination = home; 118 } 119 120 private String chopAndUpper(String fullName, String chop) { 121 StringBuffer stringBuffer = new StringBuffer (fullName); 122 stringBuffer.delete(0, chop.length()); 123 stringBuffer.setCharAt(0, Character.toLowerCase(stringBuffer.charAt(0))); 124 return stringBuffer.toString(); 125 } 126 } 127 | Popular Tags |