KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > configbean > CmpEntityEjb


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.sun.share.configbean;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.List JavaDoc;
25
26 import javax.enterprise.deploy.model.DDBean JavaDoc;
27
28 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean;
29 import org.netbeans.modules.j2ee.sun.dd.api.ejb.Ejb;
30 import org.netbeans.modules.j2ee.sun.dd.api.ejb.FlushAtEndOfMethod;
31 import org.netbeans.modules.j2ee.sun.dd.api.ejb.Cmp;
32 import org.netbeans.modules.j2ee.sun.dd.api.ejb.Finder;
33 import org.netbeans.modules.j2ee.sun.dd.api.ejb.Method;
34 import org.netbeans.modules.j2ee.sun.dd.api.ejb.OneOneFinders;
35 import org.netbeans.modules.j2ee.sun.dd.api.ejb.PrefetchDisabled;
36 import org.netbeans.modules.j2ee.sun.dd.api.ejb.QueryMethod;
37
38 import org.netbeans.modules.j2ee.sun.share.configbean.ConfigQuery;
39
40
41 /**
42  *
43  * @author vkraemer
44  */

45 public class CmpEntityEjb extends EntityEjb {
46     
47     /** Holds value of property cmp. */
48     private Cmp cmp;
49
50     /** Holds value of property flush-at-end-of-method. */
51     private FlushAtEndOfMethod flushAtEndOfMethod;
52
53     /** Holds value of property schema. */
54     private String JavaDoc schema;
55     
56     /** Holds value of property tableName. */
57     private String JavaDoc tableName;
58     
59     /** Holds value of property consistency. */
60     private String JavaDoc consistency;
61     
62     /** Holds value of property secondaryTables. */
63
64     /** Holds value of property beanName. */
65     //private String beanName;
66

67     /** Creates a new instance of CmpEntityEjb */
68     public CmpEntityEjb() {
69     }
70     
71     /** Getter for property schema.
72      * @return Value of property schema.
73      *
74      */

75     public String JavaDoc getSchema() {
76         return this.schema;
77     }
78     
79     /** Setter for property schema.
80      * @param schema New value of property schema.
81      *
82      * @throws PropertyVetoException
83      *
84      */

85     public void setSchema(String JavaDoc schema) throws java.beans.PropertyVetoException JavaDoc {
86         String JavaDoc oldSchema = this.schema;
87         getVCS().fireVetoableChange("schema", oldSchema, schema);
88         this.schema = schema;
89         getPCS().firePropertyChange("schema", oldSchema, schema);
90     }
91     
92     /** Getter for property tableName.
93      * @return Value of property tableName.
94      *
95      */

96     public String JavaDoc getTableName() {
97         return this.tableName;
98     }
99     
100     /** Setter for property tableName.
101      * @param tableName New value of property tableName.
102      *
103      * @throws PropertyVetoException
104      *
105      */

106     public void setTableName(String JavaDoc tableName) throws java.beans.PropertyVetoException JavaDoc {
107         String JavaDoc oldTableName = this.tableName;
108         getVCS().fireVetoableChange("tableName", oldTableName, tableName);
109         this.tableName = tableName;
110         getPCS().firePropertyChange("tableName", oldTableName, tableName);
111     }
112     
113     /** Getter for property consistency.
114      * @return Value of property consistency.
115      *
116      */

117     public String JavaDoc getConsistency() {
118         return this.consistency;
119     }
120     
121     /** Setter for property consistency.
122      * @param consistency New value of property consistency.
123      *
124      * @throws PropertyVetoException
125      *
126      */

127     public void setConsistency(String JavaDoc consistency) throws java.beans.PropertyVetoException JavaDoc {
128         String JavaDoc oldConsistency = this.consistency;
129         getVCS().fireVetoableChange("consistency", oldConsistency, consistency);
130         this.consistency = consistency;
131         getPCS().firePropertyChange("consistency", oldConsistency, consistency);
132     }
133
134     /** Getter for property beanName.
135      * @return Value of property beanName.
136      *
137      */

138     public String JavaDoc getBeanName() {
139         return cleanDDBeanText(getDDBean());
140     }
141     
142     /* ------------------------------------------------------------------------
143      * Persistence support. Loads DConfigBeans from previously saved Deployment
144      * plan file.
145      */

146     protected class CmpEntityEjbSnippet extends EntityEjb.EntityEjbSnippet {
147         public CommonDDBean getDDSnippet() {
148             Ejb ejb = (Ejb) super.getDDSnippet();
149             String JavaDoc version = getAppServerVersion().getEjbJarVersionAsString();
150
151             if(null != cmp){
152                 ejb.setCmp((Cmp) cmp.cloneVersion(version));
153             }
154
155             if(null != flushAtEndOfMethod){
156                 try{
157                     ejb.setFlushAtEndOfMethod((FlushAtEndOfMethod)flushAtEndOfMethod.cloneVersion(version));
158                 }catch(org.netbeans.modules.j2ee.sun.dd.api.VersionNotSupportedException e){
159                     //System.out.println("Not Supported Version"); //NOI18N
160
}
161             }
162
163             return ejb;
164         }
165
166         public boolean hasDDSnippet() {
167             if(super.hasDDSnippet()){
168                 return true;
169             }
170
171             if(null != cmp){
172                 return true;
173             }
174
175             if(null != flushAtEndOfMethod){
176                 return true;
177             }
178             return false;
179         }
180     }
181
182     java.util.Collection JavaDoc getSnippets() {
183         Collection JavaDoc snippets = new ArrayList JavaDoc();
184         snippets.add(new CmpEntityEjbSnippet());
185
186         // FIXME create snippet for sun-cmp-mappings.xml here as well.
187

188         return snippets;
189     }
190
191
192     protected void loadEjbProperties(Ejb savedEjb) {
193             super.loadEjbProperties(savedEjb);
194         Cmp cmp = savedEjb.getCmp();
195         if(null != cmp){
196             this.cmp = cmp;
197         }
198
199         FlushAtEndOfMethod flushAtEndOfMethod = null;
200         try{
201             flushAtEndOfMethod = savedEjb.getFlushAtEndOfMethod();
202         }catch(org.netbeans.modules.j2ee.sun.dd.api.VersionNotSupportedException e){
203             //System.out.println("Not Supported Version"); //NOI18N
204
}
205
206         if(null != flushAtEndOfMethod){
207             this.flushAtEndOfMethod = flushAtEndOfMethod;
208         }
209     }
210     
211     protected void clearProperties() {
212         super.clearProperties();
213         
214         cmp = null;
215         flushAtEndOfMethod = null;
216         schema = null;
217         tableName = null;
218         consistency = null;
219     }
220
221     
222     /** Getter for property cmp.
223      * @return Value of property cmp.
224      *
225      */

226     public Cmp getCmp() {
227         return this.cmp;
228     }
229
230
231         /** Getter for property flushAtEndOfMethod.
232      * @return Value of property flushAtEndOfMethod.
233      */

234     public FlushAtEndOfMethod getFlushAtEndOfMethod() {
235         return this.flushAtEndOfMethod;
236     }
237
238
239     /** Setter for property cmp.
240      * @param cmp New value of property cmp.
241      *
242      * @throws PropertyVetoException
243      *
244      */

245     public void setCmp(Cmp cmp) throws java.beans.PropertyVetoException JavaDoc {
246         Cmp oldCmp = this.cmp;
247         getVCS().fireVetoableChange("cmp", oldCmp, cmp);
248         this.cmp = cmp;
249         getPCS().firePropertyChange("cmp", oldCmp, cmp);
250     }
251
252         
253     /** Setter for property flushAtEndOfMethod.
254      * @param flushAtEndOfMethod New value of property flushAtEndOfMethod.
255      *
256      * @throws PropertyVetoException
257      */

258     public void setFlushAtEndOfMethod(FlushAtEndOfMethod flushAtEndOfMethod) throws java.beans.PropertyVetoException JavaDoc {
259         FlushAtEndOfMethod oldFlushAtEndOfMethod = this.flushAtEndOfMethod;
260         getVCS().fireVetoableChange("flushAtEndOfMethod", oldFlushAtEndOfMethod, flushAtEndOfMethod); //NOI18N
261
this.flushAtEndOfMethod = flushAtEndOfMethod;
262         getPCS().firePropertyChange("flush at end of method", oldFlushAtEndOfMethod, flushAtEndOfMethod); //NOI18N
263
}
264
265
266     //methods called by the customizer model
267
public void addFinder(Finder finder){
268         if(null == cmp){
269             cmp = getConfig().getStorageFactory().createCmp();
270         }
271         OneOneFinders oneOneFinders = cmp.getOneOneFinders();
272         if(null == oneOneFinders){
273             oneOneFinders = cmp.newOneOneFinders();
274             cmp.setOneOneFinders(oneOneFinders);
275         }
276         oneOneFinders.addFinder(finder);
277     }
278
279
280         public void addMethod(Method method){
281 /*
282             System.out.println("CmpEntityEjb addMethod ddMethod:" + method); //NOI18N
283             System.out.println("CmpEntityEjb addMethod name :" + method.getMethodName() ); //NOI18N
284             System.out.println("CmpEntityEjb addMethod interface :" + method.getMethodIntf() ); //NOI18N
285             System.out.println("CmpEntityEjb addMethod ejb name :" + method.getEjbName() ); //NOI18N
286             System.out.println("CmpEntityEjb addMethod params :" + method.getMethodParams() ); //NOI18N
287 */

288             if(null == flushAtEndOfMethod){
289                 flushAtEndOfMethod = getConfig().getStorageFactory().createFlushAtEndOfMethod();
290             }
291             flushAtEndOfMethod.addMethod(method);
292     }
293
294
295         public void addQueryMethod(QueryMethod queryMethod){
296             try{
297                 if(null == cmp){
298                     cmp = getConfig().getStorageFactory().createCmp();
299                 }
300
301                 PrefetchDisabled prefetchDisabled = cmp.getPrefetchDisabled();
302                 if(null == prefetchDisabled){
303                     prefetchDisabled = cmp.newPrefetchDisabled();
304                     cmp.setPrefetchDisabled(prefetchDisabled);
305                 }
306                 prefetchDisabled.addQueryMethod(queryMethod);
307             }catch(org.netbeans.modules.j2ee.sun.dd.api.VersionNotSupportedException ex){
308                 //System.out.println("Not Supported Version"); //NOI18N
309
}
310     }
311
312
313     public void removeFinder(Finder finder){
314         if(null != cmp){
315             OneOneFinders oneOneFinders = cmp.getOneOneFinders();
316             if(null != oneOneFinders){
317                 oneOneFinders.removeFinder(finder);
318             }
319                     try{
320                         if(oneOneFinders.sizeFinder() < 1){
321                             setCmp(null);
322                         }
323                     }catch(java.beans.PropertyVetoException JavaDoc ex){
324                     }
325         }
326     }
327
328
329     public void removeMethod(Method method){
330         if(null != flushAtEndOfMethod){
331                         flushAtEndOfMethod.removeMethod(method);
332         }
333     }
334
335
336     public void removeQueryMethod(QueryMethod queryMethod){
337             try{
338                 if(null != cmp){
339                     PrefetchDisabled prefetchDisabled = cmp.getPrefetchDisabled();
340                     if(null != prefetchDisabled){
341                         prefetchDisabled.removeQueryMethod(queryMethod);
342                     }
343                 }
344             }catch(org.netbeans.modules.j2ee.sun.dd.api.VersionNotSupportedException ex){
345                 //System.out.println("Not Supported Version"); //NOI18N
346
}
347     }
348
349
350         //List of all the finder methods of cmp bean
351
public List JavaDoc getFinderMethods(){
352             ArrayList JavaDoc methods = new ArrayList JavaDoc();
353             DDBean JavaDoc ddBean = getDDBean();
354
355             //xpath - ejb-jar/enterprise-beans/entity
356
DDBean JavaDoc[] childBeans = ddBean.getChildBean("./query"); //NOI18N
357
ConfigQuery.MethodData methodData = null;
358             DDBean JavaDoc queryMethods[];
359             DDBean JavaDoc queryMethod;
360             DDBean JavaDoc methodNameBean;
361             String JavaDoc methodName;
362             DDBean JavaDoc methodParams;
363             DDBean JavaDoc methodParam[];
364             for(int i=0; i<childBeans.length; i++){
365                 queryMethods = childBeans[i].getChildBean("./query-method"); //NOI18N
366
if(queryMethods.length > 0){
367                     queryMethod = queryMethods[0];
368                     methodNameBean = queryMethod.getChildBean("./method-name")[0]; //NOI18N
369
methodName = methodNameBean.getText();
370                     if((methodName != null) && (methodName.length() > 0)){
371                         methodParams = queryMethod.getChildBean("./method-params")[0]; //NOI18N
372
methodParam = methodParams.getChildBean("./method-param"); //NOI18N
373
ArrayList JavaDoc params = new ArrayList JavaDoc();
374                         if(methodParam != null){
375                            for(int j=0; j<methodParam.length; j++){
376                                params.add(methodParam[j].getText());
377                            }
378                         }
379                         methodData = new ConfigQuery.MethodData(methodName, params);
380                     }
381                 }
382                 methods.add((Object JavaDoc)methodData);
383             }
384             return methods;
385         }
386
387
388         //List of all the QueryMethod elements(elements from DD)
389
public List JavaDoc getPrefetchedMethods(){
390             List JavaDoc prefetchedMethodList = new ArrayList JavaDoc();
391
392             try{
393                 if(cmp != null){
394                     PrefetchDisabled prefetchDisabled = cmp.getPrefetchDisabled();
395                     if(prefetchDisabled != null){
396                         QueryMethod[] queryMethods = prefetchDisabled.getQueryMethod();
397                         if(queryMethods != null){
398                             for(int i=0; i<queryMethods.length; i++){
399                                 prefetchedMethodList.add(queryMethods[i]);
400                             }
401                         }
402                     }
403                 }
404             }catch(org.netbeans.modules.j2ee.sun.dd.api.VersionNotSupportedException ex){
405                 //System.out.println("Not Supported Version"); //NOI18N
406
}
407             return prefetchedMethodList;
408         }
409
410
411         public String JavaDoc getHelpId() {
412         return "AS_CFG_CmpEntityEjb"; //NOI18N
413
}
414 }
415
416
Popular Tags