1 19 20 package org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action; 21 22 import org.netbeans.modules.j2ee.dd.api.ejb.EntityAndSession; 23 import org.netbeans.modules.j2ee.ejbcore._RetoucheUtil; 24 import java.io.IOException ; 25 import java.util.Collections ; 26 import javax.lang.model.element.Modifier; 27 import org.netbeans.modules.j2ee.common.method.MethodCustomizerFactory; 28 import org.netbeans.modules.j2ee.common.method.MethodCustomizer; 29 import org.netbeans.modules.j2ee.common.method.MethodModel; 30 import org.netbeans.modules.j2ee.dd.api.ejb.Entity; 31 import org.netbeans.modules.j2ee.dd.api.ejb.Session; 32 import org.netbeans.modules.j2ee.ejbcore.action.BusinessMethodGenerator; 33 import org.netbeans.modules.j2ee.ejbcore.api.methodcontroller.EjbMethodController; 34 import org.netbeans.modules.j2ee.ejbcore.api.methodcontroller.MethodType; 35 import org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.shared.MethodsNode; 36 import org.openide.ErrorManager; 37 import org.openide.filesystems.FileObject; 38 import org.openide.util.NbBundle; 39 40 44 public class AddBusinessMethodStrategy extends AbstractAddMethodStrategy { 45 46 public AddBusinessMethodStrategy(String name) { 47 super(name); 48 } 49 public AddBusinessMethodStrategy() { 50 super(NbBundle.getMessage(AddBusinessMethodStrategy.class, "LBL_AddBusinessMethodAction")); 51 } 52 53 protected MethodModel getPrototypeMethod() { 54 return MethodModel.create( 55 "businessMethod", 56 "void", 57 "", 58 Collections.<MethodModel.Variable>emptyList(), 59 Collections.<String >emptyList(), 60 Collections.<Modifier>emptySet() 61 ); 62 } 63 64 protected MethodCustomizer createDialog(FileObject fileObject, MethodModel methodModel) throws IOException { 65 String className = _RetoucheUtil.getMainClassName(fileObject); 66 EjbMethodController ejbMethodController = EjbMethodController.createFromClass(fileObject, className); 67 MethodsNode methodsNode = getMethodsNode(); 68 return MethodCustomizerFactory.businessMethod( 69 getTitle(), 70 methodModel, 71 ejbMethodController.hasRemote(), 72 ejbMethodController.hasLocal(), 73 methodsNode == null ? ejbMethodController.hasLocal() : methodsNode.isLocal(), 74 methodsNode == null ? ejbMethodController.hasRemote() : !methodsNode.isLocal(), 75 Collections.<MethodModel>emptySet() ); 77 } 78 79 public MethodType.Kind getPrototypeMethodKind() { 80 return MethodType.Kind.BUSINESS; 81 } 82 83 protected void generateMethod(EntityAndSession entityAndSession, MethodModel method, boolean isOneReturn, 84 boolean publishToLocal, boolean publishToRemote, String ejbql, FileObject ejbClassFO, String className) throws IOException { 85 BusinessMethodGenerator generator = BusinessMethodGenerator.create(entityAndSession, ejbClassFO); 86 generator.generate(method, publishToLocal, publishToRemote); 87 } 88 89 public boolean supportsEjb(FileObject fileObject, String className) { 90 try { 91 EntityAndSession ejb = getEntityAndSession(fileObject, className); 92 if (ejb != null && (ejb instanceof Entity || ejb instanceof Session)) { 93 return true; 94 } 95 } catch (IOException ioe) { 96 ErrorManager.getDefault().notify(ioe); 97 } 98 return false; 99 } 100 101 } 102 | Popular Tags |