KickJava   Java API By Example, From Geeks To Geeks.

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


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.ejbcore.action.HomeMethodGenerator;
32 import org.netbeans.modules.j2ee.ejbcore.api.methodcontroller.EjbMethodController;
33 import org.netbeans.modules.j2ee.ejbcore.api.methodcontroller.MethodType;
34 import org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.shared.MethodsNode;
35 import org.openide.ErrorManager;
36 import org.openide.filesystems.FileObject;
37 import org.openide.util.NbBundle;
38
39 /**
40  * Action that can always be invoked and work procedurally.
41  * @author cwebster
42  */

43 public class AddHomeMethodStrategy extends AbstractAddMethodStrategy {
44     
45     public AddHomeMethodStrategy(String JavaDoc name) {
46         super (name);
47     }
48     public AddHomeMethodStrategy () {
49         super(NbBundle.getMessage(AddHomeMethodStrategy.class, "LBL_AddHomeMethodAction"));
50     }
51     
52     protected MethodModel getPrototypeMethod() {
53         return MethodModel.create(
54                 "homeMethod",
55                 "void",
56                 "",
57                 Collections.<MethodModel.Variable>emptyList(),
58                 Collections.<String JavaDoc>emptyList(),
59                 Collections.<Modifier>emptySet()
60                 );
61     }
62
63     protected MethodCustomizer createDialog(FileObject fileObject, final MethodModel methodModel) throws IOException JavaDoc{
64         String JavaDoc className = _RetoucheUtil.getMainClassName(fileObject);
65         EjbMethodController ejbMethodController = EjbMethodController.createFromClass(fileObject, className);
66         MethodsNode methodsNode = getMethodsNode();
67         return MethodCustomizerFactory.homeMethod(
68                 getTitle(),
69                 methodModel,
70                 ejbMethodController.hasRemote(),
71                 ejbMethodController.hasLocal(),
72                 methodsNode == null ? ejbMethodController.hasLocal() : methodsNode.isLocal(),
73                 methodsNode == null ? ejbMethodController.hasRemote() : !methodsNode.isLocal(),
74                 Collections.<MethodModel>emptySet() //TODO: RETOUCHE collect all methods
75
);
76     }
77     
78     public MethodType.Kind getPrototypeMethodKind() {
79         return MethodType.Kind.HOME;
80     }
81
82     protected void generateMethod(EntityAndSession entityAndSession,
83                                   MethodModel method, boolean isOneReturn,
84                                   boolean publishToLocal,
85                                   boolean publishToRemote, String JavaDoc ejbql,
86                                   FileObject ejbClassFO, String JavaDoc className) throws IOException JavaDoc {
87         HomeMethodGenerator generator = HomeMethodGenerator.create(entityAndSession, ejbClassFO);
88         generator.generate(method, publishToLocal, publishToRemote);
89     }
90
91     public boolean supportsEjb(FileObject fileObject, String JavaDoc className) {
92         try {
93             EntityAndSession ejb = getEntityAndSession(fileObject, className);
94             if (ejb instanceof Entity) {
95                 return true;
96             }
97         } catch (IOException JavaDoc ioe) {
98             ErrorManager.getDefault().notify(ioe);
99         }
100         return false;
101     }
102 }
103
Popular Tags