1 19 20 package org.netbeans.modules.j2ee.jboss4.config; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import java.io.ByteArrayInputStream ; 25 import java.io.File ; 26 import java.io.IOException ; 27 import java.io.OutputStream ; 28 import java.util.HashMap ; 29 import java.util.HashSet ; 30 import java.util.Map ; 31 import java.util.Set ; 32 import javax.enterprise.deploy.model.DDBean ; 33 import javax.enterprise.deploy.model.DDBeanRoot ; 34 import javax.enterprise.deploy.model.DeployableObject ; 35 import javax.enterprise.deploy.model.XpathEvent ; 36 import javax.enterprise.deploy.model.XpathListener ; 37 import javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 38 import javax.swing.text.BadLocationException ; 39 import javax.swing.text.StyledDocument ; 40 import org.netbeans.modules.j2ee.deployment.common.api.DatasourceAlreadyExistsException; 41 import org.netbeans.modules.j2ee.jboss4.config.gen.EnterpriseBeans; 42 import org.netbeans.modules.j2ee.jboss4.config.gen.Jboss; 43 import org.netbeans.modules.j2ee.jboss4.config.gen.MessageDriven; 44 import org.openide.DialogDisplayer; 45 import org.openide.ErrorManager; 46 import org.openide.NotifyDescriptor; 47 import org.openide.cookies.EditorCookie; 48 import org.openide.cookies.SaveCookie; 49 import org.openide.filesystems.FileUtil; 50 import org.openide.loaders.DataObject; 51 import org.openide.loaders.DataObjectNotFoundException; 52 import org.openide.util.NbBundle; 53 54 55 60 public class EjbDeploymentConfiguration extends JBDeploymentConfiguration 61 implements PropertyChangeListener , XpathListener { 62 63 private static final String SESSION_RESOURCE_REF = "/ejb-jar/enterprise-beans/session/resource-ref"; private static final String ENTITY_RESOURCE_REF = "/ejb-jar/enterprise-beans/entity/resource-ref"; private static final String MSGDRV_RESOURCE_REF = "/ejb-jar/enterprise-beans/message-driven/resource-ref"; private static final String SESSION_EJB_REF = "/ejb-jar/enterprise-beans/session/ejb-ref"; private static final String ENTITY_EJB_REF = "/ejb-jar/enterprise-beans/entity/ejb-ref"; private static final String MSGDRV_EJB_REF = "/ejb-jar/enterprise-beans/message-driven/ejb-ref"; private static final String MSGDRV = "/ejb-jar/enterprise-beans/message-driven"; private static final String MSGDRV_MSG_DEST = MSGDRV + "/message-destination-link"; private static final String SESSION_MSG_DEST_REF = "/ejb-jar/enterprise-beans/session/message-destination-ref"; private static final String ENTITY_MSG_DEST_REF = "/ejb-jar/enterprise-beans/entity/message-destination-ref"; private static final String MSGDRV_MSG_DEST_REF = "/ejb-jar/enterprise-beans/message-driven/message-destination-ref"; 75 static class BEAN_TYPE { 76 private String type; 77 78 private BEAN_TYPE(String type) { this.type = type; } 79 String getType() { return type; } 80 81 static final BEAN_TYPE SESSION = new BEAN_TYPE("session"); static final BEAN_TYPE ENTITY = new BEAN_TYPE("entity"); static final BEAN_TYPE MSGDRV = new BEAN_TYPE("message-driven"); } 85 86 private File jbossFile; 87 private Jboss jboss; 88 89 private String tempEjbName; 91 92 private final boolean isEJB3; 93 94 97 public EjbDeploymentConfiguration(DeployableObject deployableObject) { 98 super(deployableObject); 99 if (deployableObject != null && deployableObject.getDDBeanRoot() != null && 100 "3.0".equals(deployableObject.getDDBeanRoot().getDDBeanRootVersion())) { isEJB3 = true; 102 } 103 else { 104 isEJB3 = false; 105 } 106 } 107 108 115 public void init(File file, File resourceDir) { 116 super.init(resourceDir); 117 this.jbossFile = file; 118 getJboss(); 119 if (deploymentDescriptorDO == null) { 120 try { 121 deploymentDescriptorDO = deploymentDescriptorDO.find(FileUtil.toFileObject(jbossFile)); 122 deploymentDescriptorDO.addPropertyChangeListener(this); 123 } catch(DataObjectNotFoundException donfe) { 124 ErrorManager.getDefault().notify(donfe); 125 } 126 } 127 128 if (deplObj != null && deplObj.getDDBeanRoot() != null ) { 129 DDBeanRoot root = deplObj.getDDBeanRoot(); 131 root.addXpathListener(SESSION_RESOURCE_REF, this); 132 root.addXpathListener(ENTITY_RESOURCE_REF, this); 133 root.addXpathListener(SESSION_EJB_REF, this); 134 root.addXpathListener(ENTITY_EJB_REF, this); 135 root.addXpathListener(MSGDRV_RESOURCE_REF, this); 136 root.addXpathListener(MSGDRV_EJB_REF, this); 137 root.addXpathListener(MSGDRV, this); 138 root.addXpathListener(MSGDRV_MSG_DEST, this); 139 root.addXpathListener(SESSION_MSG_DEST_REF, this); 140 root.addXpathListener(ENTITY_MSG_DEST_REF, this); 141 root.addXpathListener(MSGDRV_MSG_DEST_REF, this); 142 } 143 } 144 145 151 public synchronized Jboss getJboss() { 152 if (jboss == null) { 153 try { 154 if (jbossFile.exists()) { 155 try { 157 jboss = jboss.createGraph(jbossFile); 158 } catch (IOException ioe) { 159 ErrorManager.getDefault().notify(ioe); 160 } catch (RuntimeException re) { 161 } 163 } else { 164 jboss = generateJboss(); 166 writefile(jbossFile, jboss); 167 } 168 } catch (ConfigurationException ce) { 169 ErrorManager.getDefault().notify(ce); 170 } 171 } 172 return jboss; 173 } 174 175 178 public synchronized void propertyChange(PropertyChangeEvent evt) { 179 if (evt.getPropertyName() == DataObject.PROP_MODIFIED && 180 evt.getNewValue() == Boolean.FALSE) { 181 182 if (evt.getSource() == deploymentDescriptorDO) jboss = null; 184 else 185 super.propertyChange(evt); 186 } 187 } 188 189 public void fireXpathEvent(XpathEvent xpe) { 190 191 if (!xpe.isAddEvent()) 192 return; 193 194 DDBean eventDDBean = xpe.getBean(); 195 if (SESSION_RESOURCE_REF.equals(eventDDBean.getXpath()) || 196 ENTITY_RESOURCE_REF.equals(eventDDBean.getXpath()) || 197 MSGDRV_RESOURCE_REF.equals(eventDDBean.getXpath())) 198 { 199 String [] desc = eventDDBean.getText("description"); String [] name = eventDDBean.getText("res-ref-name"); String [] type = eventDDBean.getText("res-type"); if (name.length > 0 && type.length > 0) { 203 try { 204 BEAN_TYPE beanType = (SESSION_RESOURCE_REF.equals(eventDDBean.getXpath()) ? 208 BEAN_TYPE.SESSION : (ENTITY_RESOURCE_REF.equals(eventDDBean.getXpath()) ? 209 BEAN_TYPE.ENTITY : BEAN_TYPE.MSGDRV)); 210 211 if (beanType != BEAN_TYPE.MSGDRV) { Set beanNames = null; 213 if (desc.length > 0 && "javax.sql.DataSource".equals(type[0])) { beanNames = getRelevantBeansDataRef(desc[0], name[0], eventDDBean.getRoot(), beanType); 215 addResReference(desc[0], name[0], beanNames, beanType); 216 } 217 else 218 if ("javax.mail.Session".equals(type[0])) { beanNames = getRelevantBeansMailRef(name[0], eventDDBean.getRoot(), beanType); 220 addMailReference(name[0], beanNames, beanType); 221 } 222 else 223 if ("javax.jms.ConnectionFactory".equals(type[0])) { beanNames = getRelevantBeansConnectionFactoryRef(name[0], eventDDBean.getRoot(), beanType); 225 addConnectionFactoryReference(name[0], beanNames, beanType); 226 } 227 } 228 else { Map beans = null; 230 if (desc.length > 0 && "javax.sql.DataSource".equals(type[0])) { beans = getRelevantMsgDrvBeansDataRef(desc[0], name[0], eventDDBean.getRoot()); 232 addMsgDrvResReference(desc[0], name[0], beans); 233 } 234 if ("javax.mail.Session".equals(type[0])) { beans = getRelevantMsgDrvBeansMailRef(name[0], eventDDBean.getRoot()); 236 addMsgDrvMailReference(name[0], beans); 237 } 238 else 239 if ("javax.jms.ConnectionFactory".equals(type[0])) { beans = getRelevantMsgDrvBeansConnectionFactoryRef(name[0], eventDDBean.getRoot()); 241 addMsgDrvConnectionFactoryReference(name[0], beans); 242 } 243 } 244 245 } catch (ConfigurationException ce) { 246 ErrorManager.getDefault().notify(ce); 247 } 248 } 249 } 250 else if (SESSION_EJB_REF.equals(eventDDBean.getXpath()) || 251 ENTITY_EJB_REF.equals(eventDDBean.getXpath()) || 252 MSGDRV_EJB_REF.equals(eventDDBean.getXpath())) 253 { 254 String [] name = eventDDBean.getText("ejb-ref-name"); String [] type = eventDDBean.getText("ejb-ref-type"); if (name.length > 0 && type.length > 0 257 && ("Session".equals(type[0]) || "Entity".equals(type[0]))) { try { 259 BEAN_TYPE beanType = (SESSION_EJB_REF.equals(eventDDBean.getXpath()) ? 263 BEAN_TYPE.SESSION : (ENTITY_EJB_REF.equals(eventDDBean.getXpath()) ? 264 BEAN_TYPE.ENTITY : BEAN_TYPE.MSGDRV)); 265 266 if (beanType != BEAN_TYPE.MSGDRV) { Set beanNames = getRelevantBeansEjbRef(name[0], eventDDBean.getRoot(), beanType); 268 addEjbReference(name[0], beanNames, beanType); 269 } 270 else { Map beans = getRelevantMsgDrvBeansEjbRef(name[0], eventDDBean.getRoot()); 272 addMsgDrvEjbReference(name[0], beans); 273 } 274 275 } catch (ConfigurationException ce) { 276 ErrorManager.getDefault().notify(ce); 277 } 278 } 279 } 280 else if (MSGDRV.equals(eventDDBean.getXpath())) { 281 if (isEJB3) { return; 283 } 284 285 String [] name = eventDDBean.getText("ejb-name"); String [] type = eventDDBean.getText("message-destination-type"); String [] dest = eventDDBean.getText("message-destination-link"); 289 if (name.length == 0) 290 return; 291 292 if (dest.length == 0) { 293 tempEjbName = name[0]; 294 } else { 295 try { 296 addMDB(name[0], dest[0]); 297 } catch (ConfigurationException ce) { 298 ErrorManager.getDefault().notify(ce); 299 } 300 } 301 } 302 else if (MSGDRV_MSG_DEST.equals(eventDDBean.getXpath())) { if (isEJB3) { return; 305 } 306 307 if (tempEjbName == null) return; 309 310 try { 311 String dest = xpe.getBean().getText(); 312 addMDB(tempEjbName, dest); 313 } catch (ConfigurationException ce) { 314 ErrorManager.getDefault().notify(ce); 315 } finally { 316 tempEjbName = null; 317 } 318 } 319 320 else if (SESSION_MSG_DEST_REF.equals(eventDDBean.getXpath()) || 321 ENTITY_MSG_DEST_REF.equals(eventDDBean.getXpath()) || 322 MSGDRV_MSG_DEST_REF.equals(eventDDBean.getXpath())) 323 { 324 String [] name = eventDDBean.getText("message-destination-ref-name"); String [] type = eventDDBean.getText("message-destination-type"); 327 if (name.length > 0) { 328 329 String destPrefix = ""; 330 if (type.length > 0) { 331 if (type[0].equals("javax.jms.Queue")) destPrefix = JBOSS4_MSG_QUEUE_JNDI_PREFIX; 333 else 334 if (type[0].equals("javax.jms.Topic")) destPrefix = JBOSS4_MSG_TOPIC_JNDI_PREFIX; 336 } 337 338 try { 339 BEAN_TYPE beanType = (SESSION_MSG_DEST_REF.equals(eventDDBean.getXpath()) ? 343 BEAN_TYPE.SESSION : (ENTITY_MSG_DEST_REF.equals(eventDDBean.getXpath()) ? 344 BEAN_TYPE.ENTITY : BEAN_TYPE.MSGDRV)); 345 346 if (beanType != BEAN_TYPE.MSGDRV) { Set beanNames = getRelevantBeansMsgDestRef(name[0], eventDDBean.getRoot(), beanType); 348 addMsgDestReference(name[0], destPrefix, beanNames, beanType); 349 } 350 else { Map beans = getRelevantMsgDrvBeansMsgDestRef(name[0], eventDDBean.getRoot()); 352 addMsgDrvMsgDestReference(name[0], destPrefix, beans); 353 } 354 355 } catch (ConfigurationException ce) { 356 ErrorManager.getDefault().notify(ce); 357 } 358 } 359 } 360 } 361 362 374 private Set getRelevantBeansDataRef(String desc, String resRefName, DDBeanRoot root, BEAN_TYPE beanType) { 375 376 Set beanNames = new HashSet (); 377 DDBean [] beans = root.getChildBean("/ejb-jar/enterprise-beans/" + beanType.getType()); for (int i = 0; i < beans.length; i++) { 379 DDBean bean = beans[i]; 380 DDBean [] resRefs = bean.getChildBean("resource-ref"); 381 for (int j = 0; resRefs != null && j < resRefs.length; j++) { 382 String [] descs = resRefs[j].getText("description"); String [] names = resRefs[j].getText("res-ref-name"); String [] types = resRefs[j].getText("res-type"); if (descs.length > 0 && names.length > 0 && types.length > 0 && 386 descs[0].equals(desc) && names[0].equals(resRefName) && "javax.sql.DataSource".equals(types[0])) { beanNames.add(bean.getChildBean("ejb-name")[0].getText()); break; 390 } 391 } 392 } 393 394 return beanNames; 395 } 396 397 408 private Map getRelevantMsgDrvBeansDataRef(String desc, String resRefName, DDBeanRoot root) { 409 410 HashMap beanMap = new HashMap (); DDBean [] beans = root.getChildBean("/ejb-jar/enterprise-beans/message-driven"); for (int i = 0; i < beans.length; i++) { 413 DDBean bean = beans[i]; 414 DDBean [] resRefs = bean.getChildBean("resource-ref"); 415 for (int j = 0; resRefs != null && j < resRefs.length; j++) { 416 String [] descs = resRefs[j].getText("description"); String [] names = resRefs[j].getText("res-ref-name"); String [] types = resRefs[j].getText("res-type"); if (descs.length > 0 && names.length > 0 && types.length > 0 && 420 descs[0].equals(desc) && names[0].equals(resRefName) && "javax.sql.DataSource".equals(types[0])) { String key = bean.getChildBean("ejb-name")[0].getText(); 423 String value = ""; 424 if (bean.getChildBean("message-destination-link").length > 0) value = bean.getChildBean("message-destination-link")[0].getText(); 426 beanMap.put(key, value); break; 428 } 429 } 430 } 431 432 return beanMap; 433 } 434 435 443 private Set getRelevantBeansEjbRef(String ejbRefName, DDBeanRoot root, BEAN_TYPE beanType) { 444 445 Set beanNames = new HashSet (); 446 DDBean [] beans = root.getChildBean("/ejb-jar/enterprise-beans/" + beanType.getType()); for (int i = 0; i < beans.length; i++) { 448 DDBean bean = beans[i]; 449 DDBean [] ejbRefs = bean.getChildBean("ejb-ref"); 450 for (int j = 0; ejbRefs != null && j < ejbRefs.length; j++) { 451 String [] names = ejbRefs[j].getText("ejb-ref-name"); String [] types = ejbRefs[j].getText("ejb-ref-type"); if (names.length > 0 && types.length > 0 && names[0].equals(ejbRefName) 454 && ("Session".equals(types[0]) || "Entity".equals(types[0]))) { beanNames.add(bean.getChildBean("ejb-name")[0].getText()); break; 458 } 459 } 460 } 461 462 return beanNames; 463 } 464 465 interface JbossModifier { 466 public void modify(Jboss modifiedJboss); 467 } 468 469 479 private Map getRelevantMsgDrvBeansEjbRef(String ejbRefName, DDBeanRoot root) { 480 481 HashMap beanMap = new HashMap (); DDBean [] beans = root.getChildBean("/ejb-jar/enterprise-beans/message-driven"); for (int i = 0; i < beans.length; i++) { 484 DDBean bean = beans[i]; 485 DDBean [] ejbRefs = bean.getChildBean("ejb-ref"); 486 for (int j = 0; ejbRefs != null && j < ejbRefs.length; j++) { 487 String [] names = ejbRefs[j].getText("ejb-ref-name"); String [] types = ejbRefs[j].getText("ejb-ref-type"); if (names.length > 0 && types.length > 0 && names[0].equals(ejbRefName) 490 && ("Session".equals(types[0]) || "Entity".equals(types[0]))) { String key = bean.getChildBean("ejb-name")[0].getText(); 493 String value = ""; 494 if (bean.getChildBean("message-destination-link").length > 0) value = bean.getChildBean("message-destination-link")[0].getText(); 496 beanMap.put(key, value); break; 498 } 499 } 500 } 501 502 return beanMap; 503 } 504 505 516 private Set getRelevantBeansMailRef(String resRefName, DDBeanRoot root, BEAN_TYPE beanType) { 517 518 Set beanNames = new HashSet (); 519 DDBean [] beans = root.getChildBean("/ejb-jar/enterprise-beans/" + beanType.getType()); for (int i = 0; i < beans.length; i++) { 521 DDBean bean = beans[i]; 522 DDBean [] resRefs = bean.getChildBean("resource-ref"); 523 for (int j = 0; resRefs != null && j < resRefs.length; j++) { 524 String [] names = resRefs[j].getText("res-ref-name"); String [] types = resRefs[j].getText("res-type"); if (names.length > 0 && types.length > 0 && 527 names[0].equals(resRefName) && "javax.mail.Session".equals(types[0])) { beanNames.add(bean.getChildBean("ejb-name")[0].getText()); break; 531 } 532 } 533 } 534 535 return beanNames; 536 } 537 538 548 private Map getRelevantMsgDrvBeansMailRef(String resRefName, DDBeanRoot root) { 549 550 HashMap beanMap = new HashMap (); DDBean [] beans = root.getChildBean("/ejb-jar/enterprise-beans/message-driven"); for (int i = 0; i < beans.length; i++) { 553 DDBean bean = beans[i]; 554 DDBean [] resRefs = bean.getChildBean("resource-ref"); 555 for (int j = 0; resRefs != null && j < resRefs.length; j++) { 556 String [] names = resRefs[j].getText("res-ref-name"); String [] types = resRefs[j].getText("res-type"); if (names.length > 0 && types.length > 0 && 559 names[0].equals(resRefName) && "javax.mail.Session".equals(types[0])) { String key = bean.getChildBean("ejb-name")[0].getText(); 562 String value = ""; 563 if (bean.getChildBean("message-destination-link").length > 0) value = bean.getChildBean("message-destination-link")[0].getText(); 565 beanMap.put(key, value); break; 567 } 568 } 569 } 570 571 return beanMap; 572 } 573 574 585 private Set getRelevantBeansConnectionFactoryRef(String resRefName, DDBeanRoot root, BEAN_TYPE beanType) { 586 587 Set beanNames = new HashSet (); 588 DDBean [] beans = root.getChildBean("/ejb-jar/enterprise-beans/" + beanType.getType()); for (int i = 0; i < beans.length; i++) { 590 DDBean bean = beans[i]; 591 DDBean [] resRefs = bean.getChildBean("resource-ref"); 592 for (int j = 0; resRefs != null && j < resRefs.length; j++) { 593 String [] names = resRefs[j].getText("res-ref-name"); String [] types = resRefs[j].getText("res-type"); if (names.length > 0 && types.length > 0 && 596 names[0].equals(resRefName) && "javax.jms.ConnectionFactory".equals(types[0])) { beanNames.add(bean.getChildBean("ejb-name")[0].getText()); break; 600 } 601 } 602 } 603 604 return beanNames; 605 } 606 607 617 private Map getRelevantMsgDrvBeansConnectionFactoryRef(String resRefName, DDBeanRoot root) { 618 619 HashMap beanMap = new HashMap (); DDBean [] beans = root.getChildBean("/ejb-jar/enterprise-beans/message-driven"); for (int i = 0; i < beans.length; i++) { 622 DDBean bean = beans[i]; 623 DDBean [] resRefs = bean.getChildBean("resource-ref"); 624 for (int j = 0; resRefs != null && j < resRefs.length; j++) { 625 String [] names = resRefs[j].getText("res-ref-name"); String [] types = resRefs[j].getText("res-type"); if (names.length > 0 && types.length > 0 && 628 names[0].equals(resRefName) && "javax.jms.ConnectionFactory".equals(types[0])) { String key = bean.getChildBean("ejb-name")[0].getText(); 631 String value = ""; 632 if (bean.getChildBean("message-destination-link").length > 0) value = bean.getChildBean("message-destination-link")[0].getText(); 634 beanMap.put(key, value); break; 636 } 637 } 638 } 639 640 return beanMap; 641 } 642 643 651 private Set getRelevantBeansMsgDestRef(String msgDestRefName, DDBeanRoot root, BEAN_TYPE beanType) { 652 653 Set beanNames = new HashSet (); 654 DDBean [] beans = root.getChildBean("/ejb-jar/enterprise-beans/" + beanType.getType()); for (int i = 0; i < beans.length; i++) { 656 DDBean bean = beans[i]; 657 DDBean [] msgDestRefs = bean.getChildBean("message-destination-ref"); for (int j = 0; msgDestRefs != null && j < msgDestRefs.length; j++) { 659 String [] names = msgDestRefs[j].getText("message-destination-ref-name"); if (names.length > 0 && names[0].equals(msgDestRefName)) { 661 beanNames.add(bean.getChildBean("ejb-name")[0].getText()); break; 664 } 665 } 666 } 667 668 return beanNames; 669 } 670 671 679 private Map getRelevantMsgDrvBeansMsgDestRef(String msgDestRefName, DDBeanRoot root) { 680 681 HashMap beanMap = new HashMap (); DDBean [] beans = root.getChildBean("/ejb-jar/enterprise-beans/message-driven"); for (int i = 0; i < beans.length; i++) { 684 DDBean bean = beans[i]; 685 DDBean [] msgDestRefs = bean.getChildBean("message-destination-ref"); for (int j = 0; msgDestRefs != null && j < msgDestRefs.length; j++) { 687 String [] names = msgDestRefs[j].getText("message-destination-ref-name"); if (names.length > 0 && names[0].equals(msgDestRefName)) { 689 String key = bean.getChildBean("ejb-name")[0].getText(); 691 String value = ""; 692 if (bean.getChildBean("message-destination-link").length > 0) value = bean.getChildBean("message-destination-link")[0].getText(); 694 beanMap.put(key, value); break; 696 } 697 } 698 } 699 700 return beanMap; 701 } 702 703 711 private void addResReference(String desc, final String resRefName, final Set beanNames, final BEAN_TYPE beanType) 712 throws ConfigurationException 713 { 714 modifyJboss(new JbossModifier() { 715 public void modify(Jboss modifiedJboss) { 716 String jndiName = JBDeploymentConfiguration.JBOSS4_DATASOURCE_JNDI_PREFIX + resRefName; 717 JbossDataSourceRefModifier.modify(modifiedJboss, resRefName, beanNames, beanType, jndiName); 718 } 719 }); 720 } 721 722 730 private void addMsgDrvResReference(String desc, final String resRefName, final Map beans) 731 throws ConfigurationException 732 { 733 modifyJboss(new JbossModifier() { 734 public void modify(Jboss modifiedJboss) { 735 String jndiName = JBDeploymentConfiguration.JBOSS4_DATASOURCE_JNDI_PREFIX + resRefName; 736 JbossDataSourceRefModifier.modifyMsgDrv(modifiedJboss, resRefName, beans, jndiName); 737 } 738 }); 739 } 740 741 748 private void addEjbReference(final String ejbRefName, final Set beanNames, final BEAN_TYPE beanType) 749 throws ConfigurationException 750 { 751 modifyJboss(new JbossModifier() { 752 public void modify(Jboss modifiedJboss) { 753 JbossEjbRefModifier.modify(modifiedJboss, ejbRefName, beanNames, beanType); 754 } 755 }); 756 } 757 758 765 private void addMsgDrvEjbReference(final String ejbRefName, final Map beans) 766 throws ConfigurationException 767 { 768 modifyJboss(new JbossModifier() { 769 public void modify(Jboss modifiedJboss) { 770 JbossEjbRefModifier.modifyMsgDrv(modifiedJboss, ejbRefName, beans); 771 } 772 }); 773 } 774 775 782 private void addMailReference(final String resRefName, final Set beanNames, final BEAN_TYPE beanType) 783 throws ConfigurationException 784 { 785 modifyJboss(new JbossModifier() { 786 public void modify(Jboss modifiedJboss) { 787 String jndiName = JBOSS4_MAIL_SERVICE_JNDI_NAME; 788 JbossDataSourceRefModifier.modify(modifiedJboss, resRefName, beanNames, beanType, jndiName); 789 } 790 }); 791 } 792 793 800 private void addMsgDrvMailReference(final String resRefName, final Map beans) 801 throws ConfigurationException 802 { 803 modifyJboss(new JbossModifier() { 804 public void modify(Jboss modifiedJboss) { 805 String jndiName = JBOSS4_MAIL_SERVICE_JNDI_NAME; 806 JbossDataSourceRefModifier.modifyMsgDrv(modifiedJboss, resRefName, beans, jndiName); 807 } 808 }); 809 } 810 811 817 private void addMDB(final String name, final String dest) throws ConfigurationException { 818 modifyJboss(new JbossModifier() { 819 public void modify(Jboss modifiedJboss) { 820 821 EnterpriseBeans eb = modifiedJboss.getEnterpriseBeans(); 822 if (eb == null) { 823 eb = new EnterpriseBeans(); 824 modifiedJboss.setEnterpriseBeans(eb); 825 } 826 827 MessageDriven[] mdbs = eb.getMessageDriven(); 829 for (int i = 0; i < mdbs.length; i++) { 830 String en = mdbs[i].getEjbName(); 831 if (name.equals(en)) { 832 return; 834 } 835 } 836 837 MessageDriven mdb = new MessageDriven(); 839 mdb.setEjbName(name); 840 mdb.setDestinationJndiName(dest); eb.addMessageDriven(mdb); 842 } 843 }); 844 } 845 846 853 private void addConnectionFactoryReference(final String resRefName, final Set beanNames, final BEAN_TYPE beanType) 854 throws ConfigurationException 855 { 856 modifyJboss(new JbossModifier() { 857 public void modify(Jboss modifiedJboss) { 858 String jndiName = JBOSS4_CONN_FACTORY_JNDI_NAME; 859 JbossDataSourceRefModifier.modify(modifiedJboss, resRefName, beanNames, beanType, jndiName); 860 } 861 }); 862 } 863 864 871 private void addMsgDrvConnectionFactoryReference(final String resRefName, final Map beans) 872 throws ConfigurationException 873 { 874 modifyJboss(new JbossModifier() { 875 public void modify(Jboss modifiedJboss) { 876 String jndiName = JBOSS4_CONN_FACTORY_JNDI_NAME; 877 JbossDataSourceRefModifier.modifyMsgDrv(modifiedJboss, resRefName, beans, jndiName); 878 } 879 }); 880 } 881 882 889 private void addMsgDestReference(final String msgDestRefName, final String destPrefix, 890 final Set beanNames, final BEAN_TYPE beanType) throws ConfigurationException 891 { 892 modifyJboss(new JbossModifier() { 893 public void modify(Jboss modifiedJboss) { 894 JbossMsgDestRefModifier.modify(modifiedJboss, msgDestRefName, beanNames, beanType, destPrefix); 895 } 896 }); 897 } 898 899 906 private void addMsgDrvMsgDestReference(final String msgDestRefName, final String destPrefix, 907 final Map beans) throws ConfigurationException 908 { 909 modifyJboss(new JbossModifier() { 910 public void modify(Jboss modifiedJboss) { 911 JbossMsgDestRefModifier.modifyMsgDrv(modifiedJboss, msgDestRefName, beans, destPrefix); 912 } 913 }); 914 } 915 916 922 private void modifyJboss(JbossModifier modifier) 923 throws ConfigurationException 924 { 925 assert deploymentDescriptorDO != null : "DataObject has not been initialized yet"; try { 927 EditorCookie editor = (EditorCookie)deploymentDescriptorDO.getCookie(EditorCookie.class); 929 StyledDocument doc = editor.getDocument(); 930 if (doc == null) { 931 doc = editor.openDocument(); 932 } 933 934 Jboss newJboss = null; 936 try { 937 byte[] docString = doc.getText(0, doc.getLength()).getBytes(); 939 newJboss = Jboss.createGraph(new ByteArrayInputStream (docString)); 940 } catch (RuntimeException e) { 941 Jboss oldJboss = getJboss(); 942 if (oldJboss == null) { 943 throw new ConfigurationException ( 946 NbBundle.getMessage(JBDeploymentConfiguration.class, "MSG_jbossXmlCannotParse", "jboss.xml")); } 948 NotifyDescriptor notDesc = new NotifyDescriptor.Confirmation( 950 NbBundle.getMessage(WarDeploymentConfiguration.class, "MSG_jbossXmlNotValid", "jboss.xml"), 951 NotifyDescriptor.OK_CANCEL_OPTION); 952 Object result = DialogDisplayer.getDefault().notify(notDesc); 953 if (result == NotifyDescriptor.CANCEL_OPTION) { 954 return; 956 } 957 newJboss = oldJboss; 959 } 960 961 modifier.modify(newJboss); 963 964 boolean modified = deploymentDescriptorDO.isModified(); 966 replaceDocument(doc, newJboss); 967 if (!modified) { 968 SaveCookie cookie = (SaveCookie)deploymentDescriptorDO.getCookie(SaveCookie.class); 969 cookie.save(); 970 } 971 jboss = newJboss; 972 } catch (BadLocationException ble) { 973 throw (ConfigurationException )(new ConfigurationException ().initCause(ble)); 974 } catch (IOException ioe) { 975 throw (ConfigurationException )(new ConfigurationException ().initCause(ioe)); 976 } 977 } 978 979 981 public void save(OutputStream os) throws ConfigurationException { 982 Jboss jboss = getJboss(); 983 if (jboss == null) { 984 throw new ConfigurationException ("Cannot read configuration, it is probably in an inconsistent state."); } 986 try { 987 jboss.write(os); 988 } catch (IOException ioe) { 989 throw new ConfigurationException (ioe.getLocalizedMessage()); 990 } 991 } 992 993 995 998 private Jboss generateJboss() { 999 return new Jboss(); 1000 } 1001 1002} 1003 | Popular Tags |