KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.HashSet JavaDoc;
27 import java.util.Set JavaDoc;
28 import javax.lang.model.element.Modifier;
29 import org.netbeans.api.progress.ProgressHandle;
30 import org.netbeans.api.progress.ProgressHandleFactory;
31 import org.netbeans.modules.j2ee.common.method.MethodCustomizerFactory;
32 import org.netbeans.modules.j2ee.common.method.MethodCustomizer;
33 import org.netbeans.modules.j2ee.common.method.MethodModel;
34 import org.netbeans.modules.j2ee.dd.api.ejb.Entity;
35 import org.netbeans.modules.j2ee.ejbcore.action.SelectMethodGenerator;
36 import org.netbeans.modules.j2ee.ejbcore.api.methodcontroller.EjbMethodController;
37 import org.netbeans.modules.j2ee.ejbcore.api.methodcontroller.EntityMethodController;
38 import org.netbeans.modules.j2ee.ejbcore.api.methodcontroller.MethodType;
39 import org.openide.ErrorManager;
40 import org.openide.filesystems.FileObject;
41 import org.openide.util.NbBundle;
42
43 /**
44  * @author Pavel Buzek
45  */

46 public class AddSelectMethodStrategy extends AbstractAddMethodStrategy {
47     
48     public AddSelectMethodStrategy() {
49         super(NbBundle.getMessage(AddSelectMethodStrategy.class, "LBL_AddSelectMethodAction"));
50     }
51     
52     public AddSelectMethodStrategy(String JavaDoc name) {
53         super(name);
54     }
55     
56     @Override JavaDoc
57     public MethodModel getPrototypeMethod() {
58         Set JavaDoc<Modifier> modifiers = new HashSet JavaDoc<Modifier>();
59         modifiers.add(Modifier.PUBLIC);
60         modifiers.add(Modifier.ABSTRACT);
61         return MethodModel.create(
62                 "ejbSelectBy",
63                 "int",
64                 "",
65                 Collections.<MethodModel.Variable>emptyList(),
66                 Collections.singletonList("javax.ejb.FinderException"),
67                 modifiers
68                 );
69     }
70     
71     protected MethodCustomizer createDialog(FileObject fileObject, final MethodModel methodModel) throws IOException JavaDoc {
72         String JavaDoc className = _RetoucheUtil.getMainClassName(fileObject);
73         EjbMethodController ejbMethodController = EjbMethodController.createFromClass(fileObject, className);
74         String JavaDoc ejbql = null;
75         if (!ejbMethodController.hasJavaImplementation(methodModel)) {
76             ejbql = ejbMethodController.createDefaultQL(methodModel);
77         }
78         return MethodCustomizerFactory.selectMethod(
79                 getTitle(),
80                 methodModel,
81                 ejbql,
82                 Collections.<MethodModel>emptySet() //TODO: RETOUCHE collect all methods
83
);
84     }
85     
86     @SuppressWarnings JavaDoc("deprecation") //NOI18N
87
protected void okButtonPressed(final MethodCustomizer methodCustomizer, final MethodType methodType,
88             final FileObject fileObject, String JavaDoc classHandle) throws java.io.IOException JavaDoc {
89         ProgressHandle handle = ProgressHandleFactory.createHandle("Adding method");
90         try {
91             handle.start(100);
92             String JavaDoc className = _RetoucheUtil.getMainClassName(fileObject);
93             EjbMethodController ejbMethodController = EjbMethodController.createFromClass(fileObject, className);
94             MethodModel method = methodType.getMethodElement();
95             EntityMethodController entityMethodController = (EntityMethodController) ejbMethodController;
96             entityMethodController.addSelectMethod(method, methodCustomizer.getEjbQL(), getDDFile(fileObject));
97             handle.progress(99);
98         } finally {
99             handle.finish();
100         }
101     }
102     
103     public MethodType.Kind getPrototypeMethodKind() {
104         return MethodType.Kind.SELECT;
105     }
106
107     protected void generateMethod(EntityAndSession entityAndSession,
108                                   MethodModel method, boolean isOneReturn,
109                                   boolean publishToLocal,
110                                   boolean publishToRemote, String JavaDoc ejbql,
111                                   FileObject ejbClassFO, String JavaDoc className) throws IOException JavaDoc {
112         SelectMethodGenerator generator = SelectMethodGenerator.create((Entity) entityAndSession, ejbClassFO, getDDFile(ejbClassFO));
113         generator.generate(method, publishToLocal, publishToRemote, isOneReturn, ejbql);
114     }
115
116     public boolean supportsEjb(FileObject fileObject, String JavaDoc className) {
117         try {
118             EntityAndSession ejb = getEntityAndSession(fileObject, className);
119             if (ejb instanceof Entity) {
120                 Entity entity = (Entity) ejb;
121                 if (Entity.PERSISTENCE_TYPE_CONTAINER.equals(entity.getPersistenceType())) {
122                     return true;
123                 }
124             }
125         } catch (IOException JavaDoc ioe) {
126             ErrorManager.getDefault().notify(ioe);
127         }
128         return false;
129     }
130 }
131
Popular Tags