Index: j2eeserver/apichanges.xml =================================================================== RCS file: /cvs/j2eeserver/apichanges.xml,v retrieving revision 1.26 diff -u -r1.26 apichanges.xml --- j2eeserver/apichanges.xml 31 Mar 2007 10:07:37 -0000 1.26 +++ j2eeserver/apichanges.xml 5 Apr 2007 15:17:06 -0000 @@ -86,6 +86,24 @@ + + + + Adding an API for working with data sources, message-driven beans and JMS messages + + + + + + +

+ API for working with data sources, message-driven beans and JMS messages. +

+
+ + + +
Index: j2eeserver/nbproject/project.properties =================================================================== RCS file: /cvs/j2eeserver/nbproject/project.properties,v retrieving revision 1.17 diff -u -r1.17 project.properties --- j2eeserver/nbproject/project.properties 31 Mar 2007 10:07:38 -0000 1.17 +++ j2eeserver/nbproject/project.properties 5 Apr 2007 15:17:06 -0000 @@ -17,7 +17,7 @@ is.autoload=true javac.source=1.5 -spec.version.base=1.24.0 +spec.version.base=1.25.0 javadoc.overview=${basedir}/api/doc/overview.html javadoc.arch=${basedir}/arch.xml Index: j2eeserver/src/org/netbeans/modules/j2ee/deployment/common/api/MessageDestination.java =================================================================== RCS file: j2eeserver/src/org/netbeans/modules/j2ee/deployment/common/api/MessageDestination.java diff -N j2eeserver/src/org/netbeans/modules/j2ee/deployment/common/api/MessageDestination.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ j2eeserver/src/org/netbeans/modules/j2ee/deployment/common/api/MessageDestination.java 5 Apr 2007 15:17:06 -0000 @@ -0,0 +1,59 @@ +/* + * 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.deployment.common.api; + +/** + * Represents a message destination + * + * @author Libor Kotouc + * + * @since 1.25 + */ +public interface MessageDestination { + + /** + * Message destination type + */ + public enum Type { + /** + * Queue + */ + QUEUE, + + /** + * Topic + */ + TOPIC + }; + + /** + * Returns the name + * + * @return the name + */ + public String getName(); + + /** + * Returns the type + * + * @return the type + */ + public Type getType(); +} Index: j2eeserver/src/org/netbeans/modules/j2ee/deployment/config/ConfigSupportImpl.java =================================================================== RCS file: /cvs/j2eeserver/src/org/netbeans/modules/j2ee/deployment/config/ConfigSupportImpl.java,v retrieving revision 1.48 diff -u -r1.48 ConfigSupportImpl.java --- j2eeserver/src/org/netbeans/modules/j2ee/deployment/config/ConfigSupportImpl.java 29 Mar 2007 23:04:47 -0000 1.48 +++ j2eeserver/src/org/netbeans/modules/j2ee/deployment/config/ConfigSupportImpl.java 5 Apr 2007 15:17:06 -0000 @@ -13,14 +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.deployment.config; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; import java.io.File; import java.io.IOException; import java.io.OutputStream; @@ -31,13 +29,10 @@ import java.util.Iterator; import java.util.Map; import java.util.Set; -import javax.enterprise.deploy.model.DDBean; -import javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException; import org.netbeans.modules.j2ee.dd.api.common.ComponentInterface; import org.netbeans.modules.j2ee.deployment.common.api.OriginalCMPMapping; import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeApplication; import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; -import org.netbeans.modules.j2ee.deployment.execution.ModuleConfigurationProvider; import org.netbeans.modules.j2ee.deployment.impl.Server; import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException; import javax.enterprise.deploy.shared.ModuleType; @@ -60,7 +55,11 @@ import org.openide.util.NbBundle; import org.netbeans.api.project.FileOwnerQuery; import org.netbeans.api.project.Project; +import org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans; +import org.netbeans.modules.j2ee.deployment.common.api.MessageDestination; import org.netbeans.modules.j2ee.deployment.execution.ModuleConfigurationProvider; +import org.netbeans.modules.j2ee.deployment.plugins.spi.config.MessageDestinationConfiguration; +import org.openide.util.Parameters; /** * Each J2eeModuleProvider hold a reference to an instance of this config support. @@ -374,7 +373,7 @@ } public Datasource createDatasource(String jndiName, String url, String username, String password, String driver) - throws OperationUnsupportedException, DatasourceAlreadyExistsException { + throws UnsupportedOperationException, DatasourceAlreadyExistsException { Datasource ds = null; if (server != null) { ModuleConfiguration config = getModuleConfiguration(); @@ -391,6 +390,266 @@ } return ds; } + + public void bindDatasourceReference(String referenceName, String jndiName) throws ConfigurationException { + + Parameters.notNull("referenceName", referenceName); // NOI18N + Parameters.notNull("jndiName", jndiName); // NOI18N + + if (server != null) { + ModuleConfiguration config = getModuleConfiguration(); + if (config != null) { + DatasourceConfiguration datasourceConfiguration = config.getLookup().lookup(DatasourceConfiguration.class); + if (datasourceConfiguration != null) { + datasourceConfiguration.bindDatasourceReference(referenceName, jndiName); + } + } + } + } + + public void bindDatasourceReferenceForEjb(String ejbName, String ejbType, + String referenceName, String jndiName) throws ConfigurationException { + + Parameters.notNull("ejbName", ejbName); // NOI18N + Parameters.notNull("ejbType", ejbType); // NOI18N + Parameters.notNull("referenceName", referenceName); // NOI18N + Parameters.notNull("jndiName", jndiName); // NOI18N + + if (!EnterpriseBeans.SESSION.equals(ejbType) && + !EnterpriseBeans.ENTITY.equals(ejbType) && + !EnterpriseBeans.MESSAGE_DRIVEN.equals(ejbType)) { + throw new IllegalArgumentException("ejbType parameter doesn't have an allowed value."); + } + + if (server != null) { + ModuleConfiguration config = getModuleConfiguration(); + if (config != null) { + DatasourceConfiguration datasourceConfiguration = config.getLookup().lookup(DatasourceConfiguration.class); + if (datasourceConfiguration != null) { + datasourceConfiguration.bindDatasourceReferenceForEjb(ejbName, ejbType, referenceName, jndiName); + } + } + } + } + + public String findDatasourceJndiName(String referenceName) throws ConfigurationException { + + Parameters.notNull("referenceName", referenceName); // NOI18N + + String jndiName = null; + if (server != null) { + ModuleConfiguration config = getModuleConfiguration(); + if (config != null) { + DatasourceConfiguration datasourceConfiguration = config.getLookup().lookup(DatasourceConfiguration.class); + if (datasourceConfiguration != null) { + jndiName = datasourceConfiguration.findDatasourceJndiName(referenceName); + } + } + } + + return jndiName; + } + + public String findDatasourceJndiNameForEjb(String ejbName, String referenceName) throws ConfigurationException { + + Parameters.notNull("ejbName", ejbName); // NOI18N + Parameters.notNull("referenceName", referenceName); // NOI18N + + String jndiName = null; + if (server != null) { + ModuleConfiguration config = getModuleConfiguration(); + if (config != null) { + DatasourceConfiguration datasourceConfiguration = config.getLookup().lookup(DatasourceConfiguration.class); + if (datasourceConfiguration != null) { + jndiName = datasourceConfiguration.findDatasourceJndiNameForEjb(ejbName, referenceName); + } + } + } + + return jndiName; + } + + public Datasource findDatasource(String jndiName) throws ConfigurationException { + + Parameters.notNull("jndiName", jndiName); // NOI18N + + Set datasources = getDatasources(); + for (Datasource ds : datasources) { + if (jndiName.equals(ds.getJndiName())) { + return ds; + } + } + datasources = provider.getServerDatasources(); + for (Datasource ds : datasources) { + if (jndiName.equals(ds.getJndiName())) { + return ds; + } + } + + return null; + } + + public Set getMessageDestinations() throws ConfigurationException { + + Set destinations = Collections.emptySet(); + + if (server != null) { + ModuleConfiguration config = getModuleConfiguration(); + if (config != null) { + MessageDestinationConfiguration msgConfig = config.getLookup().lookup(MessageDestinationConfiguration.class); + if (msgConfig != null) { + destinations = msgConfig.getMessageDestinations(); + } + } + } + + return destinations; + } + + public Set getServerMessageDestinations() throws ConfigurationException { + ServerInstance si = ServerRegistry.getInstance().getServerInstance(provider.getServerInstanceID()); + if (si == null) { + ErrorManager.getDefault().log(ErrorManager.WARNING, + "The server data sources cannot be retrieved because the server instance cannot be found."); + return Collections.emptySet(); + } + + return si.getMessageDestinations(); + } + + public boolean supportsCreateMessageDestination() { + if (server == null) { + // the module has no target server + return false; + } + ModuleConfiguration config = getModuleConfiguration(); + if (config != null) { + MessageDestinationConfiguration msgConfig = config.getLookup().lookup(MessageDestinationConfiguration.class); + if (msgConfig != null) { + return msgConfig.supportsCreateMessageDestination(); + } + } + return false; + } + + public MessageDestination createMessageDestination(String name, MessageDestination.Type type) + throws UnsupportedOperationException, ConfigurationException { + + Parameters.notNull("name", name); // NOI18N + Parameters.notNull("type", type); // NOI18N + + if (server == null) { + return null; + } + + ModuleConfiguration config = getModuleConfiguration(); + if (config == null) { + return null; + } + + MessageDestinationConfiguration msgConfig = config.getLookup().lookup(MessageDestinationConfiguration.class); + if (msgConfig != null) { + return msgConfig.createMessageDestination(name, type); + } + + return null; + } + + public void bindMdbToMessageDestination(String mdbName, String name, MessageDestination.Type type) throws ConfigurationException { + + Parameters.notNull("mdbName", mdbName); // NOI18N + Parameters.notNull("name", name); // NOI18N + Parameters.notNull("type", type); // NOI18N + + ModuleConfiguration config = getModuleConfiguration(); + if (server == null || config == null) { + return; + } + + MessageDestinationConfiguration msgConfig = config.getLookup().lookup(MessageDestinationConfiguration.class); + if (msgConfig != null) { + msgConfig.bindMdbToMessageDestination(mdbName, name, type); + } + } + + public String findMessageDestinationName(String mdbName) throws ConfigurationException { + + Parameters.notNull("mdbName", mdbName); // NOI18N + + ModuleConfiguration config = getModuleConfiguration(); + if (server == null || config == null) { + return null; + } + + MessageDestinationConfiguration msgConfig = config.getLookup().lookup(MessageDestinationConfiguration.class); + if (msgConfig != null) { + return msgConfig.findMessageDestinationName(mdbName); + } + + return null; + } + + public MessageDestination findMessageDestination(String name) throws ConfigurationException { + + Parameters.notNull("name", name); // NOI18N + + Set destinations = getMessageDestinations(); + for (MessageDestination dest : destinations) { + if (name.equals(dest.getName())) { + return dest; + } + } + destinations = provider.getConfigSupport().getServerMessageDestinations(); + for (MessageDestination dest : destinations) { + if (name.equals(dest.getName())) { + return dest; + } + } + + return null; + } + + public void bindMessageDestinationReference(String referenceName, String connectionFactoryName, + String destName, MessageDestination.Type type) throws ConfigurationException { + + Parameters.notNull("referenceName", referenceName); // NOI18N + Parameters.notNull("connectionFactoryName", connectionFactoryName); // NOI18N + Parameters.notNull("destName", destName); // NOI18N + Parameters.notNull("type", type); // NOI18N + + ModuleConfiguration config = getModuleConfiguration(); + if (server == null || config == null) { + return; + } + + MessageDestinationConfiguration msgConfig = config.getLookup().lookup(MessageDestinationConfiguration.class); + if (msgConfig != null) { + msgConfig.bindMessageDestinationReference(referenceName, connectionFactoryName, destName, type); + } + } + + public void bindMessageDestinationReferenceForEjb(String ejbName, String ejbType, + String referenceName, String connectionFactoryName, + String destName, MessageDestination.Type type) throws ConfigurationException { + + Parameters.notNull("ejbName", ejbName); // NOI18N + Parameters.notNull("ejbType", ejbType); // NOI18N + Parameters.notNull("referenceName", referenceName); // NOI18N + Parameters.notNull("connectionFactoryName", connectionFactoryName); // NOI18N + Parameters.notNull("destName", destName); // NOI18N + Parameters.notNull("type", type); // NOI18N + + ModuleConfiguration config = getModuleConfiguration(); + if (server == null || config == null) { + return; + } + + MessageDestinationConfiguration msgConfig = config.getLookup().lookup(MessageDestinationConfiguration.class); + if (msgConfig != null) { + msgConfig.bindMessageDestinationReferenceForEjb(ejbName, ejbType, referenceName, connectionFactoryName, destName, type); + } + + } // DeploymentConfigurationProvider implementation ------------------------- Index: j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/api/Deployment.java =================================================================== RCS file: /cvs/j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/api/Deployment.java,v retrieving revision 1.25 diff -u -r1.25 Deployment.java --- j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/api/Deployment.java 31 Mar 2007 10:07:38 -0000 1.25 +++ j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/api/Deployment.java 5 Apr 2007 15:17:06 -0000 @@ -13,24 +13,21 @@ * "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.deployment.devmodules.api; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; -import java.util.Map; import java.util.Set; -import java.util.WeakHashMap; import javax.enterprise.deploy.spi.Target; import javax.enterprise.deploy.spi.status.ProgressObject; import org.netbeans.modules.j2ee.deployment.common.api.Datasource; +import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException; import org.netbeans.modules.j2ee.deployment.devmodules.spi.InstanceListener; import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; import org.netbeans.modules.j2ee.deployment.impl.*; @@ -119,6 +116,10 @@ } jmp.deployDatasources(); + +if (System.getProperties().getProperty("resource-api-redesign") != null) { + deployMessageDestinations(jmp); +} modules = targetserver.deploy(progress, forceRedeploy); // inform the plugin about the deploy action, even if there was @@ -140,6 +141,17 @@ if (progress != null) { progress.finish(); } + } + } + + public void deployMessageDestinations(J2eeModuleProvider jmp) throws ConfigurationException { + ServerInstance si = ServerRegistry.getInstance ().getServerInstance (jmp.getServerInstanceID ()); + if (si != null) { + si.deployMessageDestinations(jmp.getConfigSupport().getMessageDestinations()); + } + else { + ErrorManager.getDefault().log(ErrorManager.WARNING, + "The message destinations cannot be deployed because the server instance cannot be found."); } } Index: j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/spi/J2eeModuleProvider.java =================================================================== RCS file: /cvs/j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/spi/J2eeModuleProvider.java,v retrieving revision 1.55 diff -u -r1.55 J2eeModuleProvider.java --- j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/spi/J2eeModuleProvider.java 29 Mar 2007 23:04:53 -0000 1.55 +++ j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/spi/J2eeModuleProvider.java 5 Apr 2007 15:17:06 -0000 @@ -13,23 +13,18 @@ * "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.deployment.devmodules.spi; -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.io.IOException; import java.io.OutputStream; import java.util.Collections; import java.util.Iterator; -import java.util.Map; import java.util.Set; import javax.enterprise.deploy.spi.Target; import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException; -import javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException; import org.netbeans.modules.j2ee.deployment.common.api.OriginalCMPMapping; import org.netbeans.modules.j2ee.deployment.common.api.ValidationException; import org.netbeans.modules.j2ee.deployment.config.*; @@ -38,7 +33,6 @@ import org.netbeans.modules.j2ee.deployment.impl.Server; import org.netbeans.modules.j2ee.deployment.impl.ServerInstance; import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry; -import org.netbeans.modules.j2ee.deployment.impl.ServerString; import org.netbeans.modules.j2ee.deployment.impl.ServerTarget; import org.netbeans.modules.j2ee.deployment.common.api.Datasource; import org.netbeans.modules.j2ee.deployment.common.api.DatasourceAlreadyExistsException; @@ -49,11 +43,9 @@ import org.netbeans.modules.j2ee.deployment.plugins.spi.VerifierSupport; import org.openide.ErrorManager; import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileUtil; -import org.openide.util.WeakListeners; -import java.io.File; import java.util.ArrayList; import java.util.List; +import org.netbeans.modules.j2ee.deployment.common.api.MessageDestination; /** This object must be implemented by J2EE module support and an instance * added into project lookup. @@ -207,7 +199,7 @@ try { //btw, ds existence in a project is verified directly in the deployment configuration ds = getConfigSupport().createDatasource(jndiName, url, username, password, driver); - } catch (OperationUnsupportedException oue) { + } catch (UnsupportedOperationException oue) { ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, oue); } @@ -339,14 +331,217 @@ * * @return created data source * - * @throws OperationUnsupportedException if operation is not supported + * @throws UnsupportedOperationException if operation is not supported * @throws DatasourceAlreadyExistsException if conflicting data source is found * @throws ConfigurationException reports errors in creating the data source. * * @since 1.15 */ public Datasource createDatasource(String jndiName, String url, String username, String password, String driver) - throws OperationUnsupportedException, DatasourceAlreadyExistsException, ConfigurationException; + throws UnsupportedOperationException, DatasourceAlreadyExistsException, ConfigurationException; + + /** + * Binds the data source reference name with the corresponding data source which is + * identified by the given JNDI name. + * + * @param referenceName name used to identify the data source + * @param jndiName JNDI name of the data source + * + * @throws NullPointerException if any of parameters is null + * @throws ConfigurationException if there is some problem with data source configuration + * + * @since 1.25 + */ + public void bindDatasourceReference(String referenceName, String jndiName) throws ConfigurationException; + + /** + * Binds the data source reference name with the corresponding data source which is + * identified by the given JNDI name. The reference is used within the scope of the EJB. + * + * @param ejbName EJB name + * @param ejbType EJB type - the possible values are + * org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.SESSION, + * org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.ENTITY and + * org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.MESSAGE_DRIVEN + * @param referenceName name used to identify the data source + * @param jndiName JNDI name of the data source + + * @throws NullPointerException if any of parameters is null + * @throws ConfigurationException if there is some problem with data source configuration + * @throws IllegalArgumentException if ejbType doesn't have one of allowed values + * + * @since 1.25 + */ + public void bindDatasourceReferenceForEjb(String ejbName, String ejbType, + String referenceName, String jndiName) throws ConfigurationException; + + /** + * Finds JNDI name of data source which is mapped to the given reference name of a data source + * + * @param referenceName reference name of data source + * @return JNDI name which is mapped to the given JNDI name + * + * @throws NullPointerException if reference name is null + * @throws ConfigurationException if there is some problem with data source configuration + * + * @since 1.25 + */ + public String findDatasourceJndiName(String referenceName) throws ConfigurationException; + + /** + * Finds JNDI name of data source which is mapped to the given reference name in the scope of the EJB. + * + * @param ejbName EJB name + * @param referenceName reference name of data source + * @return data source if it exists, null otherwise + * + * @throws NullPointerException if any of parameters is null + * @throws ConfigurationException if there is some problem with data source configuration + * + * @since 1.25 + */ + public String findDatasourceJndiNameForEjb(String ejbName, String referenceName) throws ConfigurationException; + + /** + * Finds data source with the given JNDI name. + * + * @param jndiName JNDI name of a data source + * @param return data source if it exists, null otherwise + * + * @throws NullPointerException if JNDI name is null + * @throws ConfigurationException if there is some problem with data source configuration + * + * @since 1.25 + */ + public Datasource findDatasource(String jndiName) throws ConfigurationException; + + /** + * Retrieves message destinations stored in the module. + * + * @return set of message destinations + * + * @throws ConfigurationException if there is some problem with message destination configuration + * + * @since 1.25 + */ + public Set getMessageDestinations() throws ConfigurationException; + + /** + * Retrieves message destinations configured on the target server instance. + * + * @return set of message destinations + * + * @throws ConfigurationException if there is some problem with message destination configuration + * + * @since 1.25 + */ + public Set getServerMessageDestinations() throws ConfigurationException; + + /** + * Tests whether a message destination creation is supported. + * + * @return true if message destination creation is supported, false otherwise. + * + * @since 1.25 + */ + public boolean supportsCreateMessageDestination(); + + /** + * Creates and saves a message destination in the module if it does not exist in the module yet. + * Message destinations are considered to be equal if their JNDI names are equal. + * + * @param name name of the message destination + * @param type message destination type + * @return created message destination + * + * @throws NullPointerException if any of parameters is null + * @throws UnsupportedOperationException if this opearation is not supported + * @throws ConfigurationException if there is some problem with message destination configuration + * + * @since 1.25 + */ + public MessageDestination createMessageDestination(String name, MessageDestination.Type type) + throws UnsupportedOperationException, ConfigurationException; + + /** + * Binds the message destination name with message-driven bean. + * + * @param mdbName MDB name + * @param name name of the message destination + * @param type message destination type + * + * @throws NullPointerException if any of parameters is null + * @throws ConfigurationException if there is some problem with message destination configuration + * + * @since 1.25 + */ + public void bindMdbToMessageDestination(String mdbName, String name, MessageDestination.Type type) throws ConfigurationException; + + /** + * Finds name of message destination which the given MDB listens to + * + * @param mdbName MDB name + * @return message destination name + * + * @throws NullPointerException if MDB name is null + * @throws ConfigurationException if there is some problem with message destination configuration + * + * @since 1.25 + */ + public String findMessageDestinationName(String mdbName) throws ConfigurationException; + + /** + * Finds message destination with the given name. + * + * @param name message destination name + * @param return message destination if it exists, null otherwise + * + * @throws NullPointerException if name is null + * @throws ConfigurationException if there is some problem with message destination configuration + * + * @since 1.25 + */ + public MessageDestination findMessageDestination(String name) throws ConfigurationException; + + /** + * Binds the message destination reference name with the corresponding message destination which is + * identified by the given name. + * + * @param referenceName reference name used to identify the message destination + * @param connectionFactoryName connection factory name + * @param destName name of the message destination + * @param type message destination type + * + * @throws NullPointerException if any of parameters is null + * @throws ConfigurationException if there is some problem with message destination configuration + * + * @since 1.25 + */ + public void bindMessageDestinationReference(String referenceName, String connectionFactoryName, + String destName, MessageDestination.Type type) throws ConfigurationException; + + /** + * Binds the message destination reference name with the corresponding message destination which is + * identified by the given name. The reference is used within the EJB scope. + * + * @param ejbName EJB name + * @param ejbType EJB type - the possible values are + * org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.SESSION, + * org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.ENTITY and + * org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.MESSAGE_DRIVEN + * @param referenceName reference name used to identify the message destination + * @param connectionFactoryName connection factory name + * @param destName name of the message destination + * @param type message destination type + * + * @throws NullPointerException if any of parameters is null + * @throws ConfigurationException if there is some problem with message destination configuration + * + * @since 1.25 + */ + public void bindMessageDestinationReferenceForEjb(String ejbName, String ejbType, + String referenceName, String connectionFactoryName, + String destName, MessageDestination.Type type) throws ConfigurationException; } /** Index: j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerInstance.java =================================================================== RCS file: /cvs/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerInstance.java,v retrieving revision 1.77 diff -u -r1.77 ServerInstance.java --- j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerInstance.java 31 Mar 2007 10:07:39 -0000 1.77 +++ j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerInstance.java 5 Apr 2007 15:17:06 -0000 @@ -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. */ @@ -39,6 +39,7 @@ import org.openide.filesystems.*; import java.util.*; import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException; +import org.netbeans.modules.j2ee.deployment.common.api.MessageDestination; import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; import org.netbeans.modules.j2ee.deployment.impl.ui.ProgressUI; @@ -53,6 +54,7 @@ import org.netbeans.modules.j2ee.deployment.plugins.spi.FindJSPServlet; import org.netbeans.modules.j2ee.deployment.plugins.spi.IncrementalDeployment; import org.netbeans.modules.j2ee.deployment.plugins.spi.J2eePlatformFactory; +import org.netbeans.modules.j2ee.deployment.plugins.spi.MessageDestinationDeployment; import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerServerSettings; import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerSupport; import org.netbeans.modules.j2ee.deployment.profiler.spi.Profiler; @@ -61,6 +63,7 @@ import org.openide.util.NbBundle; import org.openide.NotifyDescriptor; import org.openide.DialogDisplayer; +import org.openide.util.Parameters; import org.openide.util.RequestProcessor; import org.openide.windows.InputOutput; @@ -104,6 +107,8 @@ private FindJSPServlet findJSPServlet; private DatasourceManager dsMgr; private DatasourceManager ddsMgr; + private MessageDestinationDeployment msgDestDeploymentConnected; + private MessageDestinationDeployment msgDestDeploymentDisconnected; private final Set targetsStartedByIde = new HashSet(); // valued by target name private Map targets; // keyed by target name, valued by ServerTarget private boolean managerStartedByIde = false; @@ -565,6 +570,65 @@ if (dsMgr != null) dsMgr.deployDatasources(datasources); + } + + private synchronized MessageDestinationDeployment getMessageDestinationDeploymentConnected() { + if (msgDestDeploymentConnected == null) { + msgDestDeploymentConnected = server.getOptionalFactory(). + getMessageDestinationDeployment(getDeploymentManager()); + } + + return msgDestDeploymentConnected; + } + + private MessageDestinationDeployment getMessageDestinationDeploymentDisconnected() { + DeploymentManager dm = null; + try { + dm = getDisconnectedDeploymentManager(); + } catch (DeploymentManagerCreationException dmce) { + throw new RuntimeException(dmce); + } + synchronized (this) { + if (msgDestDeploymentDisconnected == null) { + msgDestDeploymentDisconnected = server.getOptionalFactory().getMessageDestinationDeployment(dm); + } + return msgDestDeploymentDisconnected; + } + } + + /** + * Retrieves message destinations configured on the target server instance. + * + * @return set of message destinations + * + * @throws ConfigurationException if there is some problem with message destination configuration + */ + public Set getMessageDestinations() throws ConfigurationException { + + MessageDestinationDeployment destDepl = getMessageDestinationDeploymentDisconnected(); + if (destDepl != null) { + return destDepl.getMessageDestinations(); + } + + return Collections.emptySet(); + } + + /** + * Deploys message destinations saved in the module. + * + * @param destinations set of message destinations + * + * @throws NullPointerException if destinations parameter is null + * @throws ConfigurationException if there is some problem with message destination configuration + */ + public void deployMessageDestinations(Set destinations) throws ConfigurationException { + + Parameters.notNull("destinations", destinations); + + MessageDestinationDeployment destDepl = getMessageDestinationDeploymentConnected(); + if (destDepl != null) { + destDepl.deployMessageDestinations(destinations); + } } //---------- State API's: running, debuggable, startedByIDE ----------- Index: j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/MessageDestinationDeployment.java =================================================================== RCS file: j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/MessageDestinationDeployment.java diff -N j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/MessageDestinationDeployment.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/MessageDestinationDeployment.java 5 Apr 2007 15:17:06 -0000 @@ -0,0 +1,53 @@ +/* + * 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.deployment.plugins.spi; + +import java.util.Set; +import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException; +import org.netbeans.modules.j2ee.deployment.common.api.MessageDestination; + +/** + * MessageDestinationDeployment is responsible for retrieving message destinations + * configured on the server and for message destination deployment. + * + * @author Libor Kotouc + * + * @since 1.25 + */ +public interface MessageDestinationDeployment { + + /** + * Retrieves message destinations configured on the target server instance. + * + * @return set of message destinations + * + * @throws ConfigurationException if there is some problem with message destination configuration + */ + Set getMessageDestinations() throws ConfigurationException; + + /** + * Deploys message destinations saved in the module. + * + * @param destinations set of message destinations + * + * @exception ConfigurationException if there is some problem with message destination configuration + */ + void deployMessageDestinations(Set destinations) throws ConfigurationException; +} Index: j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/OptionalDeploymentManagerFactory.java =================================================================== RCS file: /cvs/j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/OptionalDeploymentManagerFactory.java,v retrieving revision 1.3 diff -u -r1.3 OptionalDeploymentManagerFactory.java --- j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/OptionalDeploymentManagerFactory.java 31 Mar 2007 10:07:40 -0000 1.3 +++ j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/OptionalDeploymentManagerFactory.java 5 Apr 2007 15:17:06 -0000 @@ -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. */ @@ -21,8 +21,6 @@ package org.netbeans.modules.j2ee.deployment.plugins.spi; import javax.enterprise.deploy.spi.DeploymentManager; -import org.netbeans.modules.j2ee.deployment.plugins.spi.StartServer; -import org.netbeans.modules.j2ee.deployment.plugins.spi.TargetModuleIDResolver; import org.openide.WizardDescriptor; /** @@ -107,4 +105,20 @@ public JDBCDriverDeployer getJDBCDriverDeployer(DeploymentManager dm) { return null; } + + /** + * Creates a MessageDestinationDeployment for the given deployment manager + * or null if message destination deployment is not supported + * + * @param dm the deployment manager + * + * @return a message destination deployment or null + * if message destination deployment is not supported + * + * @since 1.25 + */ + public MessageDestinationDeployment getMessageDestinationDeployment(DeploymentManager dm) { + return null; + } + } Index: j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/config/DatasourceConfiguration.java =================================================================== RCS file: /cvs/j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/config/DatasourceConfiguration.java,v retrieving revision 1.2 diff -u -r1.2 DatasourceConfiguration.java --- j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/config/DatasourceConfiguration.java 29 Mar 2007 23:05:04 -0000 1.2 +++ j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/config/DatasourceConfiguration.java 5 Apr 2007 15:17:06 -0000 @@ -71,4 +71,60 @@ */ Datasource createDatasource(String jndiName, String url, String username, String password, String driver) throws UnsupportedOperationException, ConfigurationException, DatasourceAlreadyExistsException; + + /** + * Binds the data source reference name with the corresponding data source which is + * identified the given JNDI name. + * + * @param referenceName name used to identify the data source + * @param jndiName JNDI name of the data source + * @throws ConfigurationException if there is some problem with data source configuration + * + * @since 1.25 + */ + public void bindDatasourceReference(String referenceName, String jndiName) throws ConfigurationException; + + /** + * Binds the data source reference name with the corresponding data source which is + * identified the given JNDI name. The reference is used within the scope of the EJB. + * + * @param ejbName EJB name + * @param ejbType EJB type - the possible values are + * org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.SESSION, + * org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.ENTITY and + * org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.MESSAGE_DRIVEN + * @param referenceName name used to identify the data source + * @param jndiName JNDI name of the data source + * + * @throws ConfigurationException if there is some problem with data source configuration + * + * @since 1.25 + */ + public void bindDatasourceReferenceForEjb(String ejbName, String ejbType, + String referenceName, String jndiName) throws ConfigurationException; + + /** + * Finds JNDI name of the data source which is mapped to the given reference name. + * + * @referenceName reference name + * @return JNDI name of the data source if the mapping exists, null otherwise + * + * @throws ConfigurationException if there is some problem with data source configuration + * + * @since 1.25 + */ + public String findDatasourceJndiName(String referenceName) throws ConfigurationException; + + /** + * Finds JNDI name of the data source which is mapped to the given reference name in the scope the EJB. + * + * @param ejbName EJB name + * @param referenceName reference name + * @return JNDI name of the data source if the mapping exists, null otherwise + * + * @throws ConfigurationException if there is some problem with data source configuration + * + * @since 1.25 + */ + public String findDatasourceJndiNameForEjb(String ejbName, String referenceName) throws ConfigurationException; } Index: j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/config/MessageDestinationConfiguration.java =================================================================== RCS file: j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/config/MessageDestinationConfiguration.java diff -N j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/config/MessageDestinationConfiguration.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/config/MessageDestinationConfiguration.java 5 Apr 2007 15:17:06 -0000 @@ -0,0 +1,137 @@ +/* + * 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.deployment.plugins.spi.config; + +import java.util.List; +import java.util.Set; +import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException; +import org.netbeans.modules.j2ee.deployment.common.api.MessageDestination; + +/** + * Configuration useful for managing module message destinations. + *

+ * Implementation of this interface should be registered in the {@link ModuleConfiguration} + * lookup. + * + * @author Libor Kotouc + */ +public interface MessageDestinationConfiguration { + + /** + * Retrieves message destinations stored in the module. + * + * @return set of message destinations + * + * @throws ConfigurationException if there is some problem with message destination configuration + * + * @since 1.25 + */ + public Set getMessageDestinations() throws ConfigurationException; + + /** + * Tests whether a message destination creation is supported. + * + * @return true if message destination creation is supported, false otherwise. + * + * @since 1.25 + */ + public boolean supportsCreateMessageDestination(); + + /** + * Creates and saves a message destination in the module if it does not exist in the module yet. + * Message destinations are considered to be equal if their JNDI names are equal. + * + * @param name name of the message destination + * @param type message destination type; the value is of + * org.netbeans.modules.j2ee.deployment.common.api.MessageDestination.Type type + * @return created message destination + * + * @throws UnsupportedOperationException if this opearation is not supported + * @throws ConfigurationException if there is some problem with message destination configuration + * + * @since 1.25 + */ + public MessageDestination createMessageDestination(String name, MessageDestination.Type type) + throws UnsupportedOperationException, ConfigurationException; + + /** + * Binds the message destination name with message-driven bean. + * + * @param mdbName MDB name + * @param name name of the message destination + * @param type message destination type; the value is of + * + * @throws ConfigurationException if there is some problem with message destination configuration + * + * @since 1.25 + */ + public void bindMdbToMessageDestination(String mdbName, String name, MessageDestination.Type type) throws ConfigurationException; + + /** + * Finds name of message destination which the given MDB listens to + * + * @param mdbName MDB name + * @return message destination name + * + * @throws ConfigurationException if there is some problem with message destination configuration + * + * @since 1.25 + */ + public String findMessageDestinationName(String mdbName) throws ConfigurationException; + + /** + * Binds the message destination reference name with the corresponding message destination which is + * identified by the given name. + * + * @param referenceName reference name used to identify the message destination + * @param connectionFactoryName connection factory name + * @param destName name of the message destination + * @param type message destination type + * + * @throws ConfigurationException if there is some problem with message destination configuration + * + * @since 1.25 + */ + public void bindMessageDestinationReference(String referenceName, String connectionFactoryName, + String destName, MessageDestination.Type type) throws ConfigurationException; + + /** + * Binds the message destination reference name with the corresponding message destination which is + * identified by the given name. The reference is used within the EJB scope. + * + * @param ejbName EJB name + * @param ejbType EJB type - the possible values are + * org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.SESSION, + * org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.ENTITY and + * org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.MESSAGE_DRIVEN + * @param referenceName reference name used to identify the message destination + * @param connectionFactoryName connection factory name + * @param destName name of the message destination + * @param type message destination type + * + * @throws ConfigurationException if there is some problem with message destination configuration + * + * @since 1.25 + */ + public void bindMessageDestinationReferenceForEjb(String ejbName, String ejbType, + String referenceName, String connectionFactoryName, + String destName, MessageDestination.Type type) throws ConfigurationException; + +} Index: j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/config/ModuleConfiguration.java =================================================================== RCS file: /cvs/j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/config/ModuleConfiguration.java,v retrieving revision 1.2 diff -u -r1.2 ModuleConfiguration.java --- j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/config/ModuleConfiguration.java 29 Mar 2007 23:05:05 -0000 1.2 +++ j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/config/ModuleConfiguration.java 5 Apr 2007 15:17:06 -0000 @@ -39,7 +39,8 @@ * implementations of all the supported configurations. *

* The configuration are: {@link ContextRootConfiguration}, {@link DatasourceConfiguration}, - * {@link MappingConfiguration}, {@link EjbResourceConfiguration}, {@link DeploymentPlanConfiguration} + * {@link MappingConfiguration}, {@link EjbResourceConfiguration}, {@link DeploymentPlanConfiguration}, + * {@link MessageDestinationConfiguration} *

* Implementators are advised to use {@link org.openide.util.lookup.Lookups#fixed} * to implement this method. Index: serverplugins/jboss4/build.xml =================================================================== RCS file: /cvs/serverplugins/jboss4/build.xml,v retrieving revision 1.6 diff -u -r1.6 build.xml --- serverplugins/jboss4/build.xml 12 Oct 2006 14:37:57 -0000 1.6 +++ serverplugins/jboss4/build.xml 5 Apr 2007 15:17:07 -0000 @@ -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,41 +735,111 @@ return beanMap; } + + public void bindDatasourceReferenceForEjb(String ejbName, String ejbType, + String referenceName, String jndiName) throws ConfigurationException { + + Set beanNames = new HashSet(); + beanNames.add(ejbName); + if (org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.SESSION.equals(ejbType)) { + addResReference(jndiName, referenceName, beanNames, BEAN_TYPE.SESSION); + } + else + if (org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.ENTITY.equals(ejbType)) { + addResReference(jndiName, referenceName, beanNames, BEAN_TYPE.ENTITY); + } + else + if (org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.MESSAGE_DRIVEN.equals(ejbType)) { + addMsgDrvResReference(jndiName, referenceName, ejbName); + } + + } + + public String findDatasourceJndiNameForEjb(String ejbName, String referenceName) 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 (referenceName.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 (referenceName.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 (referenceName.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); } }); } /** - * Add a new resource reference to the message-driven beans without it. + * Add a new resource reference to the message-driven bean. * - * @param desc data source description + * @param jndiName JNDI name of the resource * @param resRefName resource reference name - * @param beans the bean names (ejb-name) mapped to the message destinations (message-destination-link) + * @param mdbName the MDB (ejb-name) which might need to add resource reference specified by resRefName * which might need to add resource reference specified by resRefName */ - private void addMsgDrvResReference(String desc, final String resRefName, final Map beans) + private void addMsgDrvResReference(final String jndiName, final String resRefName, final String mdbName) throws ConfigurationException { modifyJboss(new JbossModifier() { public void modify(Jboss modifiedJboss) { - String jndiName = JBDeploymentConfiguration.JBOSS4_DATASOURCE_JNDI_PREFIX + resRefName; - JbossDataSourceRefModifier.modifyMsgDrv(modifiedJboss, resRefName, beans, jndiName); + JbossDataSourceRefModifier.modifyMsgDrv(modifiedJboss, resRefName, mdbName, jndiName); } }); } @@ -833,13 +914,47 @@ }); } + public void bindMdbToMessageDestination(String mdbName, String name, MessageDestination.Type type) throws ConfigurationException { + addMDB(mdbName, name, type); + } + + public String findMessageDestinationName(String mdbName) throws ConfigurationException { + + EnterpriseBeans beans = getJboss().getEnterpriseBeans(); + if (beans == null) { + return null; + } + + MessageDriven[] mdbs = beans.getMessageDriven(); + for (MessageDriven mdb : mdbs) { + if (mdbName.equals(mdb.getEjbName())) { + String destJndiName = mdb.getDestinationJndiName(); + if (destJndiName != null) { + if (destJndiName.startsWith("queue/") || destJndiName.startsWith("topic/")) { + return destJndiName.substring(6); // "queue/".length() == "topic/".length() == 6 + } + else { + ErrorManager.getDefault().log( + ErrorManager.INFORMATIONAL, + NbBundle.getMessage(EjbDeploymentConfiguration.class, "MSG_NoPrefix", destJndiName)); + } + } + return null; + } + } + + return null; + } + /** * 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 { + private void addMDB(final String name, final String destName, final MessageDestination.Type destType) + throws ConfigurationException { + modifyJboss(new JbossModifier() { public void modify(Jboss modifiedJboss) { @@ -862,7 +977,13 @@ //if it doesn't exist yet, create a new one MessageDriven mdb = new MessageDriven(); mdb.setEjbName(name); - mdb.setDestinationJndiName(dest); // NOI18N + if (MessageDestination.Type.QUEUE.equals(destType)) { + mdb.setDestinationJndiName("queue/" + destName); // NOI18N + } + else + if (MessageDestination.Type.TOPIC.equals(destType)) { + mdb.setDestinationJndiName("topic/" + destName); // NOI18N + } eb.addMessageDriven(mdb); } }); @@ -889,34 +1010,69 @@ /** * 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 + * @param connectionFactoryName connection factory reference name + * @param mdbName the MDB (ejb-name) which might need to add connection factory reference specified by resRefName */ - private void addMsgDrvConnectionFactoryReference(final String resRefName, final Map beans) + private void addMsgDrvConnectionFactoryReference(final String connectionFactoryName, final String mdbName) throws ConfigurationException { modifyJboss(new JbossModifier() { public void modify(Jboss modifiedJboss) { String jndiName = JBOSS4_CONN_FACTORY_JNDI_NAME; - JbossDataSourceRefModifier.modifyMsgDrv(modifiedJboss, resRefName, beans, jndiName); + JbossDataSourceRefModifier.modifyMsgDrv(modifiedJboss, connectionFactoryName, mdbName, jndiName); } }); } + public void bindMessageDestinationReferenceForEjb(String ejbName, String ejbType, + String referenceName, String connectionFactoryName, + String destName, MessageDestination.Type type) throws ConfigurationException { + + Set beanNames = new HashSet(); + beanNames.add(ejbName); + + String destPrefix = null; + if (MessageDestination.Type.QUEUE.equals(type)) { + destPrefix = "queue/"; + } + else + if (MessageDestination.Type.TOPIC.equals(type)) { + destPrefix = "topic/"; + } + + if (org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.SESSION.equals(ejbType)) { + addConnectionFactoryReference(connectionFactoryName, beanNames, BEAN_TYPE.SESSION); + addMsgDestReference(referenceName, destPrefix, destName, beanNames, BEAN_TYPE.SESSION); + } + else + if (org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.ENTITY.equals(ejbType)) { + addConnectionFactoryReference(connectionFactoryName, beanNames, BEAN_TYPE.ENTITY); + addMsgDestReference(referenceName, destPrefix, destName, beanNames, BEAN_TYPE.ENTITY); + } + else + if (org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.MESSAGE_DRIVEN.equals(ejbType)) { + addMsgDrvConnectionFactoryReference(connectionFactoryName, ejbName); + addMsgDrvMsgDestReference(referenceName, destPrefix, destName, ejbName); + } + + } + + /** * Add a new message destination reference to the beans of the given type without it. * * @param msgDestRefName message destination reference name + * @param destName message destination name + * @param detPrefix message destination prefix (queue/ ot topic/) * @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, + private void addMsgDestReference(final String msgDestRefName, final String destPrefix, final String destName, final Set beanNames, final BEAN_TYPE beanType) throws ConfigurationException { modifyJboss(new JbossModifier() { public void modify(Jboss modifiedJboss) { - JbossMsgDestRefModifier.modify(modifiedJboss, msgDestRefName, beanNames, beanType, destPrefix); + JbossMsgDestRefModifier.modify(modifiedJboss, msgDestRefName, beanNames, beanType, destPrefix, destName); } }); } @@ -925,15 +1081,17 @@ * 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 + * @param destName message destination name + * @param destPrefix message destination prefix (queue/ ot topic/) + * @param mdbName the MDB (ejb-name value) which might need to add + * message destination reference specified by msgDestRefName */ private void addMsgDrvMsgDestReference(final String msgDestRefName, final String destPrefix, - final Map beans) throws ConfigurationException + final String destName, final String mdbName) throws ConfigurationException { modifyJboss(new JbossModifier() { public void modify(Jboss modifiedJboss) { - JbossMsgDestRefModifier.modifyMsgDrv(modifiedJboss, msgDestRefName, beans, destPrefix); + JbossMsgDestRefModifier.modifyMsgDrv(modifiedJboss, msgDestRefName, mdbName, destPrefix, destName); } }); } Index: serverplugins/jboss4/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.5 diff -u -r1.5 JBDeploymentConfiguration.java --- serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/JBDeploymentConfiguration.java 29 Mar 2007 23:05:15 -0000 1.5 +++ serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/JBDeploymentConfiguration.java 5 Apr 2007 15:17:07 -0000 @@ -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,46 @@ }); } + public void bindDatasourceReference(String referenceName, String jndiName) throws ConfigurationException {} + + public void bindDatasourceReferenceForEjb(String ejbName, String ejbType, + String referenceName, String jndiName) throws ConfigurationException {} + + public String findDatasourceJndiName(String referenceName) throws ConfigurationException { + return null; + } + + public String findDatasourceJndiNameForEjb(String ejbName, String referenceName) throws ConfigurationException { + return null; + } + + private MessageDestinationSupport getMessageDestinationsSupport() { + if (destSupport == null) { + destSupport = new MessageDestinationSupport(resourceDir); + } + return destSupport; + } + + public Set getMessageDestinations() throws ConfigurationException { + return getMessageDestinationsSupport().getMessageDestinations(); + } + + public MessageDestination createMessageDestination(String name, MessageDestination.Type type) + throws UnsupportedOperationException, ConfigurationException { + return getMessageDestinationsSupport().createMessageDestination(name, type); + } + + public void bindMdbToMessageDestination(String mdbName, String name, MessageDestination.Type type) throws ConfigurationException {} + + public String findMessageDestinationName(String mdbName) throws ConfigurationException { + return null; + } + + public void bindMessageDestinationReference(String referenceName, String connectionFactoryName, + String destName, MessageDestination.Type type) throws ConfigurationException {} + + public void bindMessageDestinationReferenceForEjb(String ejbName, String ejbType, + String referenceName, String connectionFactoryName, + String destName, MessageDestination.Type type) throws ConfigurationException {} } Index: serverplugins/jboss4/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.3 diff -u -r1.3 JBossDatasourceManager.java --- serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/JBossDatasourceManager.java 29 Mar 2007 23:05:16 -0000 1.3 +++ serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/JBossDatasourceManager.java 5 Apr 2007 15:17:07 -0000 @@ -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: serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/JbossDataSourceRefModifier.java =================================================================== RCS file: /cvs/serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/JbossDataSourceRefModifier.java,v retrieving revision 1.2 diff -u -r1.2 JbossDataSourceRefModifier.java --- serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/JbossDataSourceRefModifier.java 12 Oct 2006 14:38:00 -0000 1.2 +++ serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/JbossDataSourceRefModifier.java 5 Apr 2007 15:17:07 -0000 @@ -259,5 +259,45 @@ } } + + /** + * Add a reference to the given resource to the message-driven bean if it does not exist yet. + * + * @param modifiedJboss Jboss graph instance being modified + * @param resRefName resource reference name + * @param mdbName the MDB (ejb-name) which might need to add resource reference specified by resRefName + * @param jndiName JNDI name of the resource + */ + static void modifyMsgDrv(Jboss modifiedJboss, String resRefName, String mdbName, String jndiName) { + + if (modifiedJboss.getEnterpriseBeans() == null) + modifiedJboss.setEnterpriseBeans(new EnterpriseBeans()); + + addMsgDrvResReference(modifiedJboss, resRefName, mdbName, jndiName); + } + + private static void addMsgDrvResReference(Jboss modifiedJboss, String resRefName, String mdbName, String jndiName) { + + EnterpriseBeans eb = modifiedJboss.getEnterpriseBeans(); + + for (MessageDriven mdb : eb.getMessageDriven()) { + String ejbName = mdb.getEjbName(); + if (mdbName.equals(ejbName)) { // msgdrv found -> check whether it has the resource-ref + ResourceRef[] resourceRefs = mdb.getResourceRef(); + int j = 0; + for ( ; j < resourceRefs.length; j++) { + String rrn = resourceRefs[j].getResRefName(); + if (resRefName.equals(rrn)) + return; // resource-ref found + } + if (j == resourceRefs.length) {// resource-ref not found + ResourceRef newRR = new ResourceRef(); + newRR.setResRefName(resRefName); + newRR.setJndiName(jndiName); + mdb.addResourceRef(newRR); + } + } + } + } } Index: serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/JbossMsgDestRefModifier.java =================================================================== RCS file: /cvs/serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/JbossMsgDestRefModifier.java,v retrieving revision 1.2 diff -u -r1.2 JbossMsgDestRefModifier.java --- serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/JbossMsgDestRefModifier.java 12 Oct 2006 14:38:01 -0000 1.2 +++ serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/JbossMsgDestRefModifier.java 5 Apr 2007 15:17:07 -0000 @@ -53,8 +53,10 @@ * @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 * @param destPrefix prefix of the message destination + * @param destName message destination name */ - static void modify(Jboss modifiedJboss, String msgDestRefName, Set beanNames, BEAN_TYPE beanType, String destPrefix) { + static void modify(Jboss modifiedJboss, String msgDestRefName, Set beanNames, + BEAN_TYPE beanType, String destPrefix, String destName) { assert(beanNames.size() > 0); @@ -62,10 +64,10 @@ modifiedJboss.setEnterpriseBeans(new EnterpriseBeans()); if (beanType == BEAN_TYPE.SESSION) { - addSessionMsgDestReference(modifiedJboss, msgDestRefName, beanNames, destPrefix); + addSessionMsgDestReference(modifiedJboss, msgDestRefName, beanNames, destPrefix, destName); } else if (beanType == BEAN_TYPE.ENTITY) { - addEntityMsgDestReference(modifiedJboss, msgDestRefName, beanNames, destPrefix); + addEntityMsgDestReference(modifiedJboss, msgDestRefName, beanNames, destPrefix, destName); } } @@ -76,8 +78,10 @@ * @param resRefName message destination reference name * @param sessionNames the sessions (ejb-name value) which might need to add message destination reference specified by msgDestRefName * @param destPrefix prefix of the message destination + * @param destName message destination name */ - private static void addSessionMsgDestReference(Jboss modifiedJboss, String msgDestRefName, Set sessionNames, String destPrefix) { + private static void addSessionMsgDestReference(Jboss modifiedJboss, String msgDestRefName, + Set sessionNames, String destPrefix, String destName) { List/**/ sesssionsWithoutReference = new LinkedList(); @@ -119,7 +123,7 @@ for (Iterator it = sesssionsWithoutReference.iterator(); it.hasNext(); ) { MessageDestinationRef mdr = new MessageDestinationRef(); mdr.setMessageDestinationRefName(msgDestRefName); - String jndiName = getJndiName(msgDestRefName, destPrefix); + String jndiName = getJndiName(destName, destPrefix); mdr.setJndiName(jndiName); Session session = (Session)it.next(); session.addMessageDestinationRef(mdr); @@ -134,8 +138,10 @@ * @param resRefName message destination reference name * @param sessionNames the entities (ejb-name value) which might need to add message destination reference specified by msgDestRefName * @param destPrefix prefix of the message destination + * @param destName message destination name */ - private static void addEntityMsgDestReference(Jboss modifiedJboss, String msgDestRefName, Set entityNames, String destPrefix) { + private static void addEntityMsgDestReference(Jboss modifiedJboss, String msgDestRefName, + Set entityNames, String destPrefix, String destName) { List/**/ entitiesWithoutReference = new LinkedList(); @@ -177,7 +183,7 @@ for (Iterator it = entitiesWithoutReference.iterator(); it.hasNext(); ) { MessageDestinationRef mdr = new MessageDestinationRef(); mdr.setMessageDestinationRefName(msgDestRefName); - String jndiName = getJndiName(msgDestRefName, destPrefix); + String jndiName = getJndiName(destName, destPrefix); mdr.setJndiName(jndiName); Entity entity = (Entity)it.next(); entity.addMessageDestinationRef(mdr); @@ -262,13 +268,53 @@ } - private static String getJndiName(String msgDestRefName, String destPrefix) { - String jndiName = msgDestRefName; - // 'jms/' prefix automatically prepended to the selected message destination during 'Send JMS Message' action - if (msgDestRefName.startsWith("jms/")) // NOI18N - jndiName = destPrefix + msgDestRefName.substring("jms/".length()); //replace 'jms/' with the correct prefix + /** + * Add a reference to the given message destination to the message-driven beans if it does not exist yet. + * + * @param modifiedJboss Jboss graph instance being modified + * @param msgDestRefName message destination reference name + * @param mdbName the MDB (ejb-name value) which might need to add message + * destination reference specified by msgDestRefName + * @param destPrefix prefix of the message destination + * @param destName message destination name + */ + static void modifyMsgDrv(Jboss modifiedJboss, String msgDestRefName, + String mdbName, String destPrefix, String destName) { - return jndiName; + if (modifiedJboss.getEnterpriseBeans() == null) + modifiedJboss.setEnterpriseBeans(new EnterpriseBeans()); + + addMsgDrvMsgDestReference(modifiedJboss, msgDestRefName, mdbName, destPrefix, destName); + } + + private static void addMsgDrvMsgDestReference(Jboss modifiedJboss, String msgDestRefName, + String mdbName, String destPrefix, String destName) { + + EnterpriseBeans eb = modifiedJboss.getEnterpriseBeans(); + + for (MessageDriven mdb : eb.getMessageDriven()) { + String ejbName = mdb.getEjbName(); + if (mdbName.equals(ejbName)) { // msgdrv found -> check whether it has the message-destination-ref + MessageDestinationRef[] msgDestRefs = mdb.getMessageDestinationRef(); + int j = 0; + for ( ; j < msgDestRefs.length; j++) { + String mdrn = msgDestRefs[j].getMessageDestinationRefName(); + if (msgDestRefName.equals(mdrn)) + return; // message-destination-ref found + } + if (j == msgDestRefs.length) { // message-destination-ref not found + MessageDestinationRef mdr = new MessageDestinationRef(); + mdr.setMessageDestinationRefName(msgDestRefName); + String jndiName = getJndiName(destName, destPrefix); + mdr.setJndiName(jndiName); + mdb.addMessageDestinationRef(mdr); + } + } + } + } + + private static String getJndiName(String destName, String destPrefix) { + return destPrefix + destName; } } Index: serverplugins/jboss4/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.6 diff -u -r1.6 WarDeploymentConfiguration.java --- serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/WarDeploymentConfiguration.java 29 Mar 2007 23:05:16 -0000 1.6 +++ serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/WarDeploymentConfiguration.java 5 Apr 2007 15:17:07 -0000 @@ -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. */ @@ -29,6 +29,7 @@ import javax.swing.text.StyledDocument; import org.netbeans.modules.j2ee.dd.api.web.WebApp; import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException; +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.ContextRootConfiguration; import org.netbeans.modules.j2ee.deployment.plugins.spi.config.DatasourceConfiguration; @@ -54,7 +55,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 +101,10 @@ return true; } + public boolean supportsCreateMessageDestination() { + return true; + } + /** * Return context path. * @@ -162,7 +167,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 +202,29 @@ } } + public void bindDatasourceReference(String referenceName, String jndiName) throws ConfigurationException { + addResReference(referenceName, jndiName); + } + + public String findDatasourceJndiName(String referenceName) throws ConfigurationException { + + ResourceRef resourceRefs[] = getJbossWeb().getResourceRef(); + for (ResourceRef resourceRef : resourceRefs) { + String rrn = resourceRef.getResRefName(); + if (referenceName.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 +241,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); } }); @@ -253,6 +275,23 @@ }); } + public void bindMessageDestinationReference(String referenceName, String connectionFactoryName, + String destName, MessageDestination.Type type) throws ConfigurationException { + + addConnectionFactoryReference(connectionFactoryName); + + String jndiName = null; + if (MessageDestination.Type.QUEUE.equals(type)) { + jndiName = "queue/" + destName; + } + else + if (MessageDestination.Type.TOPIC.equals(type)) { + jndiName = "topic/" + destName; + } + + addMsgDestReference(referenceName, jndiName); + } + /** * Add a new connection factory reference. * @@ -287,7 +326,7 @@ * @param name message destination name * @param destPrefix MDB destination prefix */ - private void addMsgDestReference(final String name, final String destPrefix) throws ConfigurationException { + private void addMsgDestReference(final String name, final String jndiName) throws ConfigurationException { modifyJbossWeb(new JbossWebModifier() { public void modify(JbossWeb modifiedJbossWeb) { @@ -304,9 +343,6 @@ //if it doesn't exist yet, create a new one MessageDestinationRef mdr = new MessageDestinationRef(); mdr.setMessageDestinationRefName(name); - String jndiName = name; - if (name.startsWith("jms/")) // prefix automatically prepended to the selected message destination during 'Send JMS Message' action - jndiName = destPrefix + name.substring("jms/".length()); //replace 'jms/' with the correct prefix mdr.setJndiName(jndiName); modifiedJbossWeb.addMessageDestinationRef(mdr); } @@ -366,7 +402,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: serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/mdb/JBossMessageDestination.java =================================================================== RCS file: serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/mdb/JBossMessageDestination.java diff -N serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/mdb/JBossMessageDestination.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/mdb/JBossMessageDestination.java 5 Apr 2007 15:17:07 -0000 @@ -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 name; + private Type type; + + public JBossMessageDestination(String name, Type type) { + this.name = name; + this.type = type; + } + + public String getName() { + return name; + } + + public Type getType() { + return type; + } + +} Index: serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/mdb/JBossMessageDestinationDeployment.java =================================================================== RCS file: serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/mdb/JBossMessageDestinationDeployment.java diff -N serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/mdb/JBossMessageDestinationDeployment.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/mdb/JBossMessageDestinationDeployment.java 5 Apr 2007 15:17:07 -0000 @@ -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: serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/mdb/MessageDestinationSupport.java =================================================================== RCS file: serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/mdb/MessageDestinationSupport.java diff -N serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/mdb/MessageDestinationSupport.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/mdb/MessageDestinationSupport.java 5 Apr 2007 15:17:07 -0000 @@ -0,0 +1,169 @@ +/* + * 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 name, MessageDestination.Type type) + throws UnsupportedOperationException, ConfigurationException { + // TODO write into file + return new JBossMessageDestination(name, 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: serverplugins/jboss4/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.5 diff -u -r1.5 JBOptionalDeploymentManagerFactory.java --- serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/JBOptionalDeploymentManagerFactory.java 29 Mar 2007 23:05:17 -0000 1.5 +++ serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/JBOptionalDeploymentManagerFactory.java 5 Apr 2007 15:17:07 -0000 @@ -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: serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/resources/jboss-service_4_0.dtd =================================================================== RCS file: serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/resources/jboss-service_4_0.dtd diff -N serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/resources/jboss-service_4_0.dtd --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/resources/jboss-service_4_0.dtd 5 Apr 2007 15:17:07 -0000 @@ -0,0 +1,287 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: serverplugins/sun/appsrv81/nbproject/project.xml =================================================================== RCS file: /cvs/serverplugins/sun/appsrv81/nbproject/project.xml,v retrieving revision 1.26 diff -u -r1.26 project.xml --- serverplugins/sun/appsrv81/nbproject/project.xml 9 Nov 2006 16:54:07 -0000 1.26 +++ serverplugins/sun/appsrv81/nbproject/project.xml 5 Apr 2007 15:17:07 -0000 @@ -148,6 +148,7 @@ 4 + 1.25 Index: serverplugins/sun/appsrv81/src/org/netbeans/modules/j2ee/sun/ide/j2ee/ModuleConfigurationImpl.java =================================================================== RCS file: /cvs/serverplugins/sun/appsrv81/src/org/netbeans/modules/j2ee/sun/ide/j2ee/ModuleConfigurationImpl.java,v retrieving revision 1.2 diff -u -r1.2 ModuleConfigurationImpl.java --- serverplugins/sun/appsrv81/src/org/netbeans/modules/j2ee/sun/ide/j2ee/ModuleConfigurationImpl.java 29 Mar 2007 23:05:19 -0000 1.2 +++ serverplugins/sun/appsrv81/src/org/netbeans/modules/j2ee/sun/ide/j2ee/ModuleConfigurationImpl.java 5 Apr 2007 15:17:07 -0000 @@ -210,5 +210,19 @@ new UnsupportedOperationException()); } + public void bindDatasourceReference(String jndiName, String dsJNDIName) throws ConfigurationException { + } + + public void bindDatasourceReferenceForEjb(String ejbName, String ejbType, String jndiName, String dsJNDIName) throws ConfigurationException { + } + + public String findDatasourceJndiName(String jndiName) throws ConfigurationException { + return null; + } + + public String findDatasourceJndiNameForEjb(String ejbName, String jndiName) throws ConfigurationException { + return null; + } + } Index: tomcatint/tomcat5/nbproject/project.xml =================================================================== RCS file: /cvs/tomcatint/tomcat5/nbproject/project.xml,v retrieving revision 1.21 diff -u -r1.21 project.xml --- tomcatint/tomcat5/nbproject/project.xml 31 Mar 2007 10:07:40 -0000 1.21 +++ tomcatint/tomcat5/nbproject/project.xml 5 Apr 2007 15:17:07 -0000 @@ -112,7 +112,7 @@ 4 - 1.24 + 1.25 Index: tomcatint/tomcat5/src/org/netbeans/modules/tomcat5/config/TomcatModuleConfiguration.java =================================================================== RCS file: /cvs/tomcatint/tomcat5/src/org/netbeans/modules/tomcat5/config/TomcatModuleConfiguration.java,v retrieving revision 1.2 diff -u -r1.2 TomcatModuleConfiguration.java --- tomcatint/tomcat5/src/org/netbeans/modules/tomcat5/config/TomcatModuleConfiguration.java 29 Mar 2007 23:05:32 -0000 1.2 +++ tomcatint/tomcat5/src/org/netbeans/modules/tomcat5/config/TomcatModuleConfiguration.java 5 Apr 2007 15:17:07 -0000 @@ -612,6 +612,24 @@ else if (contextPath.indexOf("//")>=0) correct=false; //NOI18N return correct; } + + public void bindDatasourceReference(String referenceName, String jndiName) throws ConfigurationException { + // TODO implement + } + + public void bindDatasourceReferenceForEjb(String ejbName, String ejbType, String referenceName, String jndiName) throws ConfigurationException { + // TODO implement + } + + public String findDatasourceJndiName(String referenceName) throws ConfigurationException { + // TODO implement + return null; + } + + public String findDatasourceJndiNameForEjb(String ejbName, String referenceName) throws ConfigurationException { + // TODO implement + return null; + } // private helper interface ----------------------------------------------- Index: j2ee/ejbcore/nbproject/project.xml =================================================================== RCS file: /cvs/j2ee/ejbcore/nbproject/project.xml,v retrieving revision 1.19 diff -u -r1.19 project.xml --- j2ee/ejbcore/nbproject/project.xml 29 Mar 2007 23:04:38 -0000 1.19 +++ j2ee/ejbcore/nbproject/project.xml 5 Apr 2007 15:17:07 -0000 @@ -176,7 +176,7 @@ 4 - 1.23 + 1.25 @@ -366,6 +366,14 @@ 6.2 + + + + org.netbeans.api.web.webmodule + + + + 1.8 Index: j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/action/SendJMSGenerator.java =================================================================== RCS file: /cvs/j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/action/SendJMSGenerator.java,v retrieving revision 1.2 diff -u -r1.2 SendJMSGenerator.java --- j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/action/SendJMSGenerator.java 15 Feb 2007 10:17:00 -0000 1.2 +++ j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/action/SendJMSGenerator.java 5 Apr 2007 15:17:07 -0000 @@ -40,6 +40,14 @@ import org.netbeans.modules.j2ee.common.source.AbstractTask; import org.netbeans.modules.j2ee.dd.api.common.MessageDestinationRef; import org.netbeans.modules.j2ee.dd.api.common.ResourceRef; +import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider; +import org.netbeans.modules.j2ee.dd.api.ejb.Ejb; +import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar; +import org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans; +import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException; +import org.netbeans.modules.j2ee.deployment.common.api.MessageDestination; +import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; +import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; import org.netbeans.modules.j2ee.ejbcore.Utils; import org.netbeans.modules.j2ee.ejbcore._RetoucheUtil; import org.netbeans.modules.j2ee.ejbcore.ui.logicalview.entres.JMSDestination; @@ -61,7 +69,14 @@ this.jmsDestination = jmsDestination; } - public void genMethods(EnterpriseReferenceContainer container, final String className, FileObject fileObject, ServiceLocatorStrategy slStrategy) throws IOException { + public void genMethods( + EnterpriseReferenceContainer container, + final String className, + FileObject fileObject, + ServiceLocatorStrategy slStrategy, + J2eeModuleProvider j2eeModuleProvider, + MessageDestination dest) throws IOException { + JavaSource javaSource = JavaSource.forFileObject(fileObject); final boolean[] isInjectionTarget = new boolean[1]; javaSource.runUserActionTask(new AbstractTask() { @@ -89,7 +104,100 @@ String sendMethodName = createSendMethod(fileObject, className, jmsDestination.getDestination()); createJMSProducer(fileObject, className, factoryName, connectionFactoryFieldName, destinationName, destinationFieldName,sendMethodName, slStrategy); + +if (System.getProperties().getProperty("resource-api-redesign") != null) { + + if (dest != null) { + try { + if (j2eeModuleProvider.getJ2eeModule().getModuleType().equals(J2eeModule.WAR)) { + //in the current implementation, reference name is the same as the destination name... + j2eeModuleProvider.getConfigSupport().bindMessageDestinationReference( + dest.getName(), factoryName, dest.getName(), dest.getType()); + } + else + if (j2eeModuleProvider.getJ2eeModule().getModuleType().equals(J2eeModule.EJB)) { + //in the current implementation, reference name is the same as the destination name... + bindMessageDestinationReferenceForEjb(j2eeModuleProvider, fileObject, className, + dest.getName(), factoryName, dest.getName(), dest.getType()); + } + } + catch (ConfigurationException ce) { + } + } +} + + } + +private void bindMessageDestinationReferenceForEjb(J2eeModuleProvider j2eeModuleProvider, + FileObject fileObject, String className, + String referenceName, String connectionFactoryName, + String destName, MessageDestination.Type destType) throws ConfigurationException { + + EjbJar dd = null; + try { + dd = findDDRoot(fileObject); + } + catch (IOException ioe) { + // TODO + } + if (dd == null) { + return; + } + + EnterpriseBeans beans = dd.getEnterpriseBeans(); + if (beans == null) { + return; } + + String ejbName = getEjbName(beans, className); + if (ejbName == null) { + return; + } + + String ejbType = getEjbType(beans, className); + if (ejbType == null) { + return; + } + + j2eeModuleProvider.getConfigSupport().bindMessageDestinationReferenceForEjb( + ejbName, ejbType, referenceName, connectionFactoryName, destName, destType); +} + +private EjbJar findDDRoot(FileObject fileObject) throws IOException { + org.netbeans.modules.j2ee.api.ejbjar.EjbJar ejbJar = org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJar(fileObject); + assert ejbJar != null; + return DDProvider.getDefault().getMergedDDRoot(ejbJar.getMetadataUnit()); +} + +private String getEjbName(EnterpriseBeans beans, String className) { + Ejb ejb = (Ejb) beans.findBeanByName(EnterpriseBeans.SESSION, Ejb.EJB_CLASS, className); + if (ejb == null) { + ejb = (Ejb) beans.findBeanByName(EnterpriseBeans.ENTITY, Ejb.EJB_CLASS, className); + } + if (ejb == null) { + ejb = (Ejb) beans.findBeanByName(EnterpriseBeans.MESSAGE_DRIVEN, Ejb.EJB_CLASS, className); + } + + return ejb.getEjbName(); +} + +private String getEjbType(EnterpriseBeans beans, String className) { + String type = null; + + if (beans.findBeanByName(EnterpriseBeans.SESSION, Ejb.EJB_CLASS, className) != null) { + type = EnterpriseBeans.SESSION; + } + else + if (beans.findBeanByName(EnterpriseBeans.ENTITY, Ejb.EJB_CLASS, className) != null) { + type = EnterpriseBeans.ENTITY; + } + else + if (beans.findBeanByName(EnterpriseBeans.MESSAGE_DRIVEN, Ejb.EJB_CLASS, className) != null) { + type = EnterpriseBeans.MESSAGE_DRIVEN; + } + + return type; +} private String generateConnectionFactoryReference(EnterpriseReferenceContainer container, FileObject referencingFile, String referencingClass) throws IOException { ResourceRef ref = container.createResourceRef(referencingClass); Index: j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/action/UseDatabaseGenerator.java =================================================================== RCS file: /cvs/j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/action/UseDatabaseGenerator.java,v retrieving revision 1.4 diff -u -r1.4 UseDatabaseGenerator.java --- j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/action/UseDatabaseGenerator.java 15 Feb 2007 12:48:35 -0000 1.4 +++ j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/action/UseDatabaseGenerator.java 5 Apr 2007 15:17:07 -0000 @@ -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. */ @@ -37,7 +37,14 @@ import org.netbeans.modules.j2ee.common.queries.api.InjectionTargetQuery; import org.netbeans.modules.j2ee.common.source.AbstractTask; import org.netbeans.modules.j2ee.dd.api.common.ResourceRef; +import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar; +import org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans; +import org.netbeans.modules.j2ee.dd.api.ejb.Ejb; +import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider; +import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException; import org.netbeans.modules.j2ee.deployment.common.api.Datasource; +import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; +import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; import org.netbeans.modules.j2ee.ejbcore.Utils; import org.netbeans.modules.j2ee.ejbcore._RetoucheUtil; import org.netbeans.modules.j2ee.ejbcore.ui.logicalview.entres.ServiceLocatorStrategy; @@ -52,8 +59,11 @@ public UseDatabaseGenerator() { } - public void generate(final FileObject fileObject, final ElementHandle elementHandle, final Datasource datasource, - final boolean createServerResources, String serviceLocator) throws IOException { + public void generate(final FileObject fileObject, final ElementHandle elementHandle, + final J2eeModuleProvider j2eeModuleProvider, final String datasourceReferenceName, + final Datasource datasource, final boolean createServerResources, String serviceLocator) + throws IOException, ConfigurationException + { Project project = FileOwnerQuery.getOwner(fileObject); ServiceLocatorStrategy serviceLocatorStrategy = (serviceLocator == null) ? null : ServiceLocatorStrategy.create(project, fileObject, serviceLocator); @@ -73,9 +83,105 @@ generateLookupMethod(fileObject, className, jndiName, serviceLocatorStrategy); } } + +if (System.getProperties().getProperty("resource-api-redesign") != null) { + J2eeModule module = j2eeModuleProvider.getJ2eeModule(); + if (isWebModule(module)) { + bindDataSourceReference(j2eeModuleProvider, datasourceReferenceName, datasource); + } + else if (isEjbModule(module)) { + bindDataSourceReferenceForEjb(j2eeModuleProvider, datasourceReferenceName, datasource, fileObject, elementHandle); + } +} + if (serviceLocator != null) { erc.setServiceLocatorName(serviceLocator); } + } + + private void bindDataSourceReference(J2eeModuleProvider j2eeModuleProvider, String dsRefName, Datasource datasource) + throws ConfigurationException { + + String dsJndiName = datasource.getJndiName(); + j2eeModuleProvider.getConfigSupport().bindDatasourceReference(dsRefName, dsJndiName); + } + + private void bindDataSourceReferenceForEjb(J2eeModuleProvider j2eeModuleProvider, String dsRefName, Datasource datasource, + FileObject fileObject, ElementHandle elementHandle) throws ConfigurationException { + + String dsJndiName = datasource.getJndiName(); + + EjbJar dd = null; + try { + dd = findDDRoot(fileObject); + } + catch (IOException ioe) { + // TODO + } + if (dd == null) { + return; + } + + EnterpriseBeans beans = dd.getEnterpriseBeans(); + if (beans == null) { + return; + } + + String ejbName = getEjbName(beans, elementHandle.getQualifiedName()); + if (ejbName == null) { + return; + } + + String ejbType = getEjbType(beans, elementHandle.getQualifiedName()); + if (ejbType == null) { + return; + } + + j2eeModuleProvider.getConfigSupport().bindDatasourceReferenceForEjb(ejbName, ejbType, dsRefName, dsJndiName); + } + + private EjbJar findDDRoot(FileObject fileObject) throws IOException { + org.netbeans.modules.j2ee.api.ejbjar.EjbJar ejbJar = org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJar(fileObject); + assert ejbJar != null; + return DDProvider.getDefault().getMergedDDRoot(ejbJar.getMetadataUnit()); + } + + private boolean isWebModule(J2eeModule module) { + return module.getModuleType().equals(J2eeModule.WAR); + } + + private boolean isEjbModule(J2eeModule module) { + return module.getModuleType().equals(J2eeModule.EJB); + } + + private String getEjbName(EnterpriseBeans beans, String className) { + Ejb ejb = (Ejb) beans.findBeanByName(EnterpriseBeans.SESSION, Ejb.EJB_CLASS, className); + if (ejb == null) { + ejb = (Ejb) beans.findBeanByName(EnterpriseBeans.ENTITY, Ejb.EJB_CLASS, className); + } + if (ejb == null) { + ejb = (Ejb) beans.findBeanByName(EnterpriseBeans.MESSAGE_DRIVEN, Ejb.EJB_CLASS, className); + } + + return ejb.getEjbName(); + } + + private String getEjbType(EnterpriseBeans beans, String className) { + String type = null; + + if (beans.findBeanByName(EnterpriseBeans.SESSION, Ejb.EJB_CLASS, className) != null) { + type = EnterpriseBeans.SESSION; + } + else + if (beans.findBeanByName(EnterpriseBeans.ENTITY, Ejb.EJB_CLASS, className) != null) { + type = EnterpriseBeans.ENTITY; + } + else + if (beans.findBeanByName(EnterpriseBeans.MESSAGE_DRIVEN, Ejb.EJB_CLASS, className) != null) { + type = EnterpriseBeans.MESSAGE_DRIVEN; + } + + return type; } private String generateJNDILookup(String jndiName, EnterpriseReferenceContainer enterpriseReferenceContainer, Index: j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/api/codegeneration/MessageGenerator.java =================================================================== RCS file: /cvs/j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/api/codegeneration/MessageGenerator.java,v retrieving revision 1.18 diff -u -r1.18 MessageGenerator.java --- j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/api/codegeneration/MessageGenerator.java 29 Mar 2007 23:04:39 -0000 1.18 +++ j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/api/codegeneration/MessageGenerator.java 5 Apr 2007 15:17:07 -0000 @@ -106,6 +106,23 @@ ErrorManager.getDefault().notify(ex); } } + +if (System.getProperties().getProperty("resource-api-redesign") != null) { + try { + Project project = FileOwnerQuery.getOwner(pkg); + J2eeModuleProvider j2eeModuleProvider = (J2eeModuleProvider) project.getLookup().lookup(J2eeModuleProvider.class); + if (isQueue) { + j2eeModuleProvider.getConfigSupport().bindMdbToMessageDestination(ejbName, "MyQueue", org.netbeans.modules.j2ee.deployment.common.api.MessageDestination.Type.QUEUE); + } + else { + j2eeModuleProvider.getConfigSupport().bindMdbToMessageDestination(ejbName, "MyTopic", org.netbeans.modules.j2ee.deployment.common.api.MessageDestination.Type.TOPIC); + } + } + catch (ConfigurationException ce) { + // TODO inform user + } +} + } return resultFileObject; } Index: j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/mdb/MessageEJBWizard.java =================================================================== RCS file: /cvs/j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/mdb/MessageEJBWizard.java,v retrieving revision 1.8 diff -u -r1.8 MessageEJBWizard.java --- j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/mdb/MessageEJBWizard.java 18 Jan 2007 22:53:31 -0000 1.8 +++ j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/mdb/MessageEJBWizard.java 5 Apr 2007 15:17:07 -0000 @@ -13,13 +13,14 @@ * "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.ejbcore.ejb.wizard.mdb; import java.io.IOException; +import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; import org.netbeans.modules.j2ee.ejbcore.api.codegeneration.MessageGenerator; import java.util.Collections; import java.util.NoSuchElementException; @@ -34,6 +35,8 @@ import org.netbeans.spi.project.ui.templates.support.Templates; import org.openide.filesystems.FileObject; import org.netbeans.modules.j2ee.common.Util; +import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException; +import org.netbeans.modules.j2ee.deployment.common.api.MessageDestination; import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; import org.netbeans.modules.j2ee.ejbcore.Utils; import org.openide.WizardDescriptor; @@ -73,6 +76,27 @@ Util.hideLabelAndLabelFor(jComponent, NbBundle.getMessage(MessageEJBWizard.class, "LBL_JavaTargetChooserPanelGUI_CreatedFile_Label")); panels = new WizardDescriptor.Panel[] {wizardPanel}; Utils.mergeSteps(wiz, panels, SESSION_STEPS); + +if (System.getProperties().getProperty("resource-api-redesign") != null) { + J2eeModuleProvider provider = project.getLookup().lookup(J2eeModuleProvider.class); + try { + Set moduleDestinations = provider.getConfigSupport().getMessageDestinations(); + for (MessageDestination md : moduleDestinations) { + System.out.println(md.getName() + " ~ " + md.getType()); + } + if (provider.getConfigSupport().supportsCreateMessageDestination()) { + MessageDestination dest = provider.getConfigSupport().createMessageDestination("TestMsgDest01", MessageDestination.Type.TOPIC); + } + Set serverDestinations = provider.getConfigSupport().getServerMessageDestinations(); + for (MessageDestination md : serverDestinations) { + System.out.println(md.getName() + " ~ " + md.getType()); + } + } + catch (ConfigurationException ce) { + + } +} + } public Set instantiate() throws IOException { Index: j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ui/logicalview/entres/MessageDestinationPanel.java =================================================================== RCS file: /cvs/j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ui/logicalview/entres/MessageDestinationPanel.java,v retrieving revision 1.5 diff -u -r1.5 MessageDestinationPanel.java --- j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ui/logicalview/entres/MessageDestinationPanel.java 18 Jan 2007 22:53:21 -0000 1.5 +++ j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ui/logicalview/entres/MessageDestinationPanel.java 5 Apr 2007 15:17:08 -0000 @@ -26,10 +26,16 @@ import java.beans.PropertyChangeListener; import java.io.IOException; import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import javax.swing.DefaultComboBoxModel; import javax.swing.JButton; import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar; +import org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans; +import org.netbeans.modules.j2ee.dd.api.ejb.MessageDriven; +import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException; +import org.netbeans.modules.j2ee.deployment.common.api.MessageDestination; +import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; import org.openide.DialogDisplayer; import org.openide.NotifyDescriptor; @@ -45,6 +51,12 @@ private DefaultComboBoxModel destinationModel; private final ServiceLocatorStrategyPanel slPanel; +private MessageDestination dest = null; + +public MessageDestination getDestination() { + return dest; +} + /** Creates new form MessageDestinationPanel */ public MessageDestinationPanel(final JButton okButton, String lastLocator) { initComponents(); @@ -103,6 +115,25 @@ } private void populateEjbDestinationCombo(Object selectedItem) throws IOException { + +if (System.getProperties().getProperty("resource-api-redesign") != null) { + List names = getMdbNames(selectedItem); + for (String name : names) { + System.out.println(name); + } + if (names.size() > 0) { + String mdbName = names.get(0); + J2eeModuleProvider j2eeModuleProvider = controller.getJ2eeModuleProvider(selectedItem); + try { + String destName = j2eeModuleProvider.getConfigSupport().findMessageDestinationName(mdbName); + if (destName != null) { + dest = j2eeModuleProvider.getConfigSupport().findMessageDestination(destName); + } + } + catch (ConfigurationException ce) {} + } +} + EjbJar ejbJar = controller.getEjbJar(selectedItem); if (ejbJar != null) { List list = controller.extractEjbProjectDestinations(ejbJar, selectedItem); @@ -112,6 +143,31 @@ } } } + + private List getMdbNames(Object projectItem) throws IOException { + + List names = new LinkedList(); + + EjbJar ejbJar = controller.getEjbJar(projectItem); + if (ejbJar == null) { + return names; + } + + EnterpriseBeans eb = ejbJar.getEnterpriseBeans(); + if (eb == null) { + return names; + } + + MessageDriven[] mdbs = eb.getMessageDriven(); + for (MessageDriven mdb : mdbs) { + if (mdb.getEjbName() != null) { + names.add(mdb.getEjbName()); + } + } + + return names; + } + /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is Index: j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ui/logicalview/entres/MessageDestinationPanelController.java =================================================================== RCS file: /cvs/j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ui/logicalview/entres/MessageDestinationPanelController.java,v retrieving revision 1.5 diff -u -r1.5 MessageDestinationPanelController.java --- j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ui/logicalview/entres/MessageDestinationPanelController.java 9 Jan 2007 09:48:37 -0000 1.5 +++ j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ui/logicalview/entres/MessageDestinationPanelController.java 5 Apr 2007 15:17:08 -0000 @@ -31,6 +31,7 @@ import org.netbeans.modules.j2ee.dd.api.ejb.Ejb; import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar; import org.netbeans.modules.j2ee.dd.api.ejb.MessageDriven; +import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; import org.openide.ErrorManager; /** @@ -49,6 +50,11 @@ } } return projectViews.toArray(new ProjectView[projectViews.size()]); + } + + public J2eeModuleProvider getJ2eeModuleProvider(Object item) { + Project project = ((ProjectView) item).getProject(); + return project.getLookup().lookup(J2eeModuleProvider.class); } public EjbJar getEjbJar(Object item) throws IOException { Index: j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ui/logicalview/entres/SendJMSMessageAction.java =================================================================== RCS file: /cvs/j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ui/logicalview/entres/SendJMSMessageAction.java,v retrieving revision 1.17 diff -u -r1.17 SendJMSMessageAction.java --- j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ui/logicalview/entres/SendJMSMessageAction.java 13 Feb 2007 07:12:07 -0000 1.17 +++ j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ui/logicalview/entres/SendJMSMessageAction.java 5 Apr 2007 15:17:08 -0000 @@ -34,8 +34,12 @@ import org.netbeans.modules.j2ee.api.ejbjar.EnterpriseReferenceContainer; import org.netbeans.modules.j2ee.common.Util; import org.netbeans.modules.j2ee.common.source.AbstractTask; +import org.netbeans.modules.j2ee.dd.api.ejb.Ejb; import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar; +import org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans; import org.netbeans.modules.j2ee.dd.api.web.WebApp; +import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException; +import org.netbeans.modules.j2ee.deployment.common.api.MessageDestination; import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; @@ -111,8 +115,15 @@ ServiceLocatorStrategy.create(enterpriseProject, srcFile, serviceLocator); } + SendJMSGenerator generator = new SendJMSGenerator(destination); - generator.genMethods(erc, beanClass.getQualifiedName().toString(), srcFile, serviceLocatorStrategy); + generator.genMethods( + erc, + beanClass.getQualifiedName().toString(), + srcFile, + serviceLocatorStrategy, + enterpriseProject.getLookup().lookup(J2eeModuleProvider.class), + panel.getDestination()); if (serviceLocator != null) { erc.setServiceLocatorName(serviceLocator); } Index: j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ui/logicalview/entres/UseDatabaseAction.java =================================================================== RCS file: /cvs/j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ui/logicalview/entres/UseDatabaseAction.java,v retrieving revision 1.15 diff -u -r1.15 UseDatabaseAction.java --- j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ui/logicalview/entres/UseDatabaseAction.java 12 Feb 2007 07:06:37 -0000 1.15 +++ j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ui/logicalview/entres/UseDatabaseAction.java 5 Apr 2007 15:17:08 -0000 @@ -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. */ @@ -22,6 +22,8 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; import javax.lang.model.element.ElementKind; import javax.lang.model.element.TypeElement; import javax.swing.Action; @@ -33,9 +35,18 @@ import org.netbeans.api.project.Project; import org.netbeans.modules.j2ee.api.ejbjar.EnterpriseReferenceContainer; import org.netbeans.modules.j2ee.common.source.AbstractTask; +import org.netbeans.modules.j2ee.dd.api.common.ResourceRef; +import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar; +import org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans; +import org.netbeans.modules.j2ee.dd.api.ejb.Ejb; +import org.netbeans.modules.j2ee.dd.api.web.WebApp; +import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException; +import org.netbeans.modules.j2ee.deployment.common.api.Datasource; +import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; import org.netbeans.modules.j2ee.ejbcore._RetoucheUtil; import org.netbeans.modules.j2ee.ejbcore.action.UseDatabaseGenerator; +import org.netbeans.modules.web.api.webmodule.WebModule; import org.openide.DialogDescriptor; import org.openide.DialogDisplayer; import org.openide.ErrorManager; @@ -97,20 +108,126 @@ } }); selectDatabasePanel.checkDatasource(); + +if (System.getProperties().getProperty("resource-api-redesign") != null) { + try { + Map refs = getDataSourceReferences(j2eeModuleProvider, fileObject); + } + catch (ConfigurationException ce) { + //TODO notify user + } +} +String refName = "NameOfSelectedReference"; + Object option = DialogDisplayer.getDefault().notify(dialogDescriptor); if (option == NotifyDescriptor.OK_OPTION) { + UseDatabaseGenerator generator = new UseDatabaseGenerator(); - generator.generate( - fileObject, - elementHandle, - selectDatabasePanel.getDatasource(), - selectDatabasePanel.createServerResources(), - selectDatabasePanel.getServiceLocator() - ); + try { + generator.generate( + fileObject, + elementHandle, + j2eeModuleProvider, + refName, + selectDatabasePanel.getDatasource(), + selectDatabasePanel.createServerResources(), + selectDatabasePanel.getServiceLocator() + ); + } + catch (ConfigurationException ex) { + //TODO + } } return false; } + + private Map getDataSourceReferences(J2eeModuleProvider j2eeModuleProvider, FileObject fileObject) + throws ConfigurationException { + + HashMap references = new HashMap(); + + if (j2eeModuleProvider.getJ2eeModule().getModuleType().equals(J2eeModule.EJB)) { + EjbJar dd = findEjbDDRoot(fileObject); + if (dd == null) { + return references; + } + EnterpriseBeans beans = dd.getEnterpriseBeans(); + if (beans == null) { + return references; + } + + Ejb[] ejbs = beans.getEjbs(); + for (Ejb ejb : ejbs) { + ResourceRef[] refs = ejb.getResourceRef(); + for (ResourceRef ref : refs) { + String refName = ref.getResRefName(); + Datasource ds = findDatasourceForReferenceForEjb(j2eeModuleProvider, refName, ejb.getEjbName()); + if (ds != null) { + references.put(refName, ds); + System.out.println(refName + " ~ " + ds.getUrl()); + } + } + } + } + else + if (j2eeModuleProvider.getJ2eeModule().getModuleType().equals(J2eeModule.WAR)) { + WebApp dd = findWebDDRoot(fileObject); + if (dd == null) { + return references; + } + ResourceRef[] refs = dd.getResourceRef(); + for (ResourceRef ref : refs) { + String refName = ref.getResRefName(); + Datasource ds = findDatasourceForReference(j2eeModuleProvider, refName); + if (ds != null) { + references.put(refName, ds); + System.out.println(refName + " ~ " + ds.getUrl()); + } + } + } + + return references; + } + + private Datasource findDatasourceForReference(J2eeModuleProvider j2eeModuleProvider, String referenceName) throws ConfigurationException { + String jndiName = j2eeModuleProvider.getConfigSupport().findDatasourceJndiName(referenceName); + if (jndiName == null) { + return null; + } + return j2eeModuleProvider.getConfigSupport().findDatasource(jndiName); + } + + public Datasource findDatasourceForReferenceForEjb(J2eeModuleProvider j2eeModuleProvider, String referenceName, String ejbName) throws ConfigurationException { + String jndiName = j2eeModuleProvider.getConfigSupport().findDatasourceJndiNameForEjb(ejbName, referenceName); + if (jndiName == null) { + return null; + } + return j2eeModuleProvider.getConfigSupport().findDatasource(jndiName); + } + private EjbJar findEjbDDRoot(FileObject fileObject) throws ConfigurationException { + org.netbeans.modules.j2ee.api.ejbjar.EjbJar ejbJar = org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJar(fileObject); + assert ejbJar != null; + try { + return org.netbeans.modules.j2ee.dd.api.ejb.DDProvider.getDefault().getMergedDDRoot(ejbJar.getMetadataUnit()); + } + catch (IOException ioe) { + String msg = NbBundle.getMessage(UseDatabaseAction.class, "ERR_CannotReadEjbDD"); + throw new ConfigurationException(msg, ioe); + } + } + + private WebApp findWebDDRoot(FileObject fileObject) throws ConfigurationException { + WebModule mod = WebModule.getWebModule(fileObject); + try { + return org.netbeans.modules.j2ee.dd.api.web.DDProvider.getDefault().getMergedDDRoot(mod); + } + catch (IOException ioe) { + String msg = NbBundle.getMessage(UseDatabaseAction.class, "ERR_CannotReadWebDD"); + throw new ConfigurationException(msg, ioe); + } + } + protected boolean enable(Node[] nodes) { if (nodes == null || nodes.length != 1) { return false;