KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > configbean > customizers > ejbmodule > FlushAtEndOfMethodPanel


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  * FlushAtEndOfMethodPanel.java
21  *
22  * Created on February 5, 2005, 7:27 PM
23  */

24
25 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.ejbmodule;
26
27 import java.util.ArrayList JavaDoc;
28 import java.util.Hashtable JavaDoc;
29 import java.util.List JavaDoc;
30 import java.util.Map JavaDoc;
31 import java.util.ResourceBundle JavaDoc;
32
33 import javax.enterprise.deploy.model.DDBean JavaDoc;
34 import javax.swing.event.TableModelListener JavaDoc;
35
36 import org.netbeans.modules.j2ee.sun.dd.api.ejb.FlushAtEndOfMethod;
37 import org.netbeans.modules.j2ee.sun.dd.api.ejb.Method;
38 import org.netbeans.modules.j2ee.sun.share.configbean.CmpEntityEjb;
39 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.MultiMethodTableModel;
40 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.MultiMethodTablePanel;
41
42 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.ejbmodule.DummyMethod;
43
44
45 /**
46  *
47  * @author Rajeshwar Patil
48  */

49 public class FlushAtEndOfMethodPanel extends MultiMethodTablePanel{
50     
51     private CmpEntityEjb cmpEntityEjb;
52     private CmpEntityEjbCustomizer customizer;
53     private FlushAtEndOfMethodModel model;
54
55     public static final String JavaDoc HOME = "Home"; //NOI18N
56
public static final String JavaDoc REMOTE = "Remote"; //NOI18N
57
public static final String JavaDoc LOCAL = "Local"; //NOI18N
58
public static final String JavaDoc LOCAL_HOME = "LocalHome"; //NOI18N
59

60     static final ResourceBundle JavaDoc bundle =
61         ResourceBundle.getBundle(
62             "org.netbeans.modules.j2ee.sun.share.configbean.customizers.ejbmodule.Bundle"); // NOI18N
63

64     /** Creates a new instance of FlushAtEndOfMethodPanel */
65     public FlushAtEndOfMethodPanel(CmpEntityEjb cmpEntityEjb, CmpEntityEjbCustomizer customizer) {
66         this.cmpEntityEjb = cmpEntityEjb;
67         this.customizer = customizer;
68     }
69
70
71     protected MultiMethodTableModel getMultiMethodTableModel(){
72         Map JavaDoc selectionToMethodsMap = getSelectionToMethodsMap();
73         Map JavaDoc selectionToDDMethodsMap = getSelectionToDDMethodsMap();
74         model = new FlushAtEndOfMethodModel(cmpEntityEjb, selectionToMethodsMap, selectionToDDMethodsMap);
75         model.addTableModelListener((TableModelListener JavaDoc)customizer);
76         return model;
77     }
78
79
80     public void setData(CmpEntityEjb cmpEntityEjb){
81         this.cmpEntityEjb = cmpEntityEjb;
82         Map JavaDoc selectionToMethodsMap = getSelectionToMethodsMap();
83         Map JavaDoc selectionToDDMethodsMap = getSelectionToDDMethodsMap();
84         model.setData(cmpEntityEjb, selectionToMethodsMap, selectionToDDMethodsMap);
85         setData();
86     }
87
88
89     protected String JavaDoc getSelectionLabelText(){
90         return bundle.getString("LBL_Interface_1"); //NOI18N
91
}
92
93
94     protected String JavaDoc getSelectionLabelAcsblName(){
95         return bundle.getString("Interface_Acsbl_Name"); //NOI18N
96
}
97
98
99     protected String JavaDoc getSelectionLabelAcsblDesc(){
100         return bundle.getString("Interface_Acsbl_Desc"); //NOI18N
101
}
102
103
104     protected String JavaDoc getSelectionComboAcsblName(){
105         return bundle.getString("Interface_Acsbl_Name"); //NOI18N
106
}
107
108
109     protected String JavaDoc getSelectionComboAcsblDesc(){
110         return bundle.getString("Interface_Acsbl_Desc"); //NOI18N
111
}
112
113
114     protected String JavaDoc getTablePaneAcsblName(){
115         return bundle.getString("Method_Acsbl_Name"); //NOI18N
116
}
117
118
119     protected String JavaDoc getTablePaneAcsblDesc(){
120         return bundle.getString("Flush_Method_Acsbl_Desc"); //NOI18N
121
}
122
123
124     protected char getSelectionLabelMnemonic(){
125         return bundle.getString("MNC_Interface").charAt(0); //NOI18N
126
}
127
128
129     protected String JavaDoc getSelectionComboToolTip(){
130         return bundle.getString("Interface_Tool_Tip"); //NOI18N
131
}
132
133
134     protected String JavaDoc getTablePaneToolTip(){
135         return bundle.getString("Method_Tool_Tip"); //NOI18N
136
}
137
138
139     protected String JavaDoc getToolTip(int row, int col){
140         if(col == 0){
141             //ConfigQuery.MethodData method = (ConfigQuery.MethodData) model.getMethods().get(row); //revert later
142
DummyMethod method = (DummyMethod) model.getMethods().get(row);
143             if(method != null){
144                 //return method.getOperationName(); //XXX -- return the signature of method //revert later
145
return method.getName(); //XXX -- return the signature of method
146
}
147         }
148         return null;
149     }
150
151
152     protected String JavaDoc getToolTip(int col){
153         if(col == 0){
154             return bundle.getString("Flush_Method_Header_Tool_Tip"); //NOI18N
155
}
156         if(col == 1){
157             return bundle.getString("Flush_Header_Tool_Tip"); //NOI18N
158
}
159         if(col == 2){
160             return bundle.getString("Desc_Header_Tool_Tip"); //NOI18N
161
}
162         return null;
163     }
164
165
166     //Contruct a map of Interface Types to Methods
167
//Get the interface types from the standard DD amd
168
//construct this map by getting all the Methods in the Interfaces
169
private Map JavaDoc getSelectionToMethodsMap(){
170         //XXX -- you may need to change this; use api instead to query for supported interfaces
171
Hashtable JavaDoc selectionToMethodsMap = new Hashtable JavaDoc();
172         if(cmpEntityEjb != null){
173             DDBean JavaDoc ddBean = cmpEntityEjb.getDDBean();
174             //xpath - ejb-jar/enterprise-beans/entity
175
//System.out.println("xpath: " + ddBean.getXpath()); //NOI18N
176
//DDBeanRoot ddBeanRoot = getDDBean().getRoot();
177
DDBean JavaDoc[] childBeans = ddBean.getChildBean("./home"); //NOI18N
178
if(childBeans.length > 0){
179                 //System.out.println("xpath: " + childBeans[0].getXpath()); //NOI18N
180
//xpath - ejb-jar/enterprise-beans/entity/local
181
selectionToMethodsMap.put(HOME, getMethods(HOME));
182             }
183
184             childBeans = ddBean.getChildBean("./remote"); //NOI18N
185
if(childBeans.length > 0){
186                 //xpath - ejb-jar/enterprise-beans/entity/remote
187
//System.out.println("xpath: " + childBeans[0].getXpath()); //NOI18N
188
selectionToMethodsMap.put(REMOTE, getMethods(REMOTE));
189             }
190
191             childBeans = ddBean.getChildBean("./local-home"); //NOI18N
192
if(childBeans.length > 0){
193                 //System.out.println("xpath: " + childBeans[0].getXpath()); //NOI18N
194
selectionToMethodsMap.put(LOCAL_HOME, getMethods(LOCAL_HOME));
195             }
196
197             childBeans = ddBean.getChildBean("./local"); //NOI18N
198
if(childBeans.length > 0){
199                 //System.out.println("xpath: " + childBeans[0].getXpath()); //NOI18N
200
selectionToMethodsMap.put(LOCAL, getMethods(LOCAL));
201             }
202
203         }
204         return selectionToMethodsMap;
205     }
206
207
208     //Contruct a map of Interface Types to DD Method elements
209
//Get the Method elements from sun DD and contruct this map
210
private Map JavaDoc getSelectionToDDMethodsMap(){
211         Map JavaDoc selectionToDDMethodsMap = new Hashtable JavaDoc();
212         if(cmpEntityEjb != null){
213             FlushAtEndOfMethod flushAtEndOfMethod = cmpEntityEjb.getFlushAtEndOfMethod();
214             if(flushAtEndOfMethod != null){
215                 Method[] ddMethods = flushAtEndOfMethod.getMethod();
216                 if(ddMethods != null){
217                     ArrayList JavaDoc homeMethods = null;
218                     ArrayList JavaDoc remoteMethods = null;
219                     ArrayList JavaDoc localMethods = null;
220                     ArrayList JavaDoc localHomeMethods = null;
221
222                     for(int i=0; i<ddMethods.length; i++){
223                         String JavaDoc interfaceType = ddMethods[i].getMethodIntf();
224                         if(HOME.equals(interfaceType)){
225                             if(homeMethods == null){
226                                 homeMethods = new ArrayList JavaDoc();
227                             }
228                             homeMethods.add(ddMethods[i]);
229                         }
230
231                         if(REMOTE.equals(interfaceType)){
232                             if(remoteMethods == null){
233                                 remoteMethods = new ArrayList JavaDoc();
234                             }
235                             remoteMethods.add(ddMethods[i]);
236                         }
237
238                         if(LOCAL_HOME.equals(interfaceType)){
239                             if(localHomeMethods == null){
240                                 localHomeMethods = new ArrayList JavaDoc();
241                             }
242                             localHomeMethods.add(ddMethods[i]);
243                         }
244
245                         if(LOCAL.equals(interfaceType)){
246                             if(localMethods == null){
247                                 localMethods = new ArrayList JavaDoc();
248                             }
249                             localMethods.add(ddMethods[i]);
250                         }
251                     }
252
253                     if(homeMethods != null){
254                         selectionToDDMethodsMap.put(HOME, homeMethods);
255                     }
256                     if(remoteMethods != null){
257                         selectionToDDMethodsMap.put(REMOTE, remoteMethods);
258                     }
259                     if(localHomeMethods != null){
260                         selectionToDDMethodsMap.put(LOCAL_HOME, localHomeMethods);
261                     }
262                     if(localMethods != null){
263                         selectionToDDMethodsMap.put(LOCAL, localMethods);
264                     }
265                 }
266             }
267         }
268         return selectionToDDMethodsMap;
269     }
270
271
272     //get all the mehods in the given interface
273
private List JavaDoc getMethods(String JavaDoc interfaceType){
274         if(interfaceType.equals(LOCAL_HOME)){
275             //XXX dummy impementation; replace by real one
276
//returning a list of java.lang.reflect.Method objects
277
//change later to return a list of real *Method* objects.
278
//*Method* objects could be netbeans Method object
279
ArrayList JavaDoc methods = new ArrayList JavaDoc();
280             DummyMethod method = new DummyMethod();
281             method.setName("FirstMethod");
282             String JavaDoc[] params = {"int"};
283             method.setParameterTypes(params);
284             methods.add(method);
285
286             DummyMethod method2 = new DummyMethod();
287             method2.setName("SecondMethod");
288             String JavaDoc[] params2 = {"int", "String"};
289             method2.setParameterTypes(params2);
290             methods.add(method2);
291             return methods;
292         }else{
293             ArrayList JavaDoc methods = new ArrayList JavaDoc();
294             DummyMethod method = new DummyMethod();
295             method.setName("FirstMethod");
296             String JavaDoc[] params = {"String"};
297             method.setParameterTypes(params);
298             methods.add(method);
299             return methods;
300         }
301     }
302     
303     public void addTableModelListener(TableModelListener JavaDoc listner){
304         model.addTableModelListener(listner);
305     }
306 }
307
Popular Tags