KickJava   Java API By Example, From Geeks To Geeks.

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


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  * PrefetchDisabledModel.java
21  *
22  * Created on February 23, 2005, 11:46 PM
23  */

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

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

48     private CmpEntityEjb cmpEntityEjb;
49
50     private static final String JavaDoc[] columnNames = {
51         bundle.getString("LBL_Method"), //NOI18N
52
bundle.getString("LBL_Disable"), //NOI18N
53
};
54
55
56     /** Creates a new instance of PrefetchDisabledModel */
57     public PrefetchDisabledModel(CmpEntityEjb cmpEntityEjb, List JavaDoc methodList,
58             List JavaDoc prefetchedMethodList) {
59         super(methodList, prefetchedMethodList);
60         this.cmpEntityEjb = cmpEntityEjb;
61     }
62
63
64     public void setData(CmpEntityEjb cmpEntityEjb, List JavaDoc methodList,
65             List JavaDoc prefetchedMethodList){
66         this.cmpEntityEjb = cmpEntityEjb;
67         setData(methodList, prefetchedMethodList);
68     }
69
70
71     public PrefetchDisabledModel() {
72     }
73
74
75     protected String JavaDoc[] getColumnNames(){
76         return columnNames;
77     }
78
79
80     protected Class JavaDoc getColumnType(int column){
81         return Object JavaDoc.class;
82     }
83
84
85     protected Object JavaDoc getValueAt(int column, Object JavaDoc object, int row){
86         if(column == 0){
87             ConfigQuery.MethodData method = (ConfigQuery.MethodData) object;
88             return method.getOperationName( );
89         } else {
90             //Control should never reach here.
91
assert(false);
92             return null;
93         }
94     }
95
96
97     protected Object JavaDoc getDDValueAt(int column, Object JavaDoc ddObject){
98         QueryMethod queryMethod = (QueryMethod) ddObject;
99         switch(column){
100             default: {
101                 //Control should never reach here.
102
assert(false);
103                 return null;
104             }
105         }
106     }
107
108
109     protected void setDDValueAt(int column, Object JavaDoc ddObject, Object JavaDoc value){
110         QueryMethod queryMethod = (QueryMethod) ddObject;
111         switch(column){
112             default: {
113                 //Control should never reach here.
114
assert(false);
115             }
116         }
117     }
118
119
120     //convert the given Method object into the schama2beans DD (Method) object
121
protected Object JavaDoc getDDMethod(Object JavaDoc object){
122         StorageBeanFactory storageFactory = cmpEntityEjb.getConfig().getStorageFactory();
123         
124         ConfigQuery.MethodData method = (ConfigQuery.MethodData) object;
125         QueryMethod queryMethod = storageFactory.createQueryMethod();
126
127         queryMethod.setMethodName(method.getOperationName());
128         List JavaDoc params = method.getParameters();
129         MethodParams methodParams = queryMethod.newMethodParams();
130         for(int i=0; i<params.size(); i++){
131             methodParams.addMethodParam((String JavaDoc)params.get(i));
132         }
133         queryMethod.setMethodParams(methodParams);
134
135         //printMethod(queryMethod);
136
return queryMethod;
137     }
138
139
140     protected void addDDMethod(Object JavaDoc ddObject){
141         QueryMethod ddMethod = (QueryMethod)ddObject;
142         //printMethod(ddMethod);
143
cmpEntityEjb.addQueryMethod(ddMethod);
144     }
145
146
147     protected void removeDDMethod(Object JavaDoc ddObject){
148         QueryMethod ddMethod = (QueryMethod)ddObject;
149         cmpEntityEjb.removeQueryMethod(ddMethod);
150     }
151
152
153     //determine whether the given schema2bean DD (Method) object is equal to
154
//the given Method object
155
protected boolean areEqual(Object JavaDoc ddObject, Object JavaDoc object){
156         QueryMethod ddMethod = (QueryMethod)ddObject;
157         ConfigQuery.MethodData method = (ConfigQuery.MethodData) object;
158         boolean returnValue = false;
159
160
161         String JavaDoc ddMethodName = ddMethod.getMethodName();
162         String JavaDoc methodName = method.getOperationName();
163         if(ddMethodName.equals(methodName)){
164             //check for parameters
165
MethodParams methodParams = ddMethod.getMethodParams();
166             List JavaDoc params = method.getParameters();
167
168             String JavaDoc ddParam;
169             String JavaDoc param;
170             for(int i=0; i<params.size(); i++){
171                 param = (String JavaDoc)params.get(i);
172                 ddParam = methodParams.getMethodParam(i);
173                 if(!param.equals(ddParam)){
174                     return false;
175                 }
176             }
177             return true;
178         } else {
179             return false;
180         }
181     }
182
183
184     private void printMethod(QueryMethod queryMethod){
185         System.out.println("PrefetchDisabledModel queryMethod:" + queryMethod); //NOI18N
186
System.out.println("PrefetchDisabledModel queryMethod:" + queryMethod.toString()); //NOI18N
187
System.out.println("PrefetchDisabledModel name :" + queryMethod.getMethodName() ); //NOI18N
188
System.out.println("PrefetchDisabledModel params :" + queryMethod.getMethodParams() ); //NOI18N
189
}
190 }
191
Popular Tags