1 19 20 package org.netbeans.modules.j2ee.ejbcore.action; 21 22 import java.io.IOException ; 23 import java.util.ArrayList ; 24 import java.util.Collections ; 25 import java.util.List ; 26 import javax.lang.model.element.Modifier; 27 import org.netbeans.modules.j2ee.common.method.MethodModel; 28 import org.netbeans.modules.j2ee.dd.api.ejb.EntityAndSession; 29 import org.netbeans.modules.j2ee.ejbcore._RetoucheUtil; 30 import org.openide.filesystems.FileObject; 31 32 36 public class HomeMethodGenerator extends AbstractMethodGenerator { 37 38 private HomeMethodGenerator(EntityAndSession ejb, FileObject ejbClassFileObject) { 39 super(ejb, ejbClassFileObject, null); 40 } 41 42 public static HomeMethodGenerator create(EntityAndSession ejb, FileObject ejbClassFileObject) { 43 return new HomeMethodGenerator(ejb, ejbClassFileObject); 44 } 45 46 public void generate(MethodModel methodModel, boolean generateLocal, boolean generateRemote) throws IOException { 47 48 if (generateLocal && ejb.getLocalHome() != null) { 50 MethodModel methodModelCopy = MethodModel.create( 51 methodModel.getName(), 52 methodModel.getReturnType(), 53 null, 54 methodModel.getParameters(), 55 methodModel.getExceptions(), 56 Collections.<Modifier>emptySet() 57 ); 58 FileObject fileObject = _RetoucheUtil.resolveFileObjectForClass(ejbClassFileObject, ejb.getLocalHome()); 59 addMethod(methodModelCopy, fileObject, ejb.getLocalHome()); 60 } 61 62 if (generateRemote && ejb.getHome() != null) { 64 List <String > exceptions = exceptions = new ArrayList <String >(methodModel.getExceptions()); 65 if (!methodModel.getExceptions().contains("java.rmi.RemoteException")) { 66 exceptions.add("java.rmi.RemoteException"); 67 } 68 MethodModel methodModelCopy = MethodModel.create( 69 methodModel.getName(), 70 methodModel.getReturnType(), 71 null, 72 methodModel.getParameters(), 73 exceptions, 74 Collections.<Modifier>emptySet() 75 ); 76 FileObject fileObject = _RetoucheUtil.resolveFileObjectForClass(ejbClassFileObject, ejb.getHome()); 77 addMethod(methodModelCopy, fileObject, ejb.getHome()); 78 } 79 80 MethodModel methodModelCopy = MethodModel.create( 82 "ejbHome" + Character.toUpperCase(methodModel.getName().charAt(0)) + methodModel.getName().substring(1), 83 methodModel.getReturnType(), 84 methodModel.getBody(), 85 methodModel.getParameters(), 86 methodModel.getExceptions(), 87 Collections.singleton(Modifier.PUBLIC) 88 ); 89 addMethod(methodModelCopy, ejbClassFileObject, ejb.getEjbClass()); 90 91 } 92 93 } 94 | Popular Tags |