KickJava   Java API By Example, From Geeks To Geeks.

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


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.beans.PropertyVetoException JavaDoc;
23 import java.io.File JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.Collection JavaDoc;
26 import java.util.HashMap JavaDoc;
27 import java.util.Map JavaDoc;
28
29 import javax.enterprise.deploy.spi.DConfigBean JavaDoc;
30 import javax.enterprise.deploy.model.DDBean JavaDoc;
31 import javax.enterprise.deploy.model.DDBeanRoot JavaDoc;
32 import javax.enterprise.deploy.model.exceptions.DDBeanCreateException;
33 import javax.enterprise.deploy.spi.exceptions.ConfigurationException JavaDoc;
34
35 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean;
36 import org.netbeans.modules.j2ee.sun.dd.api.ejb.Ejb;
37 import org.netbeans.modules.j2ee.sun.dd.api.ejb.ActivationConfig;
38 import org.netbeans.modules.j2ee.sun.dd.api.ejb.ActivationConfigProperty;
39 import org.netbeans.modules.j2ee.sun.dd.api.ejb.MdbConnectionFactory;
40 import org.netbeans.modules.j2ee.sun.dd.api.ejb.MdbResourceAdapter;
41 import org.netbeans.modules.j2ee.sun.dd.api.common.MessageDestination;
42
43
44 /**
45  *
46  * @author vkraemer
47  */

48 public class MDEjb extends BaseEjb {
49     
50     /** Holds value of property subscriptionName. */
51     private String JavaDoc subscriptionName;
52     
53     /** Holds value of property maxMessageLoad. */
54     private String JavaDoc maxMessageLoad;
55     
56     /** Holds value of property mdbConnectionFactory. */
57     private MdbConnectionFactory mdbConnectionFactory;
58
59     /** Holds value of property mdbResourceAdapter. */
60     private MdbResourceAdapter mdbResourceAdapter;
61
62         public static final String JavaDoc __Enabled = "enabled"; //NOI18N
63
public static final String JavaDoc __JMSResource = "jms"; //NOI18N
64
public static final String JavaDoc __JMSConnectionFactory = "jms_CF"; //NOI18N
65
public static final String JavaDoc __JndiName = "jndi-name"; //NOI18N
66
public static final String JavaDoc __ResType = "res-type"; //NOI18N
67

68         private static final String JavaDoc MESSAGE_DSTN_NAME = "msg_dstn_name"; //NOI18N
69
private static final String JavaDoc MESSAGE_DSTN_TYPE = "msg_dstn_type"; //NOI18N
70

71         private static final String JavaDoc QUEUE = "javax.jms.Queue"; //NOI18N
72
private static final String JavaDoc QUEUE_CNTN_FACTORY = "javax.jms.QueueConnectionFactory"; //NOI18N
73
private static final String JavaDoc TOPIC = "javax.jms.Topic"; //NOI18N
74
private static final String JavaDoc TOPIC_CNTN_FACTORY = "javax.jms.TopicConnectionFactory"; //NOI18N
75

76
77
78     /** Creates a new instance of SunONEStatelessEjbDConfigBean */
79     public MDEjb() {
80     }
81
82     /** Getter for property subscriptionName.
83      * @return Value of property subscriptionName.
84      *
85      */

86     public String JavaDoc getSubscriptionName() {
87         return this.subscriptionName;
88     }
89    
90     /** Setter for property subscriptionName.
91      * @param subscriptionName New value of property subscriptionName.
92      *
93      * @throws PropertyVetoException
94      *
95      */

96     public void setSubscriptionName(String JavaDoc subscriptionName) throws java.beans.PropertyVetoException JavaDoc {
97         String JavaDoc oldSubscriptionName = this.subscriptionName;
98         getVCS().fireVetoableChange("subscriptionName", oldSubscriptionName, subscriptionName);
99         this.subscriptionName = subscriptionName;
100         getPCS().firePropertyChange("subscriptionName", oldSubscriptionName, subscriptionName);
101     }
102     
103     /** Getter for property maxMessageLoad.
104      * @return Value of property maxMessageLoad.
105      *
106      */

107     public String JavaDoc getMaxMessageLoad() {
108         return this.maxMessageLoad;
109     }
110     
111     /** Setter for property maxMessageLoad.
112      * @param maxMessageLoad New value of property maxMessageLoad.
113      *
114      * @throws PropertyVetoException
115      *
116      */

117     public void setMaxMessageLoad(String JavaDoc maxMessageLoad) throws java.beans.PropertyVetoException JavaDoc {
118         String JavaDoc oldMaxMessageLoad = this.maxMessageLoad;
119         getVCS().fireVetoableChange("maxMessageLoad", oldMaxMessageLoad, maxMessageLoad);
120         this.maxMessageLoad = maxMessageLoad;
121         getPCS().firePropertyChange("maxMessageLoad", oldMaxMessageLoad, maxMessageLoad);
122     }
123     
124     /* ------------------------------------------------------------------------
125      * Persistence support. Loads DConfigBeans from previously saved Deployment
126      * plan file.
127      */

128     protected class MDEjbSnippet extends BaseEjb.BaseEjbSnippet {
129         public CommonDDBean getDDSnippet() {
130             Ejb ejb = (Ejb) super.getDDSnippet();
131             String JavaDoc version = getAppServerVersion().getEjbJarVersionAsString();
132
133             if(subscriptionName != null){
134                 ejb.setJmsDurableSubscriptionName(subscriptionName);
135             }
136
137             if(maxMessageLoad != null){
138                 ejb.setJmsMaxMessagesLoad(maxMessageLoad);
139             }
140
141             if(null != mdbConnectionFactory){
142                 ejb.setMdbConnectionFactory((MdbConnectionFactory)mdbConnectionFactory.cloneVersion(version));
143             }
144
145             if(null != mdbResourceAdapter){
146                 ejb.setMdbResourceAdapter((MdbResourceAdapter)mdbResourceAdapter.cloneVersion(version));
147             }
148
149             return ejb;
150         }
151         
152         public boolean hasDDSnippet() {
153             boolean result = super.hasDDSnippet();
154             
155             if(!result) {
156                 if(Utils.notEmpty(subscriptionName)) {
157                     return true;
158                 }
159
160                 if(Utils.notEmpty(maxMessageLoad)) {
161                     return true;
162                 }
163
164                 if(mdbConnectionFactory != null) {
165                     return true;
166                 }
167
168                 if(mdbResourceAdapter != null) {
169                     return true;
170                 }
171             }
172             
173             return result;
174         }
175     }
176
177
178     java.util.Collection JavaDoc getSnippets() {
179             Collection JavaDoc snippets = new ArrayList JavaDoc();
180             snippets.add(new MDEjbSnippet());
181             return snippets;
182         }
183
184
185     protected void loadEjbProperties(Ejb savedEjb) {
186         super.loadEjbProperties(savedEjb);
187         
188         subscriptionName = savedEjb.getJmsDurableSubscriptionName();
189         maxMessageLoad = savedEjb.getJmsMaxMessagesLoad();
190                 
191         MdbConnectionFactory mdbConnectionFactory = savedEjb.getMdbConnectionFactory();
192         if(null != mdbConnectionFactory){
193             this.mdbConnectionFactory = mdbConnectionFactory;
194         }
195
196         MdbResourceAdapter mdbResourceAdapter = savedEjb.getMdbResourceAdapter();
197         if(null != mdbResourceAdapter){
198             this.mdbResourceAdapter = mdbResourceAdapter;
199         }
200     }
201     
202     protected void clearProperties() {
203         super.clearProperties();
204         
205         subscriptionName = null;
206         maxMessageLoad = null;
207         mdbConnectionFactory = null;
208         mdbResourceAdapter = null;
209     }
210     
211 // protected void setDefaultProperties() {
212
// super.setDefaultProperties();
213
//
214
// // Message driven beans always have a default JNDI name, which could be
215
// // set here. However, this is instead implemented in BaseEjb.setDefaultProperties()
216
// // with help from getDefaultJndiName() and requiresJndiName() which are overridden
217
// // in this class to provide the correct defaults (jms/[ejbname] and true).
218
// }
219

220     // Not really necessary to override this, but do it anyway so the proper name
221
// is always available.
222
protected String JavaDoc getDefaultJndiName() {
223         return "jms/" + getEjbName(); // NOI18N // J2EE recommended jndiName for jms resources.
224
}
225
226     protected boolean requiresJndiName() {
227         // For JavaEE5 and later spec bean, jndi name is optional, otherwise required.
228
return J2EEVersion.J2EE_1_4.compareSpecification(getJ2EEModuleVersion()) >= 0;
229     }
230
231     
232     /* ------------------------------------------------------------------------
233      * XPath to Factory mapping support
234      */

235 /*
236     private HashMap mdEjbFactoryMap;
237
238     protected Map getXPathToFactoryMap() {
239         if(mdEjbFactoryMap == null) {
240             mdEjbFactoryMap = (HashMap) super.getXPathToFactoryMap();
241             
242             // add child DCB's specific to Entity Beans
243         }
244         
245         return mdEjbFactoryMap;
246     }
247 */

248
249     //Methods called by Customizer
250
public void addActivationConfigProperty(ActivationConfigProperty property){
251         ActivationConfig activationCfg = getActivationConfig();
252         activationCfg.addActivationConfigProperty(property);
253     }
254
255
256     public void removeActivationConfigProperty(ActivationConfigProperty property){
257         if(null != mdbResourceAdapter){
258             ActivationConfig activationCfg =
259                 mdbResourceAdapter.getActivationConfig();
260             if(null != activationCfg){
261                 activationCfg.removeActivationConfigProperty(property);
262             }
263             if(activationCfg.sizeActivationConfigProperty() < 1){
264                 activationCfg.setActivationConfigProperty(null);
265             }
266             if(null == activationCfg.getDescription()){
267                 mdbResourceAdapter.setActivationConfig(null);
268                 if(null == mdbResourceAdapter.getResourceAdapterMid()){
269                     try{
270                         setMdbResourceAdapter(null);
271                     }catch(java.beans.PropertyVetoException JavaDoc exception){
272                     }
273                 }
274             }
275         }
276     }
277
278
279     private ActivationConfig getActivationConfig(){
280         MdbResourceAdapter mdbResourceAdapter = getMdbResourceAdapter();
281         if(null == mdbResourceAdapter){
282             mdbResourceAdapter = getConfig().getStorageFactory().createMdbResourceAdapter();
283             try{
284                 setMdbResourceAdapter(mdbResourceAdapter);
285             }catch(java.beans.PropertyVetoException JavaDoc exception){
286             }
287         }
288
289         ActivationConfig activationCfg =
290             mdbResourceAdapter.getActivationConfig();
291         if(null == activationCfg){
292             activationCfg = getConfig().getStorageFactory().createActivationConfig();
293             mdbResourceAdapter.setActivationConfig(activationCfg);
294         }
295         return activationCfg;
296     }
297
298
299     /** Getter for property mdbConnectionFactory.
300      * @return Value of property mdbConnectionFactory.
301      *
302      */

303     public MdbConnectionFactory getMdbConnectionFactory() {
304         return this.mdbConnectionFactory;
305     }
306
307     /** Setter for property mdbConnectionFactory.
308      * @param mdbConnectionFactory New value of property mdbConnectionFactory.
309      *
310      * @throws PropertyVetoException
311      *
312      */

313     public void setMdbConnectionFactory(MdbConnectionFactory mdbConnectionFactory) throws java.beans.PropertyVetoException JavaDoc {
314         MdbConnectionFactory oldMdbConnectionFactory = this.mdbConnectionFactory;
315         getVCS().fireVetoableChange("mdbConnectionFactory", oldMdbConnectionFactory, mdbConnectionFactory);
316         this.mdbConnectionFactory = mdbConnectionFactory;
317         getPCS().firePropertyChange("mdbConnectionFactory", oldMdbConnectionFactory, mdbConnectionFactory);
318     }
319     
320     /** Getter for property mdbResourceAdapter.
321      * @return Value of property mdbResourceAdapter.
322      *
323      */

324     public MdbResourceAdapter getMdbResourceAdapter() {
325         return this.mdbResourceAdapter;
326     }
327     
328     /** Setter for property mdbResourceAdapter.
329      * @param mdbResourceAdapter New value of property mdbResourceAdapter.
330      *
331      * @throws PropertyVetoException
332      *
333      */

334     public void setMdbResourceAdapter(MdbResourceAdapter mdbResourceAdapter) throws java.beans.PropertyVetoException JavaDoc {
335         MdbResourceAdapter oldMdbResourceAdapter = this.mdbResourceAdapter;
336         getVCS().fireVetoableChange("mdbResourceAdapter", oldMdbResourceAdapter, mdbResourceAdapter);
337         this.mdbResourceAdapter = mdbResourceAdapter;
338         getPCS().firePropertyChange("mdbResourceAdapter", oldMdbResourceAdapter, mdbResourceAdapter);
339     }
340
341
342     public String JavaDoc getHelpId() {
343         return "AS_CFG_MDEjb"; //NOI18N
344
}
345
346     private String JavaDoc getMessageDestinationInfo(String JavaDoc parameter){
347         String JavaDoc msgDstnInfo = null;
348         DDBeanRoot JavaDoc ejbJarRootDD = getDDBean().getRoot();
349
350         if(ejbJarRootDD != null) {
351             DDBean JavaDoc[] ejbNameDD =
352                 ejbJarRootDD.getChildBean("ejb-jar/enterprise-beans/message-driven/ejb-name"); //NOI18N
353
// First, find the ejb-name that corresponds to this bean
354
for(int i = 0; i < ejbNameDD.length; i++) {
355                 //System.out.println("getEjbName(): " + getEjbName()); //NOI18N
356
//System.out.println("ejbNameDD[i].getText(): " + ejbNameDD[0].getText()); //NOI18N
357
if(getEjbName().equals(ejbNameDD[i].getText())) {
358                     if(parameter.equals(MESSAGE_DSTN_NAME)){
359                         DDBean JavaDoc[] msgDstnLink =
360                             ejbNameDD[i].getChildBean("../message-destination-link"); //NOI18N
361
if(msgDstnLink.length > 0){
362                            msgDstnInfo = msgDstnLink[0].getText();
363                         }
364                     } else {
365                         if(parameter.equals(MESSAGE_DSTN_TYPE)){
366                             DDBean JavaDoc[] msgDstnType =
367                                 ejbNameDD[i].getChildBean("../message-destination-type"); //NOI18N
368
if(msgDstnType.length > 0){
369                                msgDstnInfo = msgDstnType[0].getText();
370                             }
371                         }
372                     }
373                 }
374             }
375         }
376         return msgDstnInfo;
377     }
378 }
379
Popular Tags