KickJava   Java API By Example, From Geeks To Geeks.

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


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.FinderMethodGenerator;
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  * @author Pavel Buzek
41  */

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