Index: build.xml =================================================================== RCS file: /cvs/serverplugins/jboss4/build.xml,v retrieving revision 1.6 retrieving revision 1.6.14.1 diff -u -r1.6 -r1.6.14.1 --- build.xml 12 Oct 2006 14:37:57 -0000 1.6 +++ build.xml 26 Mar 2007 09:47:56 -0000 1.6.14.1 @@ -67,6 +67,14 @@ removeUnreferencedNodes="true" docroot="datasources" rootDir="src"/> + 0 && "javax.sql.DataSource".equals(type[0])) { // NOI18N // beanNames = getRelevantBeansDataRef(desc[0], name[0], eventDDBean.getRoot(), beanType); -// addResReference(desc[0], name[0], beanNames, beanType); +// String jndiName = JBDeploymentConfiguration.JBOSS4_DATASOURCE_JNDI_PREFIX + resRefName; +// addResReference(jndiName, name[0], beanNames, beanType); // } // else // if ("javax.mail.Session".equals(type[0])) { // NOI18N @@ -724,21 +732,89 @@ return beanMap; } + + public void bindDatasourceReferenceEjb(String dsReferenceName, String dsJNDIName, + String ejbName, String ejbType) throws ConfigurationException { + Set beanNames = new HashSet(); + beanNames.add(ejbName); + BEAN_TYPE beanType = BEAN_TYPE.SESSION; + if (org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.ENTITY.equals(ejbType)) { + beanType = BEAN_TYPE.ENTITY; + } + else + if (org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.MESSAGE_DRIVEN.equals(ejbType)) { + beanType = BEAN_TYPE.MSGDRV; + } + + addResReference(dsJNDIName, dsReferenceName, beanNames, beanType); + } + + public String findDatasourceBindingEjb(String dsReferenceName, String ejbName) throws ConfigurationException { + + EnterpriseBeans beans = getJboss().getEnterpriseBeans(); + if (beans == null) { + return null; + } + + Session[] sessions = beans.getSession(); + for (Session session : sessions) { + if (ejbName.equals(session.getEjbName())) { + ResourceRef[] resourceRefs = session.getResourceRef(); + for (ResourceRef resourceRef : resourceRefs) { + String rrn = resourceRef.getResRefName(); + if (dsReferenceName.equals(rrn)) { + return resourceRef.getJndiName(); + } + } + return null; + } + } + + Entity[] entities = beans.getEntity(); + for (Entity entity : entities) { + if (ejbName.equals(entity.getEjbName())) { + ResourceRef[] resourceRefs = entity.getResourceRef(); + for (ResourceRef resourceRef : resourceRefs) { + String rrn = resourceRef.getResRefName(); + if (dsReferenceName.equals(rrn)) { + return resourceRef.getJndiName(); + } + } + return null; + } + } + + MessageDriven[] mdbs = beans.getMessageDriven(); + for (MessageDriven mdb : mdbs) { + if (ejbName.equals(mdb.getEjbName())) { + ResourceRef[] resourceRefs = mdb.getResourceRef(); + for (ResourceRef resourceRef : resourceRefs) { + String rrn = resourceRef.getResRefName(); + if (dsReferenceName.equals(rrn)) { + return resourceRef.getJndiName(); + } + } + return null; + } + } + + return null; + } + /** * Add a new data source reference to the beans of the given type without it. * - * @param desc data source description + * @param jndiName JNDI name of the resource * @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) + private void addResReference(final String jndiName, 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); } }); Index: src/org/netbeans/modules/j2ee/jboss4/config/JBDeploymentConfiguration.java =================================================================== RCS file: /cvs/serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/JBDeploymentConfiguration.java,v retrieving revision 1.4.6.2 retrieving revision 1.4.6.2.2.1 diff -u -r1.4.6.2 -r1.4.6.2.2.1 --- src/org/netbeans/modules/j2ee/jboss4/config/JBDeploymentConfiguration.java 23 Mar 2007 20:53:52 -0000 1.4.6.2 +++ src/org/netbeans/modules/j2ee/jboss4/config/JBDeploymentConfiguration.java 26 Mar 2007 09:47:57 -0000 1.4.6.2.2.1 @@ -13,7 +13,7 @@ * "Portions Copyrighted [year] [name of copyright owner]" * * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun * Microsystems, Inc. All Rights Reserved. */ @@ -25,23 +25,21 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.io.OutputStream; import java.util.HashSet; import java.util.Set; -import javax.enterprise.deploy.model.DDBeanRoot; -import javax.enterprise.deploy.spi.DConfigBeanRoot; -import javax.enterprise.deploy.spi.exceptions.BeanNotFoundException; -import javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException; import javax.swing.text.BadLocationException; import javax.swing.text.StyledDocument; import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException; import org.netbeans.modules.j2ee.deployment.common.api.Datasource; import org.netbeans.modules.j2ee.deployment.common.api.DatasourceAlreadyExistsException; +import org.netbeans.modules.j2ee.deployment.common.api.MessageDestination; import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; import org.netbeans.modules.j2ee.deployment.plugins.spi.config.DatasourceConfiguration; +import org.netbeans.modules.j2ee.deployment.plugins.spi.config.MessageDestinationConfiguration; import org.netbeans.modules.j2ee.jboss4.config.gen.Datasources; import org.netbeans.modules.j2ee.jboss4.config.gen.LocalTxDatasource; +import org.netbeans.modules.j2ee.jboss4.config.mdb.MessageDestinationSupport; import org.netbeans.modules.schema2beans.BaseBean; import org.openide.DialogDisplayer; import org.openide.ErrorManager; @@ -62,9 +60,11 @@ /** * Base for JBoss DeploymentConfiguration implementations. * - * @author Pavel Buzek, lkotouc + * @author Pavel Buzek, Libor Kotouc */ -public abstract class JBDeploymentConfiguration implements DatasourceConfiguration { +public abstract class JBDeploymentConfiguration + implements DatasourceConfiguration, MessageDestinationConfiguration { + protected static final String JBOSS4_DATASOURCE_JNDI_PREFIX = "java:"; // NOI18N protected static final String JBOSS4_MAIL_SERVICE_JNDI_NAME = "java:Mail"; // NOI18N @@ -92,6 +92,9 @@ //cached data object for the data source file private DataObject datasourcesDO; + //support for message destination resources + private MessageDestinationSupport destSupport; + /** Creates a new instance of JBDeploymentConfiguration */ public JBDeploymentConfiguration (J2eeModule j2eeModule) { this.j2eeModule = j2eeModule; @@ -114,7 +117,7 @@ // helper methods ------------------------------------------------- - protected void writefile(final File file, final BaseBean bean) throws ConfigurationException { + public static void writeFile(final File file, final BaseBean bean) throws ConfigurationException { try { FileObject cfolder = FileUtil.toFileObject(file.getParentFile()); if (cfolder == null) { @@ -261,7 +264,7 @@ } else { // create jboss-ds.xml if it does not exist yet datasources = new Datasources(); - writefile(datasourcesFile, datasources); + writeFile(datasourcesFile, datasources); } } catch (ConfigurationException ce) { ErrorManager.getDefault().notify(ce); @@ -408,5 +411,32 @@ }); } + public void bindDatasourceReference(String dsReferenceName, String dsJNDIName) throws ConfigurationException {} + + public void bindDatasourceReferenceEjb(String dsReferenceName, String dsJNDIName, + String ejbName, String ejbType) throws ConfigurationException {} + + public String findDatasourceBinding(String dsReferenceName) throws ConfigurationException { + return null; + } + + public String findDatasourceBindingEjb(String dsReferenceName, String ejbName) throws ConfigurationException { + return null; + } + + public Set getMessageDestinations() throws ConfigurationException { + if (destSupport == null) { + destSupport = new MessageDestinationSupport(resourceDir); + } + return destSupport.getMessageDestinations(); + } + + public MessageDestination createMessageDestination(String jndiName, MessageDestination.Type type) + throws UnsupportedOperationException, ConfigurationException { + if (destSupport == null) { + destSupport = new MessageDestinationSupport(resourceDir); + } + return destSupport.createMessageDestination(jndiName, type); + } } Index: src/org/netbeans/modules/j2ee/jboss4/config/JBossDatasourceManager.java =================================================================== RCS file: /cvs/serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/JBossDatasourceManager.java,v retrieving revision 1.2.6.3 retrieving revision 1.2.6.3.2.1 diff -u -r1.2.6.3 -r1.2.6.3.2.1 --- src/org/netbeans/modules/j2ee/jboss4/config/JBossDatasourceManager.java 1 Mar 2007 14:03:32 -0000 1.2.6.3 +++ src/org/netbeans/modules/j2ee/jboss4/config/JBossDatasourceManager.java 26 Mar 2007 09:47:57 -0000 1.2.6.3.2.1 @@ -13,7 +13,7 @@ * "Portions Copyrighted [year] [name of copyright owner]" * * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun * Microsystems, Inc. All Rights Reserved. */ @@ -90,7 +90,15 @@ FileObject dsFO = (FileObject)it.next(); File dsFile = FileUtil.toFile(dsFO); try { - Datasources ds = Datasources.createGraph(dsFile); + Datasources ds = null; + try { + ds = Datasources.createGraph(dsFile); + } catch (RuntimeException re) { + // most likely not a data source (e.g. jms-ds.xml in JBoss 5.x) + String msg = NbBundle.getMessage(JBossDatasourceManager.class, "MSG_NotParseableDatasources", dsFile.getAbsolutePath()); + ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, msg); + continue; + } LocalTxDatasource ltxds[] = ds.getLocalTxDatasource(); for (int i = 0; i < ltxds.length; i++) { if (ltxds[i].getJndiName().length() > 0) { Index: src/org/netbeans/modules/j2ee/jboss4/config/WarDeploymentConfiguration.java =================================================================== RCS file: /cvs/serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/WarDeploymentConfiguration.java,v retrieving revision 1.5.6.2 retrieving revision 1.5.6.2.2.1 diff -u -r1.5.6.2 -r1.5.6.2.2.1 --- src/org/netbeans/modules/j2ee/jboss4/config/WarDeploymentConfiguration.java 23 Mar 2007 20:53:52 -0000 1.5.6.2 +++ src/org/netbeans/modules/j2ee/jboss4/config/WarDeploymentConfiguration.java 26 Mar 2007 09:47:57 -0000 1.5.6.2.2.1 @@ -13,7 +13,7 @@ * "Portions Copyrighted [year] [name of copyright owner]" * * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun * Microsystems, Inc. All Rights Reserved. */ @@ -54,7 +54,7 @@ * Web module deployment configuration handles creation and updating of the * jboss-web.xml configuration file. * - * @author sherold, lkotouc + * @author Stepan Herold, Libor Kotouc */ public class WarDeploymentConfiguration extends JBDeploymentConfiguration implements ModuleConfiguration, ContextRootConfiguration, DatasourceConfiguration, @@ -100,6 +100,10 @@ return true; } + public boolean supportsCreateMessageDestination() { + return true; + } + /** * Return context path. * @@ -162,7 +166,7 @@ try { String resType = resourceRef.getResType(); if ("javax.sql.DataSource".equals(resType)) { // NOI18N - addResReference(resourceRef.getResRefName()); + addResReference(resourceRef.getResRefName(), JBOSS4_DATASOURCE_JNDI_PREFIX + resourceRef.getResRefName()); } else if ("javax.mail.Session".equals(resType)) { // NOI18N addMailReference(resourceRef.getResRefName()); } else if ("javax.jms.ConnectionFactory".equals(resType)) { // NOI18N @@ -197,12 +201,29 @@ } } + public void bindDatasourceReference(String dsReferenceName, String dsJNDIName) throws ConfigurationException { + addResReference(dsReferenceName, dsJNDIName); + } + + public String findDatasourceBinding(String dsReferenceName) throws ConfigurationException { + + ResourceRef resourceRefs[] = getJbossWeb().getResourceRef(); + for (ResourceRef resourceRef : resourceRefs) { + String rrn = resourceRef.getResRefName(); + if (dsReferenceName.equals(rrn)) { + return resourceRef.getJndiName(); + } + } + + return null; + } + /** * Add a new resource reference. * * @param name resource reference name */ - private void addResReference(final String name) throws ConfigurationException { + private void addResReference(final String name, final String jndiName) throws ConfigurationException { modifyJbossWeb(new JbossWebModifier() { public void modify(JbossWeb modifiedJbossWeb) { @@ -219,7 +240,7 @@ //if it doesn't exist yet, create a new one ResourceRef newRR = new ResourceRef(); newRR.setResRefName(name); - newRR.setJndiName(JBOSS4_DATASOURCE_JNDI_PREFIX + name); + newRR.setJndiName(jndiName); modifiedJbossWeb.addResourceRef(newRR); } }); @@ -366,7 +387,7 @@ } else { // create jboss-web.xml if it does not exist yet jbossWeb = generateJbossWeb(); - writefile(jbossWebFile, jbossWeb); + writeFile(jbossWebFile, jbossWeb); } } catch (ConfigurationException ce) { ErrorManager.getDefault().notify(ce); Index: src/org/netbeans/modules/j2ee/jboss4/config/mdb/JBossMessageDestination.java =================================================================== RCS file: src/org/netbeans/modules/j2ee/jboss4/config/mdb/JBossMessageDestination.java diff -N src/org/netbeans/modules/j2ee/jboss4/config/mdb/JBossMessageDestination.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/netbeans/modules/j2ee/jboss4/config/mdb/JBossMessageDestination.java 26 Mar 2007 09:54:58 -0000 1.1.2.1 @@ -0,0 +1,46 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.modules.j2ee.jboss4.config.mdb; + +import org.netbeans.modules.j2ee.deployment.common.api.MessageDestination; + +/** + * + * @author Libor Kotouc + */ +public class JBossMessageDestination implements MessageDestination { + + private String jndiName; + private Type type; + + public JBossMessageDestination(String jndiName, Type type) { + this.jndiName = jndiName; + this.type = type; + } + + public String getJndiName() { + return jndiName; + } + + public Type getType() { + return type; + } + +} Index: src/org/netbeans/modules/j2ee/jboss4/config/mdb/JBossMessageDestinationDeployment.java =================================================================== RCS file: src/org/netbeans/modules/j2ee/jboss4/config/mdb/JBossMessageDestinationDeployment.java diff -N src/org/netbeans/modules/j2ee/jboss4/config/mdb/JBossMessageDestinationDeployment.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/netbeans/modules/j2ee/jboss4/config/mdb/JBossMessageDestinationDeployment.java 26 Mar 2007 09:54:59 -0000 1.1.2.1 @@ -0,0 +1,259 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.modules.j2ee.jboss4.config.mdb; + +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; +import java.util.HashSet; +import java.util.Set; +import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException; +import org.netbeans.modules.j2ee.deployment.common.api.MessageDestination; +import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; +import org.netbeans.modules.j2ee.deployment.plugins.spi.MessageDestinationDeployment; +import org.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginProperties; +import org.netbeans.modules.schema2beans.BaseBean; +import org.openide.filesystems.FileLock; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileSystem; +import org.openide.filesystems.FileUtil; + +/** + * + * @author Libor Kotouc + */ +public final class JBossMessageDestinationDeployment implements MessageDestinationDeployment { + +// private static final String DSdotXML = "-ds.xml"; // NOI18N +// private static final String JBossDSdotXML = "jboss-ds.xml"; // NOI18N + + // server's deploy dir + private FileObject deployDir; + + public JBossMessageDestinationDeployment(String serverUrl) { + String serverDirPath = InstanceProperties.getInstanceProperties(serverUrl). + getProperty(JBPluginProperties.PROPERTY_DEPLOY_DIR); + deployDir = FileUtil.toFileObject(new File(serverDirPath)); + } + + public Set getMessageDestinations() throws ConfigurationException { + HashSet destinations = new HashSet(); + destinations.add(new JBossMessageDestination("SampleServerQueue", MessageDestination.Type.QUEUE)); + destinations.add(new JBossMessageDestination("SampleServerTopic", MessageDestination.Type.TOPIC)); + return destinations; + } + + public void deployMessageDestinations(Set destinations) throws ConfigurationException { + } + + +/* + public Set getDatasources() throws ConfigurationException { + + Set datasources = new HashSet(); + + if (deployDir == null || !deployDir.isValid() || !deployDir.isFolder() || !deployDir.canRead()) { + ErrorManager.getDefault().log(ErrorManager.USER, + NbBundle.getMessage(JBossMessageDestinationDeployment.class, "ERR_WRONG_DEPLOY_DIR")); + return datasources; + } + + Enumeration files = deployDir.getChildren(true); + List confs = new LinkedList(); + while (files.hasMoreElements()) { // searching for config files with DS + FileObject file = (FileObject) files.nextElement(); + if (!file.isFolder() && file.getNameExt().endsWith(DSdotXML) && file.canRead()) + confs.add(file); + } + + if (confs.size() == 0) // nowhere to search + return datasources; + + for (Iterator it = confs.iterator(); it.hasNext();) { + FileObject dsFO = (FileObject)it.next(); + File dsFile = FileUtil.toFile(dsFO); + try { + Datasources ds = null; + try { + ds = Datasources.createGraph(dsFile); + } catch (RuntimeException re) { + // most likely not a data source (e.g. jms-ds.xml in JBoss 5.x) + String msg = NbBundle.getMessage(JBossMessageDestinationDeployment.class, "MSG_NotParseableDatasources", dsFile.getAbsolutePath()); + ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, msg); + continue; + } + LocalTxDatasource ltxds[] = ds.getLocalTxDatasource(); + for (int i = 0; i < ltxds.length; i++) { + if (ltxds[i].getJndiName().length() > 0) { + datasources.add(new JBossDatasource( + ltxds[i].getJndiName(), + ltxds[i].getConnectionUrl(), + ltxds[i].getUserName(), + ltxds[i].getPassword(), + ltxds[i].getDriverClass())); + } + } + } catch (IOException ioe) { + String msg = NbBundle.getMessage(JBossMessageDestinationDeployment.class, "MSG_CannotReadDatasources", dsFile.getAbsolutePath()); + throw new ConfigurationException(msg, ioe); + } catch (RuntimeException re) { + String msg = NbBundle.getMessage(JBossMessageDestinationDeployment.class, "MSG_NotParseableDatasources", dsFile.getAbsolutePath()); + throw new ConfigurationException(msg ,re); + } + } + + return datasources; + } + + public void deployDatasources(Set datasources) + throws ConfigurationException, DatasourceAlreadyExistsException + { + Set deployedDS = getDatasources(); + Map ddsMap = transform(deployedDS); // for faster searching + + HashMap newDS = new HashMap(); // will contain all ds which do not conflict with existing ones + + //resolve all conflicts + LinkedList conflictDS = new LinkedList(); + for (Iterator it = datasources.iterator(); it.hasNext();) { + Object o = it.next(); + if (!(o instanceof JBossDatasource)) + continue; + JBossDatasource ds = (JBossDatasource)o; + String jndiName = ds.getJndiName(); + if (ddsMap.keySet().contains(jndiName)) { // conflicting ds found + if (!ddsMap.get(jndiName).equals(ds)) { // found ds is not equal + conflictDS.add(ddsMap.get(jndiName)); // NOI18N + } + } + else if (jndiName != null) { + newDS.put(jndiName, ds); + } + } + + if (conflictDS.size() > 0) { // conflict found -> exception + throw new DatasourceAlreadyExistsException(conflictDS); + } + + //write jboss-ds.xml + FileObject dsXmlFo = serverDir.getFileObject(JBossDSdotXML); + File dsXMLFile = (dsXmlFo != null ? FileUtil.toFile(dsXmlFo) : null); + + Datasources deployedDSGraph = null; + try { + deployedDSGraph = (dsXMLFile != null ? Datasources.createGraph(dsXMLFile) : new Datasources()); + } + catch (IOException ioe) { + ErrorManager.getDefault().annotate(ioe, NbBundle.getMessage(getClass(), "ERR_CannotReadDSdotXml")); + ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioe); + return; + } + + //merge ds graph with newDS - remove conflicting ds from graph + LocalTxDatasource ltxds[] = deployedDSGraph.getLocalTxDatasource(); + for (int i = 0; i < ltxds.length; i++) { + String jndiName = ltxds[i].getJndiName(); + if (newDS.keySet().contains(jndiName)) //conflict, we must remove it from graph + deployedDSGraph.removeLocalTxDatasource(ltxds[i]); + } + + //add all ds from newDS + for (Iterator it = newDS.values().iterator(); it.hasNext();) { + JBossDatasource ds = (JBossDatasource) it.next(); + + LocalTxDatasource lds = new LocalTxDatasource(); + lds.setJndiName(ds.getJndiName()); + lds.setConnectionUrl(ds.getUrl()); + lds.setDriverClass(ds.getDriverClassName()); + lds.setUserName(ds.getUsername()); + lds.setPassword(ds.getPassword()); + lds.setMinPoolSize(ds.getMinPoolSize()); + lds.setMaxPoolSize(ds.getMaxPoolSize()); + lds.setIdleTimeoutMinutes(ds.getIdleTimeoutMinutes()); + + deployedDSGraph.addLocalTxDatasource(lds); + } + + //write modified graph into jboss-ds.xml + if (newDS.size() > 0) { + if (dsXMLFile == null) { + try { + dsXmlFo = serverDir.createData(JBossDSdotXML); + } + catch (IOException ioe) { + ErrorManager.getDefault().annotate(ioe, NbBundle.getMessage(getClass(), "ERR_CannotCreateDSdotXml")); + ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioe); + return; + } + + dsXMLFile = FileUtil.toFile(dsXmlFo); + } + + writeFile(dsXMLFile, deployedDSGraph); + } + + } + + private Map transform(Set datasources) { + HashMap map = new HashMap(); + for (Iterator it = datasources.iterator(); it.hasNext();) { + JBossDatasource ds = (JBossDatasource) it.next(); + if (ds.getJndiName() != null) + map.put(ds.getJndiName(), ds); + } + return map; + } +*/ + private void writeFile(final File file, final BaseBean bean) throws ConfigurationException { + try { + + FileSystem fs = deployDir.getFileSystem(); + fs.runAtomicAction(new FileSystem.AtomicAction() { + public void run() throws IOException { + OutputStream os = null; + FileLock lock = null; + try { + String name = file.getName(); + FileObject configFO = deployDir.getFileObject(name); + if (configFO == null) { + configFO = deployDir.createData(name); + } + lock = configFO.lock(); + os = new BufferedOutputStream (configFO.getOutputStream(lock), 4096); + // TODO notification needed + if (bean != null) { + bean.write(os); + } + } finally { + if (os != null) { + try { os.close(); } catch(IOException ioe) {} + } + if (lock != null) + lock.releaseLock(); + } + } + }); + } catch (IOException e) { + throw new ConfigurationException (e.getLocalizedMessage ()); + } + } + +} Index: src/org/netbeans/modules/j2ee/jboss4/config/mdb/MessageDestinationSupport.java =================================================================== RCS file: src/org/netbeans/modules/j2ee/jboss4/config/mdb/MessageDestinationSupport.java diff -N src/org/netbeans/modules/j2ee/jboss4/config/mdb/MessageDestinationSupport.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/netbeans/modules/j2ee/jboss4/config/mdb/MessageDestinationSupport.java 26 Mar 2007 09:54:59 -0000 1.1.2.1 @@ -0,0 +1,168 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + */ +package org.netbeans.modules.j2ee.jboss4.config.mdb; + +import java.io.File; +import java.io.IOException; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; +import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException; +import org.netbeans.modules.j2ee.deployment.common.api.MessageDestination; +import org.netbeans.modules.j2ee.jboss4.config.JBDeploymentConfiguration; +import org.netbeans.modules.j2ee.jboss4.config.gen.Mbean; +import org.netbeans.modules.j2ee.jboss4.config.gen.Server; +import org.openide.ErrorManager; +import org.openide.filesystems.FileChangeAdapter; +import org.openide.filesystems.FileEvent; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; + +/** + * + * @author Libor Kotouc + */ +public class MessageDestinationSupport { + + public static String MSG_DEST_RESOURCE_NAME_JB4 = "netbeans-destinations-service.xml"; // NOI18N + + //model of the destination service file + private Server destinationServiceModel; + + //destination service file (placed in the resourceDir) + private File destinationsFile; + + //destination service file object + private FileObject destinationsFO; + + public MessageDestinationSupport(File resourceDir) { + this.destinationsFile = destinationsFile; + + destinationsFile = new File(resourceDir, MSG_DEST_RESOURCE_NAME_JB4); + ensureDestinationsFOExists(); + } + + /** + * Listener of netbeans-destinations-service.xml document changes. + */ + private class MessageDestinationFileListener extends FileChangeAdapter { + + public void fileChanged(FileEvent fe) { + assert(fe.getSource() == destinationsFO); + destinationServiceModel = null; + } + + public void fileDeleted(FileEvent fe) { + assert(fe.getSource() == destinationsFO); + destinationServiceModel = null; + } + } + + private void ensureDestinationsFOExists() { + if (!destinationsFile.exists()) { + return; + } + if (destinationsFO == null || !destinationsFO.isValid()) { + destinationsFO = FileUtil.toFileObject(destinationsFile); + assert(destinationsFO != null); + destinationsFO.addFileChangeListener(new MessageDestinationFileListener()); + } + } + + public Set getMessageDestinations() throws ConfigurationException { + + Server server = getMessageDestinationGraph(); + if (server == null) { + return Collections.emptySet(); + } + + HashSet destinations = new HashSet(); + + for (Mbean mbean : destinationServiceModel.getMbean()) { + String mbeanNameAttribute = mbean.getName(); + if (mbeanNameAttribute == null) { + continue; + } + + MessageDestination.Type type = null; + if (mbeanNameAttribute.indexOf("service=Queue") > -1) { // NOI18N + type = MessageDestination.Type.QUEUE; + } + else + if (mbeanNameAttribute.indexOf("service=Topic") > -1) { // NOI18N + type = MessageDestination.Type.TOPIC; + } + if (type == null) { + continue; + } + + int nameIndex = mbeanNameAttribute.indexOf("name="); // NOI18N + if (nameIndex == -1) { + continue; + } + + String name = mbeanNameAttribute.substring(nameIndex + 5); // "name=".length() == 5 + if (name.indexOf(",") > -1) { + name = name.substring(0, name.indexOf(",")); // NOI18N + } + + destinations.add(new JBossMessageDestination(name, type)); + } + + return destinations; + } + + public MessageDestination createMessageDestination(String jndiName, MessageDestination.Type type) + throws UnsupportedOperationException, ConfigurationException { + return new JBossMessageDestination(jndiName, type); + } + + /** + * Return destination service graph. If it was not created yet, load it from the file + * and cache it. If the file does not exist, generate it. + * + * @return Destination service graph or null if the netbeans-destinations-service.xml file is not parseable. + */ + private synchronized Server getMessageDestinationGraph() { + + try { + if (destinationsFile.exists()) { + // load configuration if already exists + try { + if (destinationServiceModel == null) + destinationServiceModel = Server.createGraph(destinationsFile); + } catch (IOException ioe) { + ErrorManager.getDefault().notify(ioe); + } catch (RuntimeException re) { + // netbeans-destinations-service.xml is not parseable, do nothing + } + } else { + // create netbeans-destinations-service.xml if it does not exist yet + destinationServiceModel = new Server(); + JBDeploymentConfiguration.writeFile(destinationsFile, destinationServiceModel); + ensureDestinationsFOExists(); + } + } catch (ConfigurationException ce) { + ErrorManager.getDefault().notify(ce); + } + + return destinationServiceModel; + } + +} Index: src/org/netbeans/modules/j2ee/jboss4/ide/JBOptionalDeploymentManagerFactory.java =================================================================== RCS file: /cvs/serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/JBOptionalDeploymentManagerFactory.java,v retrieving revision 1.4.6.1 retrieving revision 1.4.6.1.2.1 diff -u -r1.4.6.1 -r1.4.6.1.2.1 --- src/org/netbeans/modules/j2ee/jboss4/ide/JBOptionalDeploymentManagerFactory.java 10 Feb 2007 08:29:43 -0000 1.4.6.1 +++ src/org/netbeans/modules/j2ee/jboss4/ide/JBOptionalDeploymentManagerFactory.java 26 Mar 2007 09:47:58 -0000 1.4.6.1.2.1 @@ -13,11 +13,12 @@ * "Portions Copyrighted [year] [name of copyright owner]" * * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.j2ee.jboss4.ide; +import org.netbeans.modules.j2ee.deployment.plugins.spi.MessageDestinationDeployment; import org.netbeans.modules.j2ee.jboss4.JBDeploymentManager; import org.netbeans.modules.j2ee.deployment.plugins.spi.DatasourceManager; import org.netbeans.modules.j2ee.jboss4.config.JBossDatasourceManager; @@ -27,6 +28,7 @@ import org.netbeans.modules.j2ee.deployment.plugins.spi.IncrementalDeployment; import org.netbeans.modules.j2ee.deployment.plugins.spi.OptionalDeploymentManagerFactory; import org.netbeans.modules.j2ee.deployment.plugins.spi.StartServer; +import org.netbeans.modules.j2ee.jboss4.config.mdb.JBossMessageDestinationDeployment; import org.openide.WizardDescriptor.InstantiatingIterator; /** @@ -61,5 +63,14 @@ return dsMgr; } + + public MessageDestinationDeployment getMessageDestinationDeployment(DeploymentManager dm) { + if (!(dm instanceof JBDeploymentManager)) { + throw new IllegalArgumentException(""); + } + + return new JBossMessageDestinationDeployment(((JBDeploymentManager)dm).getUrl()); + } + } Index: src/org/netbeans/modules/j2ee/jboss4/resources/jboss-service_4_0.dtd =================================================================== RCS file: src/org/netbeans/modules/j2ee/jboss4/resources/jboss-service_4_0.dtd diff -N src/org/netbeans/modules/j2ee/jboss4/resources/jboss-service_4_0.dtd --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/netbeans/modules/j2ee/jboss4/resources/jboss-service_4_0.dtd 26 Mar 2007 09:55:00 -0000 1.1.2.1 @@ -0,0 +1,287 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +