KickJava   Java API By Example, From Geeks To Geeks.

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


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  * FlushAtEndOfMethodModel.java
21  *
22  * Created on February 4, 2005, 12:26 AM
23  */

24
25 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.ejbmodule;
26
27 import java.util.Map JavaDoc;
28 import java.util.ResourceBundle JavaDoc;
29
30 import org.netbeans.modules.j2ee.sun.dd.api.ejb.Method;
31 import org.netbeans.modules.j2ee.sun.dd.api.common.MethodParams;
32 import org.netbeans.modules.j2ee.sun.share.configbean.CmpEntityEjb;
33 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.MultiMethodTableModel;
34 import org.netbeans.modules.j2ee.sun.share.configbean.StorageBeanFactory;
35
36 /**
37  *
38  * @author Rajeshwar Patil
39  */

40 public class FlushAtEndOfMethodModel extends MultiMethodTableModel{
41
42     static final ResourceBundle JavaDoc bundle =
43         ResourceBundle.getBundle(
44             "org.netbeans.modules.j2ee.sun.share.configbean.customizers.ejbmodule.Bundle"); //NOI18N
45

46     private CmpEntityEjb cmpEntityEjb;
47
48     private static final String JavaDoc[] columnNames = {
49         bundle.getString("LBL_Method"), //NOI18N
50
bundle.getString("LBL_Flush"), //NOI18N
51
bundle.getString("LBL_Description") //NOI18N
52
};
53
54
55     /** Creates a new instance of FlushAtEndOfMethodModel */
56     public FlushAtEndOfMethodModel(CmpEntityEjb cmpEntityEjb, Map JavaDoc selectionToMethodsMap, Map JavaDoc selectionToDDMethodsMap) {
57         super(selectionToMethodsMap, selectionToDDMethodsMap);
58         this.cmpEntityEjb = cmpEntityEjb;
59     }
60
61
62     public void setData(CmpEntityEjb cmpEntityEjb, Map JavaDoc selectionToMethodsMap, Map JavaDoc selectionToDDMethodsMap){
63         this.cmpEntityEjb = cmpEntityEjb;
64         setData(selectionToMethodsMap, selectionToDDMethodsMap);
65     }
66
67
68     public FlushAtEndOfMethodModel() {
69     }
70
71
72     protected String JavaDoc[] getColumnNames(){
73         return columnNames;
74     }
75
76
77     protected Class JavaDoc getColumnType(int column){
78         if(column == 2){
79             return String JavaDoc.class;
80         }else{
81             //Control should never reach here.
82
assert(false);
83         }
84         return Object JavaDoc.class;
85     }
86
87     ///revert later(post Netbeans 4.1); since method is a mockup object and
88
//does not have unique method name available to display, using row number instead
89
/*
90     protected Object getValueAt(int column, Object object){
91         if(column == 0){
92             //XXX implemented for DummyMethod replace with real *Method*
93             //System.out.println("FlushAtEndOfMethodModel getValueAt return value :" + object.toString() );
94             DummyMethod method = (DummyMethod) object;
95             return method.toString( );
96         } else {
97             //Control should never reach here.
98             //System.out.println("FlushAtEndOfMethodModel getValueAt return value null :" );
99             assert(false);
100             return null;
101         }
102     }
103    */

104     protected Object JavaDoc getValueAt(int column, Object JavaDoc object, int row){
105         if(column == 0){
106             //XXX implemented for DummyMethod replace with real *Method*
107
//System.out.println("FlushAtEndOfMethodModel getValueAt return value :" + object.toString() );
108
DummyMethod method = (DummyMethod) object;
109             return "Method" + row;
110         } else {
111             //Control should never reach here.
112
//System.out.println("FlushAtEndOfMethodModel getValueAt return value null :" );
113
assert(false);
114             return null;
115         }
116     }
117
118
119     protected Object JavaDoc getDDValueAt(int column, Object JavaDoc ddObject){
120         if(column == 2){
121             Method ddMethod = (Method) ddObject;
122             return ddMethod.getDescription( );
123         } else {
124             //Control should never reach here.
125
assert(false);
126             return null;
127         }
128     }
129
130
131     protected void setDDValueAt(int column, Object JavaDoc ddObject, Object JavaDoc value){
132         if(column == 2){
133             Method ddMethod = (Method) ddObject;
134             ddMethod.setDescription((String JavaDoc)value);
135         } else {
136             //Control should never reach here.
137
assert(false);
138         }
139     }
140
141
142     //convert the given Method object into the schama2beans DD (Method) object
143
protected Object JavaDoc getDDMethod(Object JavaDoc object, String JavaDoc selection){
144         StorageBeanFactory storageFactory = cmpEntityEjb.getConfig().getStorageFactory();
145         //System.out.println("FlushAtEndOfMethodModel getDDMethod");
146
//System.out.println("FlushAtEndOfMethodModel getDDMethod method :" + object );
147
//System.out.println("FlushAtEndOfMethodModel getDDMethod selection :" + selection );
148
//XXX implemented for DummyMethod replace with real *Method*
149
DummyMethod method = (DummyMethod)object;
150         //Method ddMethod = new Method();
151
Method ddMethod = storageFactory.createMethod();
152         //ddMethod.setDescription(method.toString());
153
ddMethod.setMethodName(method.getName());
154         ddMethod.setMethodIntf(selection);
155         ddMethod.setEjbName(cmpEntityEjb.getEjbName());
156
157         String JavaDoc[] params = method.getParameterTypes();
158         //MethodParams ddParams = new MethodParams();
159
MethodParams ddParams = storageFactory.createMethodParams();
160         for(int i=0; i<params.length; i++){
161             ddParams.addMethodParam(params[i]);
162         }
163
164         ddMethod.setMethodParams(ddParams);
165         
166         //System.out.println("FlushAtEndOfMethodModel getDDMethod ddMethod:" + ddMethod);
167
//System.out.println("FlushAtEndOfMethodModel getDDMethod name :" + ddMethod.getMethodName() );
168
//System.out.println("FlushAtEndOfMethodModel getDDMethod interface :" + ddMethod.getMethodIntf() );
169
//System.out.println("FlushAtEndOfMethodModel getDDMethod ejb name :" + ddMethod.getEjbName() );
170
//System.out.println("FlushAtEndOfMethodModel getDDMethod params :" + ddMethod.getMethodParams() );
171

172         return ddMethod;
173     }
174
175
176     protected void addDDMethod(Object JavaDoc ddObject){
177         Method ddMethod = (Method)ddObject;
178         //printMethod(ddMethod);
179
cmpEntityEjb.addMethod(ddMethod);
180     }
181
182
183     protected void removeDDMethod(Object JavaDoc ddObject){
184         Method ddMethod = (Method)ddObject;
185         cmpEntityEjb.removeMethod(ddMethod);
186     }
187
188
189     //determine whether the given schema2bean DD (Method) object is equal to
190
//the given Method object
191
protected boolean areEqual(Object JavaDoc ddObject, Object JavaDoc object){
192         //XXX implemented for DummyMethod replace with real *Method*
193
Method ddMethod = (Method)ddObject;
194         DummyMethod method = (DummyMethod) object;
195         boolean returnValue = false;
196
197
198         String JavaDoc ddMethodName = ddMethod.getMethodName();
199         //System.out.println("FlushAtEndOfMethodModel areEqual ddMethodName " + ddMethodName);
200
String JavaDoc methodName = method.getName();
201         //System.out.println("FlushAtEndOfMethodModel areEqual methodName " + methodName);
202
if(ddMethodName.equals(methodName)){
203             //check for parameters
204
MethodParams methodParams = ddMethod.getMethodParams();
205             String JavaDoc[] params = method.getParameterTypes();
206
207             String JavaDoc ddParam;
208             String JavaDoc param;
209             for(int i=0; i<params.length; i++){
210                 param = params[i];
211                 ddParam = methodParams.getMethodParam(i);
212                 //System.out.println("FlushAtEndOfMethodModel areEqual param " + param);
213
//System.out.println("FlushAtEndOfMethodModel areEqual ddParam " + ddParam);
214
if(!param.equals(ddParam)){
215                     return false;
216                 }
217             }
218             return true;
219         } else {
220             return false;
221         }
222     }
223
224
225     private void printMethod(Method ddMethod){
226         System.out.println("FlushAtEndOfMethodModel ddMethod:" + ddMethod); //NOI18N
227
System.out.println("FlushAtEndOfMethodModel ddMethod:" + ddMethod.toString()); //NOI18N
228
System.out.println("FlushAtEndOfMethodModel name :" + ddMethod.getMethodName() ); //NOI18N
229
System.out.println("FlushAtEndOfMethodModel interface :" + ddMethod.getMethodIntf() ); //NOI18N
230
System.out.println("FlushAtEndOfMethodModel ejb name :" + ddMethod.getEjbName() ); //NOI18N
231
System.out.println("FlushAtEndOfMethodModel params :" + ddMethod.getMethodParams() ); //NOI18N
232
}
233 }
234
Popular Tags