KickJava   Java API By Example, From Geeks To Geeks.

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


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  * MDEjbCustomizer.java October 27, 2003, 1:05 PM
21  *
22  */

23
24 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.ejbmodule;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.Collection JavaDoc;
28
29 import javax.swing.event.TableModelListener JavaDoc;
30
31 //DEPLOYMENT API
32
import javax.enterprise.deploy.spi.DConfigBean JavaDoc;
33
34 import org.netbeans.modules.j2ee.sun.dd.api.common.DefaultResourcePrincipal;
35 import org.netbeans.modules.j2ee.sun.dd.api.ejb.ActivationConfig;
36 import org.netbeans.modules.j2ee.sun.dd.api.ejb.ActivationConfigProperty;
37 import org.netbeans.modules.j2ee.sun.dd.api.ejb.BeanPool;
38 import org.netbeans.modules.j2ee.sun.dd.api.ejb.MdbConnectionFactory;
39 import org.netbeans.modules.j2ee.sun.dd.api.ejb.MdbResourceAdapter;
40 import org.netbeans.modules.j2ee.sun.share.configbean.BaseEjb;
41 import org.netbeans.modules.j2ee.sun.share.configbean.MDEjb;
42 import org.netbeans.modules.j2ee.sun.share.configbean.StorageBeanFactory;
43
44
45 /**
46  *
47  * @author Rajeshwar Patil
48  * @version %I%, %G%
49  */

50 public class MDEjbCustomizer extends EjbCustomizer
51             implements TableModelListener JavaDoc {
52
53     private MDEjb theBean;
54     private MDEjbPanel mdEjbPanel;
55     private BeanPoolPanel beanPoolPanel;
56     private ActivationCfgPropertyPanel actvnCfgPrptyPanel;
57     private MdbConnectionFactoryPanel mdbConnectionFactoryPanel;
58     
59
60     /** Creates a new instance of MDEjbCustomizer */
61     public MDEjbCustomizer() {
62     }
63     
64
65     public void setObject(Object JavaDoc bean) {
66         super.setObject(bean);
67         
68         // Only do this if the bean is actually changing.
69
if(theBean != bean) {
70             if(bean instanceof MDEjb) {
71                 theBean = (MDEjb) bean;
72             }
73         }
74     }
75
76
77     //get the bean specific panel
78
protected javax.swing.JPanel JavaDoc getBeanPanel(){
79         mdEjbPanel = new MDEjbPanel(this);
80         return mdEjbPanel;
81     }
82
83
84     //initialize all the elements in the bean specific panel
85
protected void initializeBeanPanel(BaseEjb theBean){
86         if(!(theBean instanceof MDEjb)){
87             assert(false);
88         }
89
90         MDEjb mdEjb = (MDEjb)theBean;
91         String JavaDoc jmsDurableSubscriptionName = mdEjb.getSubscriptionName();
92         mdEjbPanel.setJmsDurableSubscriptionName(jmsDurableSubscriptionName);
93
94         String JavaDoc maxMessagesLoad = mdEjb.getMaxMessageLoad();
95         mdEjbPanel.setMaxMessagesLoad(maxMessagesLoad);
96
97         MdbResourceAdapter mdbResourceAdapter = mdEjb.getMdbResourceAdapter();
98         if(mdbResourceAdapter != null){
99             String JavaDoc resourceAdapterMid =
100                 mdbResourceAdapter.getResourceAdapterMid();
101             mdEjbPanel.setResourceAdapterMid(resourceAdapterMid);
102             
103             ActivationConfig activationCfg =
104                 mdbResourceAdapter.getActivationConfig();
105             if(activationCfg != null){
106                 String JavaDoc description = activationCfg.getDescription();
107                 mdEjbPanel.setActivationConfigDescription(description);
108             }
109         }
110     }
111
112
113     protected void addTabbedBeanPanels() {
114         beanPoolPanel = new BeanPoolPanel(this);
115         tabbedPanel.insertTab(bundle.getString("LBL_BeanPool"), null, beanPoolPanel, null, 0); // NOI18N
116

117         mdbConnectionFactoryPanel = new MdbConnectionFactoryPanel(this);
118         mdbConnectionFactoryPanel.getAccessibleContext().setAccessibleName(bundle.getString("Mdb_Connection_Factory_Acsbl_Name")); //NOI18N
119
mdbConnectionFactoryPanel.getAccessibleContext().setAccessibleDescription(bundle.getString("Mdb_Connection_Factory_Acsbl_Desc")); //NOI18N
120
tabbedPanel.addTab(bundle.getString("LBL_Mdb_Connection_Factory"), // NOI18N
121
mdbConnectionFactoryPanel);
122
123         ActivationCfgPropertyModel activnCfgPrptyModel =
124             new ActivationCfgPropertyModel();
125         activnCfgPrptyModel.addTableModelListener(this);
126         actvnCfgPrptyPanel =
127             new ActivationCfgPropertyPanel(activnCfgPrptyModel);
128         actvnCfgPrptyPanel.getAccessibleContext().setAccessibleName(bundle.getString("Activation_Config_Property_Acsbl_Name")); //NOI18N
129
actvnCfgPrptyPanel.getAccessibleContext().setAccessibleDescription(bundle.getString("Activation_Config_Property_Acsbl_Desc")); //NOI18N
130
tabbedPanel.addTab(bundle.getString("LBL_Activation_Config_Property"), // NOI18N
131
actvnCfgPrptyPanel);
132
133         //Select Bean Pool Panel
134
tabbedPanel.setSelectedIndex(tabbedPanel.indexOfTab(bundle.getString("LBL_BeanPool"))); //NOI18N
135
}
136
137
138     protected void initializeTabbedBeanPanels(BaseEjb theBean) {
139         if(!(theBean instanceof MDEjb)){
140             assert(false);
141         }
142
143         MDEjb mdEjb = (MDEjb)theBean;
144         BeanPool beanPool = mdEjb.getBeanPool();
145         beanPoolPanel.setValues(beanPool);
146
147         MdbConnectionFactory mdbConnectionFactory =
148             mdEjb.getMdbConnectionFactory();
149         mdbConnectionFactoryPanel.setValues(mdbConnectionFactory);
150
151         MdbResourceAdapter mdbResourceAdapter = mdEjb.getMdbResourceAdapter();
152         if(mdbResourceAdapter == null){
153             actvnCfgPrptyPanel.setModel(mdEjb,null);
154         }else{
155             ActivationConfig activationCfg =
156                 mdbResourceAdapter.getActivationConfig();
157             if(activationCfg == null){
158                 actvnCfgPrptyPanel.setModel(mdEjb,null);
159             }else{
160                 ActivationConfigProperty[] activationCfgProperty =
161                     activationCfg.getActivationConfigProperty();
162                 actvnCfgPrptyPanel.setModel(mdEjb,activationCfgProperty);
163             }
164         }
165     }
166
167
168     public Collection JavaDoc getErrors(){
169         ArrayList JavaDoc errors = null;
170         if(validationSupport == null) assert(false);
171         errors = (ArrayList JavaDoc)super.getErrors();
172
173         //Message Driven Ejb field Validations
174
String JavaDoc property = mdEjbPanel.getJmsDurableSubscriptionName();
175         errors.addAll(validationSupport.validate(property,
176             "/sun-ejb-jar/enterprise-beans/ejb/jms-durable-subscription-name", //NOI18N
177
bundle.getString("LBL_Jms_Durable_Subscription_Name")));//NOI18N
178

179         property = mdEjbPanel.getMaxMessagesLoad();
180         errors.addAll(validationSupport.validate(property,
181             "/sun-ejb-jar/enterprise-beans/ejb/jms-max-messages-load", //NOI18N
182
bundle.getString("LBL_Jms_Max_Messages_Load"))); //NOI18N
183

184         boolean isResourceAdapterPresent = isResourceAdapterPresent();
185         if(isResourceAdapterPresent){
186             property = mdEjbPanel.getResourceAdapterMid();
187             errors.addAll(validationSupport.validate(property,
188                 "/sun-ejb-jar/enterprise-beans/ejb/mdb-resource-adapter/resource-adapter-mid", //NOI18N
189
bundle.getString("LBL_Resource_Adapter_Mid"))); //NOI18N
190

191             property = mdEjbPanel.getActivationConfigDescription();
192             errors.addAll(validationSupport.validate(property,
193                 "/sun-ejb-jar/enterprise-beans/ejb/mdb-resource-adapter/activation-config/description", //NOI18N
194
bundle.getString("LBL_Activation_Config_Description")));//NOI18N
195
}
196             
197         return errors;
198     }
199
200
201     public void validateEntries(){
202         super.validateEntries();
203     }
204
205
206     public String JavaDoc getHelpId() {
207         return "AS_CFG_MDEjb"; //NOI18N
208
}
209
210     //MD Ejb update methods
211
void updateJmsDurableSubscriptionName(String JavaDoc jmsDurblSubsName){
212         try{
213             if(EMPTY_STRING.equals(jmsDurblSubsName)){
214                 theBean.setSubscriptionName(null);
215             }else{
216                 theBean.setSubscriptionName(jmsDurblSubsName);
217             }
218         }catch(java.beans.PropertyVetoException JavaDoc exception){
219         }
220         notifyChange();
221     }
222
223
224     void updateJmsMaxMessagesLoad(String JavaDoc maxMessagesLoad){
225         try{
226             if(EMPTY_STRING.equals(maxMessagesLoad)){
227                 theBean.setMaxMessageLoad(null);
228             }else{
229                 theBean.setMaxMessageLoad(maxMessagesLoad);
230             }
231         }catch(java.beans.PropertyVetoException JavaDoc exception){
232         }
233         notifyChange();
234     }
235
236
237     void updateMdbConnectionFactoryJndiName(String JavaDoc jndiName){
238         MdbConnectionFactory mddbConnectionFactory
239             = getMdbConnectionFactory();
240
241         if((EMPTY_STRING.equals(jndiName)) || (null == jndiName)){
242             mddbConnectionFactory.setJndiName(null);
243             updateMdbConnectionFactory();
244         }else{
245             mddbConnectionFactory.setJndiName(jndiName);
246         }
247         notifyChange();
248     }
249
250
251     void updateDefaultResourcePrincipalName(String JavaDoc principalName){
252         DefaultResourcePrincipal defaultResourcePrincipal =
253             getDefaultResourcePrincipal();
254
255         if((EMPTY_STRING.equals(principalName)) || (null == principalName)){
256             defaultResourcePrincipal.setName(null);
257             updateDefaultResourcePrincipal();
258         }else{
259             defaultResourcePrincipal.setName(principalName);
260         }
261
262         notifyChange();
263     }
264
265
266     void updateDefaultResourcePrincipalPassword(String JavaDoc principalPassword){
267         DefaultResourcePrincipal defaultResourcePrincipal =
268             getDefaultResourcePrincipal();
269
270         if((EMPTY_STRING.equals(principalPassword)) || (null == principalPassword)){
271             defaultResourcePrincipal.setPassword(null);
272             updateDefaultResourcePrincipal();
273         }else{
274             defaultResourcePrincipal.setPassword(principalPassword);
275         }
276
277         notifyChange();
278     }
279
280
281     void updateResourceAdapterMid(String JavaDoc mid){
282         MdbResourceAdapter mdbResourceAdapter =
283             getMdbResourceAdapter();
284
285         if((EMPTY_STRING.equals(mid)) || (null == mid)){
286             mdbResourceAdapter.setResourceAdapterMid(null);
287             updateResourceAdapter();
288         }else{
289             mdbResourceAdapter.setResourceAdapterMid(mid);
290         }
291
292         notifyChange();
293     }
294
295
296     void updateActivationConfigDescription(String JavaDoc description){
297         ActivationConfig activationConfig = getActivationConfig();
298
299         if((EMPTY_STRING.equals(description)) || (null == description)){
300             activationConfig.setDescription(null);
301             updateActivationConfig();
302         }else{
303             activationConfig.setDescription(description);
304         }
305
306         notifyChange();
307     }
308
309
310     private MdbConnectionFactory getMdbConnectionFactory(){
311         MdbConnectionFactory mdbConnectionFactory =
312             theBean.getMdbConnectionFactory();
313         if(mdbConnectionFactory == null){
314             mdbConnectionFactory = theBean.getConfig().getStorageFactory().createMdbConnectionFactory();
315             try{
316                 theBean.setMdbConnectionFactory(mdbConnectionFactory);
317             }catch(java.beans.PropertyVetoException JavaDoc exception){
318             }
319         }
320         return mdbConnectionFactory;
321     }
322
323
324     private DefaultResourcePrincipal getDefaultResourcePrincipal(){
325         MdbConnectionFactory mdbConnectionFactory =
326             getMdbConnectionFactory();
327         DefaultResourcePrincipal defaultResourcePrincipal =
328             mdbConnectionFactory.getDefaultResourcePrincipal();
329         if(defaultResourcePrincipal == null){
330             defaultResourcePrincipal = theBean.getConfig().getStorageFactory().createDefaultResourcePrincipal();
331             mdbConnectionFactory.setDefaultResourcePrincipal(
332                defaultResourcePrincipal);
333         }
334         return defaultResourcePrincipal;
335     }
336
337
338     private MdbResourceAdapter getMdbResourceAdapter(){
339         MdbResourceAdapter mdbResourceAdapter =
340             theBean.getMdbResourceAdapter();
341         if(mdbResourceAdapter == null){
342             mdbResourceAdapter = theBean.getConfig().getStorageFactory().createMdbResourceAdapter();
343             try{
344                 theBean.setMdbResourceAdapter(mdbResourceAdapter);
345             }catch(java.beans.PropertyVetoException JavaDoc exception){
346             }
347         }
348         return mdbResourceAdapter;
349     }
350
351
352     private ActivationConfig getActivationConfig(){
353         MdbResourceAdapter mdbResourceAdapter =
354             getMdbResourceAdapter();
355         ActivationConfig activationConfig =
356             mdbResourceAdapter.getActivationConfig();
357         if(activationConfig == null){
358             activationConfig = theBean.getConfig().getStorageFactory().createActivationConfig();
359             mdbResourceAdapter.setActivationConfig(
360                activationConfig);
361         }
362         return activationConfig;
363     }
364
365
366     private boolean isResourceAdapterPresent(){
367         boolean resourceAdapterPresent = false;
368         String JavaDoc property = mdEjbPanel.getResourceAdapterMid();
369         while(true){
370             if((property != null) && (property.length() != 0)){
371                 resourceAdapterPresent = true;
372                 break;
373             }
374
375             property = mdEjbPanel.getActivationConfigDescription();
376             if((property != null) && (property.length() != 0)){
377                 resourceAdapterPresent = true;
378                 break;
379             }
380             break;
381         }
382         return resourceAdapterPresent;
383     }
384
385
386     private void updateDefaultResourcePrincipal(){
387         DefaultResourcePrincipal defaultResourcePrincipal =
388             getDefaultResourcePrincipal();
389         
390         if(defaultResourcePrincipal.getName() != null) return;
391         if(defaultResourcePrincipal.getPassword() != null) return;
392         getMdbConnectionFactory().setDefaultResourcePrincipal(null);
393         updateMdbConnectionFactory();
394     }
395
396
397     private void updateMdbConnectionFactory(){
398         MdbConnectionFactory mddbConnectionFactory
399             = getMdbConnectionFactory();
400
401         if(mddbConnectionFactory.getJndiName() != null) return;
402         if(mddbConnectionFactory.getDefaultResourcePrincipal() != null) return;
403         try{
404             theBean.setMdbConnectionFactory(null);
405         }catch(java.beans.PropertyVetoException JavaDoc exception){
406         }
407     }
408
409
410     private void updateActivationConfig(){
411         ActivationConfig activationConfig = getActivationConfig();
412
413         if(activationConfig.getDescription() != null) return;
414         if((activationConfig.getActivationConfigProperty() != null) &&
415                 (activationConfig.getActivationConfigProperty().length > 0)) return;
416
417         getMdbResourceAdapter().setActivationConfig(null);
418         updateResourceAdapter();
419     }
420
421
422     private void updateResourceAdapter(){
423         MdbResourceAdapter mdbResourceAdapter =
424             getMdbResourceAdapter();
425
426         if(mdbResourceAdapter.getResourceAdapterMid() != null) return;
427         if(mdbResourceAdapter.getActivationConfig() != null) return;
428         try{
429             theBean.setMdbResourceAdapter(null);
430         }catch(java.beans.PropertyVetoException JavaDoc exception){
431         }
432     }
433 }
434
Popular Tags