1 19 23 24 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.ejbmodule; 25 26 import java.util.ArrayList ; 27 import java.util.Collection ; 28 29 import javax.swing.event.TableModelListener ; 30 31 import javax.enterprise.deploy.spi.DConfigBean ; 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 50 public class MDEjbCustomizer extends EjbCustomizer 51 implements TableModelListener { 52 53 private MDEjb theBean; 54 private MDEjbPanel mdEjbPanel; 55 private BeanPoolPanel beanPoolPanel; 56 private ActivationCfgPropertyPanel actvnCfgPrptyPanel; 57 private MdbConnectionFactoryPanel mdbConnectionFactoryPanel; 58 59 60 61 public MDEjbCustomizer() { 62 } 63 64 65 public void setObject(Object bean) { 66 super.setObject(bean); 67 68 if(theBean != bean) { 70 if(bean instanceof MDEjb) { 71 theBean = (MDEjb) bean; 72 } 73 } 74 } 75 76 77 protected javax.swing.JPanel getBeanPanel(){ 79 mdEjbPanel = new MDEjbPanel(this); 80 return mdEjbPanel; 81 } 82 83 84 protected void initializeBeanPanel(BaseEjb theBean){ 86 if(!(theBean instanceof MDEjb)){ 87 assert(false); 88 } 89 90 MDEjb mdEjb = (MDEjb)theBean; 91 String jmsDurableSubscriptionName = mdEjb.getSubscriptionName(); 92 mdEjbPanel.setJmsDurableSubscriptionName(jmsDurableSubscriptionName); 93 94 String maxMessagesLoad = mdEjb.getMaxMessageLoad(); 95 mdEjbPanel.setMaxMessagesLoad(maxMessagesLoad); 96 97 MdbResourceAdapter mdbResourceAdapter = mdEjb.getMdbResourceAdapter(); 98 if(mdbResourceAdapter != null){ 99 String resourceAdapterMid = 100 mdbResourceAdapter.getResourceAdapterMid(); 101 mdEjbPanel.setResourceAdapterMid(resourceAdapterMid); 102 103 ActivationConfig activationCfg = 104 mdbResourceAdapter.getActivationConfig(); 105 if(activationCfg != null){ 106 String 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); 117 mdbConnectionFactoryPanel = new MdbConnectionFactoryPanel(this); 118 mdbConnectionFactoryPanel.getAccessibleContext().setAccessibleName(bundle.getString("Mdb_Connection_Factory_Acsbl_Name")); mdbConnectionFactoryPanel.getAccessibleContext().setAccessibleDescription(bundle.getString("Mdb_Connection_Factory_Acsbl_Desc")); tabbedPanel.addTab(bundle.getString("LBL_Mdb_Connection_Factory"), 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")); actvnCfgPrptyPanel.getAccessibleContext().setAccessibleDescription(bundle.getString("Activation_Config_Property_Acsbl_Desc")); tabbedPanel.addTab(bundle.getString("LBL_Activation_Config_Property"), actvnCfgPrptyPanel); 132 133 tabbedPanel.setSelectedIndex(tabbedPanel.indexOfTab(bundle.getString("LBL_BeanPool"))); } 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 getErrors(){ 169 ArrayList errors = null; 170 if(validationSupport == null) assert(false); 171 errors = (ArrayList )super.getErrors(); 172 173 String property = mdEjbPanel.getJmsDurableSubscriptionName(); 175 errors.addAll(validationSupport.validate(property, 176 "/sun-ejb-jar/enterprise-beans/ejb/jms-durable-subscription-name", bundle.getString("LBL_Jms_Durable_Subscription_Name"))); 179 property = mdEjbPanel.getMaxMessagesLoad(); 180 errors.addAll(validationSupport.validate(property, 181 "/sun-ejb-jar/enterprise-beans/ejb/jms-max-messages-load", bundle.getString("LBL_Jms_Max_Messages_Load"))); 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", bundle.getString("LBL_Resource_Adapter_Mid"))); 191 property = mdEjbPanel.getActivationConfigDescription(); 192 errors.addAll(validationSupport.validate(property, 193 "/sun-ejb-jar/enterprise-beans/ejb/mdb-resource-adapter/activation-config/description", bundle.getString("LBL_Activation_Config_Description"))); } 196 197 return errors; 198 } 199 200 201 public void validateEntries(){ 202 super.validateEntries(); 203 } 204 205 206 public String getHelpId() { 207 return "AS_CFG_MDEjb"; } 209 210 void updateJmsDurableSubscriptionName(String 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 exception){ 219 } 220 notifyChange(); 221 } 222 223 224 void updateJmsMaxMessagesLoad(String 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 exception){ 232 } 233 notifyChange(); 234 } 235 236 237 void updateMdbConnectionFactoryJndiName(String 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 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 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 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 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 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 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 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 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 exception){ 431 } 432 } 433 } 434 | Popular Tags |