KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbcore > ui > logicalview > ejb > action > AddCreateMethodStrategy


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action;
21
22 import java.io.IOException JavaDoc;
23 import java.util.Collections JavaDoc;
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 /**
42  * @author Pavel Buzek
43  */

44 public class AddCreateMethodStrategy extends AbstractAddMethodStrategy {
45     
46     public AddCreateMethodStrategy(String JavaDoc 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 JavaDoc{
66         String JavaDoc 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() //TODO: RETOUCHE collect all methods
77
);
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 JavaDoc ejbql, FileObject ejbClassFO, String JavaDoc className) throws IOException JavaDoc {
86         CreateMethodGenerator generator = CreateMethodGenerator.create(entityAndSession, ejbClassFO);
87         generator.generate(method, publishToLocal, publishToRemote);
88     }
89
90     public boolean supportsEjb(FileObject fileObject, String JavaDoc 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 JavaDoc ioe) {
99             ErrorManager.getDefault().notify(ioe);
100         }
101         return false;
102     }
103
104 }
105
Popular Tags