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