KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.netbeans.modules.j2ee.dd.api.ejb.EntityAndSession;
23 import org.netbeans.modules.j2ee.ejbcore._RetoucheUtil;
24 import java.io.IOException JavaDoc;
25 import java.util.Collections JavaDoc;
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 /**
41  * @author Pavel Buzek
42  * @author Martin Adamek
43  */

44 public class AddBusinessMethodStrategy extends AbstractAddMethodStrategy {
45     
46     public AddBusinessMethodStrategy(String JavaDoc 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 JavaDoc>emptyList(),
60                 Collections.<Modifier>emptySet()
61                 );
62     }
63     
64     protected MethodCustomizer createDialog(FileObject fileObject, MethodModel methodModel) throws IOException JavaDoc {
65         String JavaDoc 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() //TODO: RETOUCHE collect all methods
76
);
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 JavaDoc ejbql, FileObject ejbClassFO, String JavaDoc className) throws IOException JavaDoc {
85         BusinessMethodGenerator generator = BusinessMethodGenerator.create(entityAndSession, ejbClassFO);
86         generator.generate(method, publishToLocal, publishToRemote);
87     }
88     
89     public boolean supportsEjb(FileObject fileObject, String JavaDoc 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 JavaDoc ioe) {
96             ErrorManager.getDefault().notify(ioe);
97         }
98         return false;
99     }
100
101 }
102
Popular Tags