1 19 20 package org.netbeans.modules.j2ee.sun.share.configbean; 21 22 import java.beans.PropertyVetoException ; 23 import java.io.File ; 24 import java.util.ArrayList ; 25 import java.util.Collection ; 26 import java.util.HashMap ; 27 import java.util.Map ; 28 29 import javax.enterprise.deploy.spi.DConfigBean ; 30 import javax.enterprise.deploy.model.DDBean ; 31 import javax.enterprise.deploy.model.DDBeanRoot ; 32 import javax.enterprise.deploy.model.exceptions.DDBeanCreateException; 33 import javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 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 48 public class MDEjb extends BaseEjb { 49 50 51 private String subscriptionName; 52 53 54 private String maxMessageLoad; 55 56 57 private MdbConnectionFactory mdbConnectionFactory; 58 59 60 private MdbResourceAdapter mdbResourceAdapter; 61 62 public static final String __Enabled = "enabled"; public static final String __JMSResource = "jms"; public static final String __JMSConnectionFactory = "jms_CF"; public static final String __JndiName = "jndi-name"; public static final String __ResType = "res-type"; 68 private static final String MESSAGE_DSTN_NAME = "msg_dstn_name"; private static final String MESSAGE_DSTN_TYPE = "msg_dstn_type"; 71 private static final String QUEUE = "javax.jms.Queue"; private static final String QUEUE_CNTN_FACTORY = "javax.jms.QueueConnectionFactory"; private static final String TOPIC = "javax.jms.Topic"; private static final String TOPIC_CNTN_FACTORY = "javax.jms.TopicConnectionFactory"; 76 77 78 79 public MDEjb() { 80 } 81 82 86 public String getSubscriptionName() { 87 return this.subscriptionName; 88 } 89 90 96 public void setSubscriptionName(String subscriptionName) throws java.beans.PropertyVetoException { 97 String oldSubscriptionName = this.subscriptionName; 98 getVCS().fireVetoableChange("subscriptionName", oldSubscriptionName, subscriptionName); 99 this.subscriptionName = subscriptionName; 100 getPCS().firePropertyChange("subscriptionName", oldSubscriptionName, subscriptionName); 101 } 102 103 107 public String getMaxMessageLoad() { 108 return this.maxMessageLoad; 109 } 110 111 117 public void setMaxMessageLoad(String maxMessageLoad) throws java.beans.PropertyVetoException { 118 String oldMaxMessageLoad = this.maxMessageLoad; 119 getVCS().fireVetoableChange("maxMessageLoad", oldMaxMessageLoad, maxMessageLoad); 120 this.maxMessageLoad = maxMessageLoad; 121 getPCS().firePropertyChange("maxMessageLoad", oldMaxMessageLoad, maxMessageLoad); 122 } 123 124 128 protected class MDEjbSnippet extends BaseEjb.BaseEjbSnippet { 129 public CommonDDBean getDDSnippet() { 130 Ejb ejb = (Ejb) super.getDDSnippet(); 131 String 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 getSnippets() { 179 Collection snippets = new ArrayList (); 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 220 protected String getDefaultJndiName() { 223 return "jms/" + getEjbName(); } 225 226 protected boolean requiresJndiName() { 227 return J2EEVersion.J2EE_1_4.compareSpecification(getJ2EEModuleVersion()) >= 0; 229 } 230 231 232 235 248 249 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 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 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 303 public MdbConnectionFactory getMdbConnectionFactory() { 304 return this.mdbConnectionFactory; 305 } 306 307 313 public void setMdbConnectionFactory(MdbConnectionFactory mdbConnectionFactory) throws java.beans.PropertyVetoException { 314 MdbConnectionFactory oldMdbConnectionFactory = this.mdbConnectionFactory; 315 getVCS().fireVetoableChange("mdbConnectionFactory", oldMdbConnectionFactory, mdbConnectionFactory); 316 this.mdbConnectionFactory = mdbConnectionFactory; 317 getPCS().firePropertyChange("mdbConnectionFactory", oldMdbConnectionFactory, mdbConnectionFactory); 318 } 319 320 324 public MdbResourceAdapter getMdbResourceAdapter() { 325 return this.mdbResourceAdapter; 326 } 327 328 334 public void setMdbResourceAdapter(MdbResourceAdapter mdbResourceAdapter) throws java.beans.PropertyVetoException { 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 getHelpId() { 343 return "AS_CFG_MDEjb"; } 345 346 private String getMessageDestinationInfo(String parameter){ 347 String msgDstnInfo = null; 348 DDBeanRoot ejbJarRootDD = getDDBean().getRoot(); 349 350 if(ejbJarRootDD != null) { 351 DDBean [] ejbNameDD = 352 ejbJarRootDD.getChildBean("ejb-jar/enterprise-beans/message-driven/ejb-name"); for(int i = 0; i < ejbNameDD.length; i++) { 355 if(getEjbName().equals(ejbNameDD[i].getText())) { 358 if(parameter.equals(MESSAGE_DSTN_NAME)){ 359 DDBean [] msgDstnLink = 360 ejbNameDD[i].getChildBean("../message-destination-link"); if(msgDstnLink.length > 0){ 362 msgDstnInfo = msgDstnLink[0].getText(); 363 } 364 } else { 365 if(parameter.equals(MESSAGE_DSTN_TYPE)){ 366 DDBean [] msgDstnType = 367 ejbNameDD[i].getChildBean("../message-destination-type"); if(msgDstnType.length > 0){ 369 msgDstnInfo = msgDstnType[0].getText(); 370 } 371 } 372 } 373 } 374 } 375 } 376 return msgDstnInfo; 377 } 378 } 379 | Popular Tags |