Index: jboss4/src/org/netbeans/modules/j2ee/jboss4/config/EjbDeploymentConfiguration.java =================================================================== RCS file: /cvs/serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/EjbDeploymentConfiguration.java,v retrieving revision 1.4 diff -u -8 -p -r1.4 EjbDeploymentConfiguration.java --- jboss4/src/org/netbeans/modules/j2ee/jboss4/config/EjbDeploymentConfiguration.java 12 Oct 2006 14:38:00 -0000 1.4 +++ jboss4/src/org/netbeans/modules/j2ee/jboss4/config/EjbDeploymentConfiguration.java 9 Jan 2007 12:02:24 -0000 @@ -52,17 +52,17 @@ import org.openide.loaders.DataObjectNot import org.openide.util.NbBundle; /** * EJB module deployment configuration handles jboss.xml configuration file creation. * * @author sherold, lkotouc */ -public class EjbDeploymentConfiguration extends JBDeploymentConfiguration +public class EjbDeploymentConfiguration extends JBDeploymentConfiguration implements PropertyChangeListener, XpathListener { private static final String SESSION_RESOURCE_REF = "/ejb-jar/enterprise-beans/session/resource-ref"; // NOI18N private static final String ENTITY_RESOURCE_REF = "/ejb-jar/enterprise-beans/entity/resource-ref"; //NOI1*N private static final String MSGDRV_RESOURCE_REF = "/ejb-jar/enterprise-beans/message-driven/resource-ref"; // NOI18N private static final String SESSION_EJB_REF = "/ejb-jar/enterprise-beans/session/ejb-ref"; // NOI18N private static final String ENTITY_EJB_REF = "/ejb-jar/enterprise-beans/entity/ejb-ref"; // NOI18N private static final String MSGDRV_EJB_REF = "/ejb-jar/enterprise-beans/message-driven/ejb-ref"; // NOI18N @@ -82,62 +82,64 @@ public class EjbDeploymentConfiguration static final BEAN_TYPE ENTITY = new BEAN_TYPE("entity"); // NOI18N static final BEAN_TYPE MSGDRV = new BEAN_TYPE("message-driven"); // NOI18N } private File jbossFile; private Jboss jboss; // stores ejb-name between MSGDRV Xpath event and MSGDRV_MSG_DEST are fired - private String tempEjbName; + private String tempEjbName; private final boolean isEJB3; - + /** - * Creates a new instance of EjbDeploymentConfiguration + * Creates a new instance of EjbDeploymentConfiguration */ public EjbDeploymentConfiguration(DeployableObject deployableObject) { super(deployableObject); - isEJB3 = ("3.0".equals(deployableObject.getDDBeanRoot().getDDBeanRootVersion())); // NOI81N + isEJB3 = (deployableObject.getDDBeanRoot() != null)?("3.0".equals(deployableObject.getDDBeanRoot().getDDBeanRootVersion())):(true); // NOI81N } /** * EjbDeploymentConfiguration initialization. This method should be called before * this class is being used. - * + * * @param file jboss.xml file. * @param resourceDir directory containing definition for enterprise resources. */ public void init(File file, File resourceDir) { super.init(resourceDir); this.jbossFile = file; getJboss(); if (deploymentDescriptorDO == null) { try { deploymentDescriptorDO = deploymentDescriptorDO.find(FileUtil.toFileObject(jbossFile)); deploymentDescriptorDO.addPropertyChangeListener(this); } catch(DataObjectNotFoundException donfe) { ErrorManager.getDefault().notify(donfe); } } - //listen on the resource-ref element - deplObj.getDDBeanRoot().addXpathListener(SESSION_RESOURCE_REF, this); - deplObj.getDDBeanRoot().addXpathListener(ENTITY_RESOURCE_REF, this); - deplObj.getDDBeanRoot().addXpathListener(SESSION_EJB_REF, this); - deplObj.getDDBeanRoot().addXpathListener(ENTITY_EJB_REF, this); - deplObj.getDDBeanRoot().addXpathListener(MSGDRV_RESOURCE_REF, this); - deplObj.getDDBeanRoot().addXpathListener(MSGDRV_EJB_REF, this); - deplObj.getDDBeanRoot().addXpathListener(MSGDRV, this); - deplObj.getDDBeanRoot().addXpathListener(MSGDRV_MSG_DEST, this); - deplObj.getDDBeanRoot().addXpathListener(SESSION_MSG_DEST_REF, this); - deplObj.getDDBeanRoot().addXpathListener(ENTITY_MSG_DEST_REF, this); - deplObj.getDDBeanRoot().addXpathListener(MSGDRV_MSG_DEST_REF, this); + if(deplObj.getDDBeanRoot() != null) { + //listen on the resource-ref element + deplObj.getDDBeanRoot().addXpathListener(SESSION_RESOURCE_REF, this); + deplObj.getDDBeanRoot().addXpathListener(ENTITY_RESOURCE_REF, this); + deplObj.getDDBeanRoot().addXpathListener(SESSION_EJB_REF, this); + deplObj.getDDBeanRoot().addXpathListener(ENTITY_EJB_REF, this); + deplObj.getDDBeanRoot().addXpathListener(MSGDRV_RESOURCE_REF, this); + deplObj.getDDBeanRoot().addXpathListener(MSGDRV_EJB_REF, this); + deplObj.getDDBeanRoot().addXpathListener(MSGDRV, this); + deplObj.getDDBeanRoot().addXpathListener(MSGDRV_MSG_DEST, this); + deplObj.getDDBeanRoot().addXpathListener(SESSION_MSG_DEST_REF, this); + deplObj.getDDBeanRoot().addXpathListener(ENTITY_MSG_DEST_REF, this); + deplObj.getDDBeanRoot().addXpathListener(MSGDRV_MSG_DEST_REF, this); + } } - + /** * Return jboss graph. If it was not created yet, load it from the file * and cache it. If the file does not exist, generate it. * * @return jboss graph or null if the jboss.xml file is not parseable. */ public synchronized Jboss getJboss() { if (jboss == null) { @@ -163,117 +165,108 @@ public class EjbDeploymentConfiguration return jboss; } /** * Listen to jboss.xml document changes. */ public synchronized void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName() == DataObject.PROP_MODIFIED && - evt.getNewValue() == Boolean.FALSE) { + evt.getNewValue() == Boolean.FALSE) { if (evt.getSource() == deploymentDescriptorDO) // dataobject has been modified, jboss graph is out of sync jboss = null; else super.propertyChange(evt); } } - + public void fireXpathEvent(XpathEvent xpe) { if (!xpe.isAddEvent()) return; DDBean eventDDBean = xpe.getBean(); if (SESSION_RESOURCE_REF.equals(eventDDBean.getXpath()) || - ENTITY_RESOURCE_REF.equals(eventDDBean.getXpath()) || - MSGDRV_RESOURCE_REF.equals(eventDDBean.getXpath())) - { + ENTITY_RESOURCE_REF.equals(eventDDBean.getXpath()) || + MSGDRV_RESOURCE_REF.equals(eventDDBean.getXpath())) { String[] desc = eventDDBean.getText("description"); // NOI18N String[] name = eventDDBean.getText("res-ref-name"); // NOI18N String[] type = eventDDBean.getText("res-type"); // NOI18N if (name.length > 0 && type.length > 0) { try { //we don't know which bean contains the created resource-ref, //thus we must find all beans containing the same resource-ref //as the one just created - BEAN_TYPE beanType = (SESSION_RESOURCE_REF.equals(eventDDBean.getXpath()) ? - BEAN_TYPE.SESSION : (ENTITY_RESOURCE_REF.equals(eventDDBean.getXpath()) ? - BEAN_TYPE.ENTITY : BEAN_TYPE.MSGDRV)); - + BEAN_TYPE beanType = (SESSION_RESOURCE_REF.equals(eventDDBean.getXpath()) ? + BEAN_TYPE.SESSION : (ENTITY_RESOURCE_REF.equals(eventDDBean.getXpath()) ? + BEAN_TYPE.ENTITY : BEAN_TYPE.MSGDRV)); + if (beanType != BEAN_TYPE.MSGDRV) { //sessions and entities Set beanNames = null; if (desc.length > 0 && "javax.sql.DataSource".equals(type[0])) { // NOI18N beanNames = getRelevantBeansDataRef(desc[0], name[0], eventDDBean.getRoot(), beanType); addResReference(desc[0], name[0], beanNames, beanType); - } - else - if ("javax.mail.Session".equals(type[0])) { // NOI18N + } else + if ("javax.mail.Session".equals(type[0])) { // NOI18N beanNames = getRelevantBeansMailRef(name[0], eventDDBean.getRoot(), beanType); addMailReference(name[0], beanNames, beanType); - } - else - if ("javax.jms.ConnectionFactory".equals(type[0])) { // NOI18N + } else + if ("javax.jms.ConnectionFactory".equals(type[0])) { // NOI18N beanNames = getRelevantBeansConnectionFactoryRef(name[0], eventDDBean.getRoot(), beanType); addConnectionFactoryReference(name[0], beanNames, beanType); - } - } - else { // message-driven beans + } + } else { // message-driven beans Map beans = null; if (desc.length > 0 && "javax.sql.DataSource".equals(type[0])) { // NOI18N beans = getRelevantMsgDrvBeansDataRef(desc[0], name[0], eventDDBean.getRoot()); addMsgDrvResReference(desc[0], name[0], beans); } if ("javax.mail.Session".equals(type[0])) { // NOI18N beans = getRelevantMsgDrvBeansMailRef(name[0], eventDDBean.getRoot()); addMsgDrvMailReference(name[0], beans); - } - else - if ("javax.jms.ConnectionFactory".equals(type[0])) { // NOI18N + } else + if ("javax.jms.ConnectionFactory".equals(type[0])) { // NOI18N beans = getRelevantMsgDrvBeansConnectionFactoryRef(name[0], eventDDBean.getRoot()); addMsgDrvConnectionFactoryReference(name[0], beans); - } + } } - + } catch (ConfigurationException ce) { ErrorManager.getDefault().notify(ce); } } - } - else if (SESSION_EJB_REF.equals(eventDDBean.getXpath()) || - ENTITY_EJB_REF.equals(eventDDBean.getXpath()) || - MSGDRV_EJB_REF.equals(eventDDBean.getXpath())) - { + } else if (SESSION_EJB_REF.equals(eventDDBean.getXpath()) || + ENTITY_EJB_REF.equals(eventDDBean.getXpath()) || + MSGDRV_EJB_REF.equals(eventDDBean.getXpath())) { String[] name = eventDDBean.getText("ejb-ref-name"); // NOI18N String[] type = eventDDBean.getText("ejb-ref-type"); // NOI18N - if (name.length > 0 && type.length > 0 + if (name.length > 0 && type.length > 0 && ("Session".equals(type[0]) || "Entity".equals(type[0]))) { // NOI18N try { //we don't know which bean contains the created ejb-ref, //thus we must find all beans containing the same ejb-ref //as the one just created - BEAN_TYPE beanType = (SESSION_EJB_REF.equals(eventDDBean.getXpath()) ? - BEAN_TYPE.SESSION : (ENTITY_EJB_REF.equals(eventDDBean.getXpath()) ? - BEAN_TYPE.ENTITY : BEAN_TYPE.MSGDRV)); - + BEAN_TYPE beanType = (SESSION_EJB_REF.equals(eventDDBean.getXpath()) ? + BEAN_TYPE.SESSION : (ENTITY_EJB_REF.equals(eventDDBean.getXpath()) ? + BEAN_TYPE.ENTITY : BEAN_TYPE.MSGDRV)); + if (beanType != BEAN_TYPE.MSGDRV) { //sessions and entities Set beanNames = getRelevantBeansEjbRef(name[0], eventDDBean.getRoot(), beanType); addEjbReference(name[0], beanNames, beanType); - } - else { // message-driven beans + } else { // message-driven beans Map beans = getRelevantMsgDrvBeansEjbRef(name[0], eventDDBean.getRoot()); addMsgDrvEjbReference(name[0], beans); } - + } catch (ConfigurationException ce) { ErrorManager.getDefault().notify(ce); } } - } - else if (MSGDRV.equals(eventDDBean.getXpath())) { + } else if (MSGDRV.equals(eventDDBean.getXpath())) { if (isEJB3) { // do not generate MDB destination reference for EJB3 modules (issue #82452) return; } String[] name = eventDDBean.getText("ejb-name"); // NOI18N String[] type = eventDDBean.getText("message-destination-type"); // NOI18N String[] dest = eventDDBean.getText("message-destination-link"); // NOI18N @@ -284,136 +277,133 @@ public class EjbDeploymentConfiguration tempEjbName = name[0]; } else { try { addMDB(name[0], dest[0]); } catch (ConfigurationException ce) { ErrorManager.getDefault().notify(ce); } } - } - else if (MSGDRV_MSG_DEST.equals(eventDDBean.getXpath())) { //is fired right after the MSGDRV Xpath event, too + } else if (MSGDRV_MSG_DEST.equals(eventDDBean.getXpath())) { //is fired right after the MSGDRV Xpath event, too if (isEJB3) { // do not generate MDB destination reference for EJB3 modules (issue #82452) return; } - + if (tempEjbName == null) // MSGDRV was not fired before return; try { String dest = xpe.getBean().getText(); addMDB(tempEjbName, dest); } catch (ConfigurationException ce) { ErrorManager.getDefault().notify(ce); } finally { tempEjbName = null; } } else if (SESSION_MSG_DEST_REF.equals(eventDDBean.getXpath()) || - ENTITY_MSG_DEST_REF.equals(eventDDBean.getXpath()) || - MSGDRV_MSG_DEST_REF.equals(eventDDBean.getXpath())) - { + ENTITY_MSG_DEST_REF.equals(eventDDBean.getXpath()) || + MSGDRV_MSG_DEST_REF.equals(eventDDBean.getXpath())) { String[] name = eventDDBean.getText("message-destination-ref-name"); // NOI18N String[] type = eventDDBean.getText("message-destination-type"); // NOI18N if (name.length > 0) { String destPrefix = ""; if (type.length > 0) { if (type[0].equals("javax.jms.Queue")) // NOI18N destPrefix = JBOSS4_MSG_QUEUE_JNDI_PREFIX; else - if (type[0].equals("javax.jms.Topic")) // NOI18N - destPrefix = JBOSS4_MSG_TOPIC_JNDI_PREFIX; + if (type[0].equals("javax.jms.Topic")) // NOI18N + destPrefix = JBOSS4_MSG_TOPIC_JNDI_PREFIX; } try { //we don't know which bean contains the created resource-ref, //thus we must find all beans containing the same resource-ref //as the one just created - BEAN_TYPE beanType = (SESSION_MSG_DEST_REF.equals(eventDDBean.getXpath()) ? - BEAN_TYPE.SESSION : (ENTITY_MSG_DEST_REF.equals(eventDDBean.getXpath()) ? - BEAN_TYPE.ENTITY : BEAN_TYPE.MSGDRV)); - + BEAN_TYPE beanType = (SESSION_MSG_DEST_REF.equals(eventDDBean.getXpath()) ? + BEAN_TYPE.SESSION : (ENTITY_MSG_DEST_REF.equals(eventDDBean.getXpath()) ? + BEAN_TYPE.ENTITY : BEAN_TYPE.MSGDRV)); + if (beanType != BEAN_TYPE.MSGDRV) { //sessions and entities Set beanNames = getRelevantBeansMsgDestRef(name[0], eventDDBean.getRoot(), beanType); addMsgDestReference(name[0], destPrefix, beanNames, beanType); - } - else { // message-driven beans + } else { // message-driven beans Map beans = getRelevantMsgDrvBeansMsgDestRef(name[0], eventDDBean.getRoot()); addMsgDrvMsgDestReference(name[0], destPrefix, beans); } - + } catch (ConfigurationException ce) { ErrorManager.getDefault().notify(ce); } } } } /** - * Searches for the beans of the give type referring to the given data source. + * Searches for the beans of the give type referring to the given data source. * It returns the names for the beans found. * * @param desc searched data source description tag value * @param resRefName searched data source (res-ref-name tag value) * @param root root bean to search from * @param beanType type of bean to search for * - * @return set of the names (ejb-name) of the beans refering to the resource-ref + * @return set of the names (ejb-name) of the beans refering to the resource-ref * with the same description and res-ref-name */ private Set getRelevantBeansDataRef(String desc, String resRefName, DDBeanRoot root, BEAN_TYPE beanType) { Set beanNames = new HashSet(); DDBean[] beans = root.getChildBean("/ejb-jar/enterprise-beans/" + beanType.getType()); // NOI18N for (int i = 0; i < beans.length; i++) { DDBean bean = beans[i]; DDBean[] resRefs = bean.getChildBean("resource-ref"); for (int j = 0; resRefs != null && j < resRefs.length; j++) { String[] descs = resRefs[j].getText("description"); // NOI18N String[] names = resRefs[j].getText("res-ref-name"); // NOI18N String[] types = resRefs[j].getText("res-type"); // NOI18N if (descs.length > 0 && names.length > 0 && types.length > 0 && - descs[0].equals(desc) && names[0].equals(resRefName) && "javax.sql.DataSource".equals(types[0])) { // NOI18N + descs[0].equals(desc) && names[0].equals(resRefName) && "javax.sql.DataSource".equals(types[0])) { // NOI18N //store bean's ejb-name tag value beanNames.add(bean.getChildBean("ejb-name")[0].getText()); // NOI18N break; } } } return beanNames; } /** - * Searches for the message-driven beans referring to the given resource. + * Searches for the message-driven beans referring to the given resource. * It returns the names and message destination links for the beans found. * * @param desc searched data source description tag value * @param resRefName searched res-ref-name tag value * @param root root bean to search from * - * @return map where the keys are the bean names (ejb-name) and + * @return map where the keys are the bean names (ejb-name) and * the values are the message destinations (message-destination-link) */ private Map getRelevantMsgDrvBeansDataRef(String desc, String resRefName, DDBeanRoot root) { HashMap/**/ beanMap = new HashMap(); // maps ejb-name to message-destination-link DDBean[] beans = root.getChildBean("/ejb-jar/enterprise-beans/message-driven"); // NOI18N for (int i = 0; i < beans.length; i++) { DDBean bean = beans[i]; DDBean[] resRefs = bean.getChildBean("resource-ref"); for (int j = 0; resRefs != null && j < resRefs.length; j++) { String[] descs = resRefs[j].getText("description"); // NOI18N String[] names = resRefs[j].getText("res-ref-name"); // NOI18N String[] types = resRefs[j].getText("res-type"); // NOI18N if (descs.length > 0 && names.length > 0 && types.length > 0 && - descs[0].equals(desc) && names[0].equals(resRefName) && "javax.sql.DataSource".equals(types[0])) { // NOI18N + descs[0].equals(desc) && names[0].equals(resRefName) && "javax.sql.DataSource".equals(types[0])) { // NOI18N //store bean's ejb-name and message-destination-link tag values String key = bean.getChildBean("ejb-name")[0].getText(); String value = ""; if (bean.getChildBean("message-destination-link").length > 0) // NOI18N value = bean.getChildBean("message-destination-link")[0].getText(); beanMap.put(key, value); // NOI18N break; } @@ -423,205 +413,205 @@ public class EjbDeploymentConfiguration return beanMap; } /** * @param ejbRefName searched ejb-ref-name tag value * @param root root bean to search from * @param beanType type of bean to search for * - * @return set of the names (ejb-name) of the beans refering to the ejb-ref + * @return set of the names (ejb-name) of the beans refering to the ejb-ref * with the same ejb-ref-name */ private Set getRelevantBeansEjbRef(String ejbRefName, DDBeanRoot root, BEAN_TYPE beanType) { Set beanNames = new HashSet(); DDBean[] beans = root.getChildBean("/ejb-jar/enterprise-beans/" + beanType.getType()); // NOI18N for (int i = 0; i < beans.length; i++) { DDBean bean = beans[i]; DDBean[] ejbRefs = bean.getChildBean("ejb-ref"); for (int j = 0; ejbRefs != null && j < ejbRefs.length; j++) { String[] names = ejbRefs[j].getText("ejb-ref-name"); // NOI18N String[] types = ejbRefs[j].getText("ejb-ref-type"); // NOI18N - if (names.length > 0 && types.length > 0 && names[0].equals(ejbRefName) - && ("Session".equals(types[0]) || "Entity".equals(types[0]))) { // NOI18N + if (names.length > 0 && types.length > 0 && names[0].equals(ejbRefName) + && ("Session".equals(types[0]) || "Entity".equals(types[0]))) { // NOI18N //store bean's ejb-name tag value beanNames.add(bean.getChildBean("ejb-name")[0].getText()); // NOI18N break; } } } return beanNames; } interface JbossModifier { public void modify(Jboss modifiedJboss); } /** - * Searches for the message-driven beans referring to the given ejb. + * Searches for the message-driven beans referring to the given ejb. * It returns the names and message destination links for the beans found. * * @param ejbRefName searched ejb-ref-name tag value * @param root root bean to search from * - * @return map where the keys are the bean names (ejb-name) and + * @return map where the keys are the bean names (ejb-name) and * the values are the message destinations (message-destination-link) */ private Map getRelevantMsgDrvBeansEjbRef(String ejbRefName, DDBeanRoot root) { HashMap/**/ beanMap = new HashMap(); // maps ejb-name to message-destination-link DDBean[] beans = root.getChildBean("/ejb-jar/enterprise-beans/message-driven"); // NOI18N for (int i = 0; i < beans.length; i++) { DDBean bean = beans[i]; DDBean[] ejbRefs = bean.getChildBean("ejb-ref"); for (int j = 0; ejbRefs != null && j < ejbRefs.length; j++) { String[] names = ejbRefs[j].getText("ejb-ref-name"); // NOI18N String[] types = ejbRefs[j].getText("ejb-ref-type"); // NOI18N - if (names.length > 0 && types.length > 0 && names[0].equals(ejbRefName) - && ("Session".equals(types[0]) || "Entity".equals(types[0]))) { // NOI18N + if (names.length > 0 && types.length > 0 && names[0].equals(ejbRefName) + && ("Session".equals(types[0]) || "Entity".equals(types[0]))) { // NOI18N //store bean's ejb-name and message-destination-link tag values String key = bean.getChildBean("ejb-name")[0].getText(); String value = ""; if (bean.getChildBean("message-destination-link").length > 0) // NOI18N value = bean.getChildBean("message-destination-link")[0].getText(); beanMap.put(key, value); // NOI18N break; } } } return beanMap; } /** - * Searches for the beans of the give type referring to the given mail service. + * Searches for the beans of the give type referring to the given mail service. * It returns the names for the beans found. * * @param resRefName searched mail service (res-ref-name tag value) * @param root root bean to search from * @param beanType type of bean to search for * - * @return set of the names (ejb-name) of the beans refering to the resource-ref + * @return set of the names (ejb-name) of the beans refering to the resource-ref * with the same description and res-ref-name */ private Set getRelevantBeansMailRef(String resRefName, DDBeanRoot root, BEAN_TYPE beanType) { Set beanNames = new HashSet(); DDBean[] beans = root.getChildBean("/ejb-jar/enterprise-beans/" + beanType.getType()); // NOI18N for (int i = 0; i < beans.length; i++) { DDBean bean = beans[i]; DDBean[] resRefs = bean.getChildBean("resource-ref"); for (int j = 0; resRefs != null && j < resRefs.length; j++) { String[] names = resRefs[j].getText("res-ref-name"); // NOI18N String[] types = resRefs[j].getText("res-type"); // NOI18N if (names.length > 0 && types.length > 0 && - names[0].equals(resRefName) && "javax.mail.Session".equals(types[0])) { // NOI18N + names[0].equals(resRefName) && "javax.mail.Session".equals(types[0])) { // NOI18N //store bean's ejb-name tag value beanNames.add(bean.getChildBean("ejb-name")[0].getText()); // NOI18N break; } } } return beanNames; } /** - * Searches for the message-driven beans referring to the given mail service. + * Searches for the message-driven beans referring to the given mail service. * It returns the names and message destination links for the beans found. * * @param resRefName searched res-ref-name tag value * @param root root bean to search from * - * @return map where the keys are the bean names (ejb-name) and + * @return map where the keys are the bean names (ejb-name) and * the values are the message destinations (message-destination-link) */ private Map getRelevantMsgDrvBeansMailRef(String resRefName, DDBeanRoot root) { HashMap/**/ beanMap = new HashMap(); // maps ejb-name to message-destination-link DDBean[] beans = root.getChildBean("/ejb-jar/enterprise-beans/message-driven"); // NOI18N for (int i = 0; i < beans.length; i++) { DDBean bean = beans[i]; DDBean[] resRefs = bean.getChildBean("resource-ref"); for (int j = 0; resRefs != null && j < resRefs.length; j++) { String[] names = resRefs[j].getText("res-ref-name"); // NOI18N String[] types = resRefs[j].getText("res-type"); // NOI18N if (names.length > 0 && types.length > 0 && - names[0].equals(resRefName) && "javax.mail.Session".equals(types[0])) { // NOI18N + names[0].equals(resRefName) && "javax.mail.Session".equals(types[0])) { // NOI18N //store bean's ejb-name and message-destination-link tag values String key = bean.getChildBean("ejb-name")[0].getText(); String value = ""; if (bean.getChildBean("message-destination-link").length > 0) // NOI18N value = bean.getChildBean("message-destination-link")[0].getText(); beanMap.put(key, value); // NOI18N break; } } } return beanMap; } /** - * Searches for the beans of the given type referring to the given connection factory. + * Searches for the beans of the given type referring to the given connection factory. * It returns the names for the beans found. * * @param resRefName searched connection factory (res-ref-name tag value) * @param root root bean to search from * @param beanType type of bean to search for * - * @return set of the names (ejb-name) of the beans refering to the resource-ref + * @return set of the names (ejb-name) of the beans refering to the resource-ref * with the same res-ref-name */ private Set getRelevantBeansConnectionFactoryRef(String resRefName, DDBeanRoot root, BEAN_TYPE beanType) { Set beanNames = new HashSet(); DDBean[] beans = root.getChildBean("/ejb-jar/enterprise-beans/" + beanType.getType()); // NOI18N for (int i = 0; i < beans.length; i++) { DDBean bean = beans[i]; DDBean[] resRefs = bean.getChildBean("resource-ref"); for (int j = 0; resRefs != null && j < resRefs.length; j++) { String[] names = resRefs[j].getText("res-ref-name"); // NOI18N String[] types = resRefs[j].getText("res-type"); // NOI18N if (names.length > 0 && types.length > 0 && - names[0].equals(resRefName) && "javax.jms.ConnectionFactory".equals(types[0])) { // NOI18N + names[0].equals(resRefName) && "javax.jms.ConnectionFactory".equals(types[0])) { // NOI18N //store bean's ejb-name tag value beanNames.add(bean.getChildBean("ejb-name")[0].getText()); // NOI18N break; } } } return beanNames; } - + /** - * Searches for the message-driven beans referring to the given connection factory. + * Searches for the message-driven beans referring to the given connection factory. * It returns the names and message destination links for the beans found. * * @param resRefName searched res-ref-name tag value * @param root root bean to search from * - * @return map where the keys are the bean names (ejb-name) and + * @return map where the keys are the bean names (ejb-name) and * the values are the message destinations (message-destination-link) */ private Map getRelevantMsgDrvBeansConnectionFactoryRef(String resRefName, DDBeanRoot root) { HashMap/**/ beanMap = new HashMap(); // maps ejb-name to message-destination-link DDBean[] beans = root.getChildBean("/ejb-jar/enterprise-beans/message-driven"); // NOI18N for (int i = 0; i < beans.length; i++) { DDBean bean = beans[i]; DDBean[] resRefs = bean.getChildBean("resource-ref"); for (int j = 0; resRefs != null && j < resRefs.length; j++) { String[] names = resRefs[j].getText("res-ref-name"); // NOI18N String[] types = resRefs[j].getText("res-type"); // NOI18N if (names.length > 0 && types.length > 0 && - names[0].equals(resRefName) && "javax.jms.ConnectionFactory".equals(types[0])) { // NOI18N + names[0].equals(resRefName) && "javax.jms.ConnectionFactory".equals(types[0])) { // NOI18N //store bean's ejb-name and message-destination-link tag values String key = bean.getChildBean("ejb-name")[0].getText(); String value = ""; if (bean.getChildBean("message-destination-link").length > 0) // NOI18N value = bean.getChildBean("message-destination-link")[0].getText(); beanMap.put(key, value); // NOI18N break; } @@ -631,17 +621,17 @@ public class EjbDeploymentConfiguration return beanMap; } /** * @param msgDestRefName searched message-destination-ref tag value * @param root root bean to search from * @param beanType type of bean to search for * - * @return set of the names (ejb-name) of the beans refering to the message-destination-ref + * @return set of the names (ejb-name) of the beans refering to the message-destination-ref * with the same message-destination-ref-name */ private Set getRelevantBeansMsgDestRef(String msgDestRefName, DDBeanRoot root, BEAN_TYPE beanType) { Set beanNames = new HashSet(); DDBean[] beans = root.getChildBean("/ejb-jar/enterprise-beans/" + beanType.getType()); // NOI18N for (int i = 0; i < beans.length; i++) { DDBean bean = beans[i]; @@ -659,17 +649,17 @@ public class EjbDeploymentConfiguration return beanNames; } /** * @param msgDestRefName searched message-destination-ref tag value * @param root root bean to search from * @param beanType type of bean to search for * - * @return set of the names (ejb-name) of the beans refering to the message-destination-ref + * @return set of the names (ejb-name) of the beans refering to the message-destination-ref * with the same message-destination-ref-name */ private Map getRelevantMsgDrvBeansMsgDestRef(String msgDestRefName, DDBeanRoot root) { HashMap/**/ beanMap = new HashMap(); // maps ejb-name to message-destination-link DDBean[] beans = root.getChildBean("/ejb-jar/enterprise-beans/message-driven"); // NOI18N for (int i = 0; i < beans.length; i++) { DDBean bean = beans[i]; @@ -688,236 +678,225 @@ public class EjbDeploymentConfiguration } } return beanMap; } /** * Add a new data source reference to the beans of the given type without it. - * + * * @param desc data source description * @param resRefName data source reference name * @param beanNames the beans (ejb-name value) which might need to add data source reference specified by resRefName * @param beanType type of bean to add data source reference to */ - private void addResReference(String desc, final String resRefName, final Set beanNames, final BEAN_TYPE beanType) - throws ConfigurationException - { + private void addResReference(String desc, final String resRefName, final Set beanNames, final BEAN_TYPE beanType) + throws ConfigurationException { modifyJboss(new JbossModifier() { - public void modify(Jboss modifiedJboss) { - String jndiName = JBDeploymentConfiguration.JBOSS4_DATASOURCE_JNDI_PREFIX + resRefName; - JbossDataSourceRefModifier.modify(modifiedJboss, resRefName, beanNames, beanType, jndiName); - } + public void modify(Jboss modifiedJboss) { + String jndiName = JBDeploymentConfiguration.JBOSS4_DATASOURCE_JNDI_PREFIX + resRefName; + JbossDataSourceRefModifier.modify(modifiedJboss, resRefName, beanNames, beanType, jndiName); + } }); } - + /** * Add a new resource reference to the message-driven beans without it. - * + * * @param desc data source description * @param resRefName resource reference name * @param beans the bean names (ejb-name) mapped to the message destinations (message-destination-link) * which might need to add resource reference specified by resRefName */ - private void addMsgDrvResReference(String desc, final String resRefName, final Map beans) - throws ConfigurationException - { + private void addMsgDrvResReference(String desc, final String resRefName, final Map beans) + throws ConfigurationException { modifyJboss(new JbossModifier() { - public void modify(Jboss modifiedJboss) { - String jndiName = JBDeploymentConfiguration.JBOSS4_DATASOURCE_JNDI_PREFIX + resRefName; - JbossDataSourceRefModifier.modifyMsgDrv(modifiedJboss, resRefName, beans, jndiName); - } + public void modify(Jboss modifiedJboss) { + String jndiName = JBDeploymentConfiguration.JBOSS4_DATASOURCE_JNDI_PREFIX + resRefName; + JbossDataSourceRefModifier.modifyMsgDrv(modifiedJboss, resRefName, beans, jndiName); + } }); } - + /** * Add a new ejb reference to the beans of the given type without it. - * + * * @param ejbRefName ejb reference name * @param beanNames the beans (ejb-name value) which might need to add ejb reference specified by ejbRefName * @param beanType type of bean to add ejb reference to */ - private void addEjbReference(final String ejbRefName, final Set beanNames, final BEAN_TYPE beanType) - throws ConfigurationException - { + private void addEjbReference(final String ejbRefName, final Set beanNames, final BEAN_TYPE beanType) + throws ConfigurationException { modifyJboss(new JbossModifier() { - public void modify(Jboss modifiedJboss) { - JbossEjbRefModifier.modify(modifiedJboss, ejbRefName, beanNames, beanType); - } + public void modify(Jboss modifiedJboss) { + JbossEjbRefModifier.modify(modifiedJboss, ejbRefName, beanNames, beanType); + } }); } - + /** * Add a new ejb reference to the message-driven beans without it. - * + * * @param ejbRefName ejb reference name * @param beans the bean names (ejb-name) mapped to the message destinations (message-destination-link) * which might need to add ejb reference specified by ejbRefName */ - private void addMsgDrvEjbReference(final String ejbRefName, final Map beans) - throws ConfigurationException - { + private void addMsgDrvEjbReference(final String ejbRefName, final Map beans) + throws ConfigurationException { modifyJboss(new JbossModifier() { - public void modify(Jboss modifiedJboss) { - JbossEjbRefModifier.modifyMsgDrv(modifiedJboss, ejbRefName, beans); - } + public void modify(Jboss modifiedJboss) { + JbossEjbRefModifier.modifyMsgDrv(modifiedJboss, ejbRefName, beans); + } }); } - + /** * Add a new mail service reference to the beans of the given type without it. - * + * * @param resRefName mail service reference name * @param beanNames the beans (ejb-name value) which might need to add mail service reference specified by resRefName * @param beanType type of bean to add mail service reference to */ - private void addMailReference(final String resRefName, final Set beanNames, final BEAN_TYPE beanType) - throws ConfigurationException - { + private void addMailReference(final String resRefName, final Set beanNames, final BEAN_TYPE beanType) + throws ConfigurationException { modifyJboss(new JbossModifier() { - public void modify(Jboss modifiedJboss) { - String jndiName = JBOSS4_MAIL_SERVICE_JNDI_NAME; - JbossDataSourceRefModifier.modify(modifiedJboss, resRefName, beanNames, beanType, jndiName); - } + public void modify(Jboss modifiedJboss) { + String jndiName = JBOSS4_MAIL_SERVICE_JNDI_NAME; + JbossDataSourceRefModifier.modify(modifiedJboss, resRefName, beanNames, beanType, jndiName); + } }); } - + /** * Add a new mail service reference to the message-driven beans without it. - * + * * @param resRefName mail service reference name * @param beans the bean names (ejb-name) mapped to the message destinations (message-destination-link) * which might need to add mail service reference specified by resRefName */ - private void addMsgDrvMailReference(final String resRefName, final Map beans) - throws ConfigurationException - { + private void addMsgDrvMailReference(final String resRefName, final Map beans) + throws ConfigurationException { modifyJboss(new JbossModifier() { - public void modify(Jboss modifiedJboss) { - String jndiName = JBOSS4_MAIL_SERVICE_JNDI_NAME; - JbossDataSourceRefModifier.modifyMsgDrv(modifiedJboss, resRefName, beans, jndiName); - } + public void modify(Jboss modifiedJboss) { + String jndiName = JBOSS4_MAIL_SERVICE_JNDI_NAME; + JbossDataSourceRefModifier.modifyMsgDrv(modifiedJboss, resRefName, beans, jndiName); + } }); } - + /** * Add MDB record. - * + * * @param name MDB name (ejb-name) * @param dest MDB destination (message-destination-link) */ private void addMDB(final String name, final String dest) throws ConfigurationException { modifyJboss(new JbossModifier() { public void modify(Jboss modifiedJboss) { - + EnterpriseBeans eb = modifiedJboss.getEnterpriseBeans(); if (eb == null) { eb = new EnterpriseBeans(); modifiedJboss.setEnterpriseBeans(eb); } // check whether mdb not already defined MessageDriven[] mdbs = eb.getMessageDriven(); for (int i = 0; i < mdbs.length; i++) { String en = mdbs[i].getEjbName(); if (name.equals(en)) { // already exists return; } } - + //if it doesn't exist yet, create a new one MessageDriven mdb = new MessageDriven(); mdb.setEjbName(name); mdb.setDestinationJndiName(dest); // NOI18N eb.addMessageDriven(mdb); } }); } - + /** * Add a new connection factory reference to the beans of the given type without it. - * + * * @param resRefName connection factory reference name * @param beanNames the beans (ejb-name value) which might need to add connection factory reference specified by resRefName * @param beanType type of bean to add connection factory reference to */ - private void addConnectionFactoryReference(final String resRefName, final Set beanNames, final BEAN_TYPE beanType) - throws ConfigurationException - { + private void addConnectionFactoryReference(final String resRefName, final Set beanNames, final BEAN_TYPE beanType) + throws ConfigurationException { modifyJboss(new JbossModifier() { - public void modify(Jboss modifiedJboss) { - String jndiName = JBOSS4_CONN_FACTORY_JNDI_NAME; - JbossDataSourceRefModifier.modify(modifiedJboss, resRefName, beanNames, beanType, jndiName); - } + public void modify(Jboss modifiedJboss) { + String jndiName = JBOSS4_CONN_FACTORY_JNDI_NAME; + JbossDataSourceRefModifier.modify(modifiedJboss, resRefName, beanNames, beanType, jndiName); + } }); } - + /** * Add a new connection factory reference to the message-driven beans without it. - * + * * @param resRefName connection factory reference name * @param beans the bean names (ejb-name) mapped to the message destinations (message-destination-link) * which might need to add connection factory reference specified by resRefName */ - private void addMsgDrvConnectionFactoryReference(final String resRefName, final Map beans) - throws ConfigurationException - { - modifyJboss(new JbossModifier() { - public void modify(Jboss modifiedJboss) { - String jndiName = JBOSS4_CONN_FACTORY_JNDI_NAME; - JbossDataSourceRefModifier.modifyMsgDrv(modifiedJboss, resRefName, beans, jndiName); - } + private void addMsgDrvConnectionFactoryReference(final String resRefName, final Map beans) + throws ConfigurationException { + modifyJboss(new JbossModifier() { + public void modify(Jboss modifiedJboss) { + String jndiName = JBOSS4_CONN_FACTORY_JNDI_NAME; + JbossDataSourceRefModifier.modifyMsgDrv(modifiedJboss, resRefName, beans, jndiName); + } }); } /** * Add a new message destination reference to the beans of the given type without it. - * + * * @param msgDestRefName message destination reference name * @param beanNames the beans (ejb-name value) which might need to add message destination reference specified by msgDestRefName * @param beanType type of bean to add message destination reference to */ private void addMsgDestReference(final String msgDestRefName, final String destPrefix, - final Set beanNames, final BEAN_TYPE beanType) throws ConfigurationException - { + final Set beanNames, final BEAN_TYPE beanType) throws ConfigurationException { modifyJboss(new JbossModifier() { - public void modify(Jboss modifiedJboss) { - JbossMsgDestRefModifier.modify(modifiedJboss, msgDestRefName, beanNames, beanType, destPrefix); - } + public void modify(Jboss modifiedJboss) { + JbossMsgDestRefModifier.modify(modifiedJboss, msgDestRefName, beanNames, beanType, destPrefix); + } }); } - + /** * Add a new message destination reference to the message driven beans without it. - * + * * @param msgDestRefName message destination reference name * @param beanNames the beans (ejb-name value) which might need to add message destination reference specified by msgDestRefName * @param beanType type of bean to add message destination reference to */ private void addMsgDrvMsgDestReference(final String msgDestRefName, final String destPrefix, - final Map beans) throws ConfigurationException - { + final Map beans) throws ConfigurationException { modifyJboss(new JbossModifier() { - public void modify(Jboss modifiedJboss) { - JbossMsgDestRefModifier.modifyMsgDrv(modifiedJboss, msgDestRefName, beans, destPrefix); - } + public void modify(Jboss modifiedJboss) { + JbossMsgDestRefModifier.modifyMsgDrv(modifiedJboss, msgDestRefName, beans, destPrefix); + } }); } - + /** * Perform jboss changes defined by the jboss modifier. Update editor * content and save changes, if appropriate. * * @param modifier */ private void modifyJboss(JbossModifier modifier) - throws ConfigurationException - { + throws ConfigurationException { assert deploymentDescriptorDO != null : "DataObject has not been initialized yet"; // NIO18N try { // get the document EditorCookie editor = (EditorCookie)deploymentDescriptorDO.getCookie(EditorCookie.class); StyledDocument doc = editor.getDocument(); if (doc == null) { doc = editor.openDocument(); }