diff --git a/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/api/codegeneration/MessageGenerator.java b/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/api/codegeneration/MessageGenerator.java --- a/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/api/codegeneration/MessageGenerator.java +++ b/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/api/codegeneration/MessageGenerator.java @@ -74,11 +74,12 @@ import org.netbeans.modules.j2ee.dd.api.ejb.MessageDriven; import org.netbeans.modules.j2ee.dd.api.ejb.Method; import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException; +import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; import org.netbeans.modules.j2ee.ejbcore.EjbGenerationUtil; -import org.netbeans.modules.j2ee.ejbcore.ejb.wizard.mdb.ActivationConfigProperties; import org.netbeans.modules.j2ee.ejbcore.naming.EJBNameOptions; import org.netbeans.modules.javaee.resources.api.JndiResourcesDefinition; +import org.netbeans.modules.javaee.specs.support.api.JmsSupport; import org.openide.filesystems.FileObject; import org.openide.util.Exceptions; @@ -98,6 +99,8 @@ private final boolean isSimplified; private final boolean isXmlBased; private final Map properties; + private final Profile profile; + private final JmsSupport jmsSupport; // EJB naming options private final EJBNameOptions ejbNameOptions; @@ -110,11 +113,11 @@ private final Map templateParameters; - public static MessageGenerator create(Profile profile, String wizardTargetName, FileObject pkg, MessageDestination messageDestination, boolean isSimplified, Map properties) { - return new MessageGenerator(profile, wizardTargetName, pkg, messageDestination, isSimplified, properties, false); + public static MessageGenerator create(Profile profile, String wizardTargetName, FileObject pkg, MessageDestination messageDestination, boolean isSimplified, Map properties, JmsSupport jmsSupport) { + return new MessageGenerator(profile, wizardTargetName, pkg, messageDestination, isSimplified, properties, jmsSupport, false); } - - protected MessageGenerator(Profile profile, String wizardTargetName, FileObject pkg, MessageDestination messageDestination, boolean isSimplified, Map properties, boolean isTest) { + + protected MessageGenerator(Profile profile, String wizardTargetName, FileObject pkg, MessageDestination messageDestination, boolean isSimplified, Map properties, JmsSupport jmsSupport, boolean isTest) { this.pkg = pkg; this.messageDestination = messageDestination; this.isSimplified = isSimplified; @@ -127,11 +130,17 @@ this.packageName = EjbGenerationUtil.getSelectedPackageName(pkg); this.packageNameWithDot = packageName + "."; this.templateParameters = new HashMap(); + this.profile = profile; + this.jmsSupport = jmsSupport; + if (!Util.isAtLeastJavaEE7Web(profile) + && jmsSupport.getMessageDrivenMapping().activationConfigProperty() != null) { + properties.put(jmsSupport.getMessageDrivenMapping().activationConfigProperty(), messageDestination.getName()); + } // fill all possible template parameters this.templateParameters.put("package", packageName); this.templateParameters.put("messageDestinationName", messageDestination.getName()); this.templateParameters.put("activationConfigProperties", transformProperties(properties)); - this.templateParameters.put("useMappedName", useMappedName(profile, properties)); + this.templateParameters.put("useMappedName", useMappedName()); if (isTest) { // set date, time and user to values used in goldenfiles this.templateParameters.put("date", "{date}"); @@ -312,12 +321,13 @@ throw new UnsupportedOperationException("Method not implemented yet."); } - private static boolean useMappedName(Profile profile, Map acProperties) { + private boolean useMappedName() { + // JavaEE7 platform should always use portable, compatible way if (Util.isAtLeastJavaEE7Web(profile)) { - String destinationLookup = acProperties.get(ActivationConfigProperties.DESTINATION_LOOKUP); - return destinationLookup == null || destinationLookup.isEmpty(); + return false; + } else { + return jmsSupport.getMessageDrivenMapping().useMappedName(); } - return true; } public static final class KeyValuePair { diff --git a/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/mdb/MdbPropertiesPanelVisual.java b/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/mdb/MdbPropertiesPanelVisual.java --- a/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/mdb/MdbPropertiesPanelVisual.java +++ b/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/mdb/MdbPropertiesPanelVisual.java @@ -227,7 +227,7 @@ setProperty(ActivationConfigProperties.CLIENT_ID, destination.getName()); setProperty(ActivationConfigProperties.DESTINATION_TYPE, DestinationType.TOPIC); setProperty(ActivationConfigProperties.SUBSCRIPTION_DURABILITY, SubscriptionDurability.DURABLE); - setProperty(ActivationConfigProperties.SUBSCRIPTION_NAME, destination.getName()); + setProperty(ActivationConfigProperties.SUBSCRIPTION_NAME, destination.getName()); if (eeProjectCapabilities.isEjb32Supported()) { setProperty(ActivationConfigProperties.DESTINATION_LOOKUP, destination.getName()); } diff --git a/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/mdb/MdbWizard.java b/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/mdb/MdbWizard.java --- a/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/mdb/MdbWizard.java +++ b/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/mdb/MdbWizard.java @@ -59,6 +59,7 @@ import org.netbeans.modules.j2ee.core.api.support.wizard.Wizards; import org.netbeans.modules.j2ee.ejbcore.api.codegeneration.MessageGenerator; import org.netbeans.modules.j2ee.ejbcore.ejb.wizard.MultiTargetChooserPanel; +import org.netbeans.modules.javaee.specs.support.api.JmsSupport; import org.netbeans.spi.project.ui.templates.support.Templates; import org.openide.WizardDescriptor; import org.openide.filesystems.FileObject; @@ -120,7 +121,8 @@ pkg, ejbPanel.getDestination(), isSimplified, - propertiesPanel.getProperties()); + propertiesPanel.getProperties(), + JmsSupport.getInstance(Util.getPlatform(Templates.getProject(wiz)))); FileObject result = generator.generate(); return result == null ? Collections.EMPTY_SET : Collections.singleton(result); } diff --git a/javaee.specs.support/manifest.mf b/javaee.specs.support/manifest.mf --- a/javaee.specs.support/manifest.mf +++ b/javaee.specs.support/manifest.mf @@ -1,5 +1,5 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.javaee.specs.support/0 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/javaee/specs/support/resources/Bundle.properties -OpenIDE-Module-Specification-Version: 1.12 +OpenIDE-Module-Specification-Version: 1.13 diff --git a/javaee.specs.support/src/org/netbeans/modules/javaee/specs/support/DefaultJmsSupportImpl.java b/javaee.specs.support/src/org/netbeans/modules/javaee/specs/support/DefaultJmsSupportImpl.java new file mode 100644 --- /dev/null +++ b/javaee.specs.support/src/org/netbeans/modules/javaee/specs/support/DefaultJmsSupportImpl.java @@ -0,0 +1,70 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, 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-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2013 Sun Microsystems, Inc. + */ +package org.netbeans.modules.javaee.specs.support; + +import org.netbeans.modules.javaee.specs.support.spi.JmsSupportImplementation; + +/** + * Default {@link JmsSupportImplementation} implementation. + * Used in cases when the server doesn't provide its own implementation. + * + * @author Martin Fousek + */ +public class DefaultJmsSupportImpl implements JmsSupportImplementation { + + @Override + public MessageDrivenMapping getMessageDrivenMapping() { + return new MessageDrivenMapping() { + + @Override + public boolean useMappedName() { + return true; + } + + @Override + public String activationConfigProperty() { + return null; + } + }; + } + +} diff --git a/javaee.specs.support/src/org/netbeans/modules/javaee/specs/support/api/JmsSupport.java b/javaee.specs.support/src/org/netbeans/modules/javaee/specs/support/api/JmsSupport.java new file mode 100644 --- /dev/null +++ b/javaee.specs.support/src/org/netbeans/modules/javaee/specs/support/api/JmsSupport.java @@ -0,0 +1,91 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, 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-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2013 Sun Microsystems, Inc. + */ +package org.netbeans.modules.javaee.specs.support.api; + +import org.netbeans.api.annotations.common.NonNull; +import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; +import org.netbeans.modules.javaee.specs.support.DefaultJmsSupportImpl; +import org.netbeans.modules.javaee.specs.support.spi.JmsSupportImplementation; +import org.netbeans.modules.javaee.specs.support.spi.JmsSupportImplementation.MessageDrivenMapping; + +/** + * + * @author Martin Fousek + * @since 1.13 + */ +public final class JmsSupport { + + private static final JmsSupport DEFAULT = new JmsSupport(new DefaultJmsSupportImpl()); + private final JmsSupportImplementation impl; + + private JmsSupport(JmsSupportImplementation impl) { + this.impl = impl; + } + + /** + * Returns instance for given j2eePlatform. + * @param j2eePlatform platform, can be null for default support retrieval + * @return platform specific instance, if no such exist default one is provided + */ + @NonNull + public static JmsSupport getInstance(J2eePlatform j2eePlatform) { + if (j2eePlatform == null) { + return DEFAULT; + } + + JmsSupportImplementation supportImpl = j2eePlatform.getLookup().lookup(JmsSupportImplementation.class); + if (supportImpl != null) { + return new JmsSupport(supportImpl); + } + return DEFAULT; + } + + /** + * Gets mapping information for @MessageDriven bean. + * + * @return server specific mapping + */ + public MessageDrivenMapping getMessageDrivenMapping() { + return impl.getMessageDrivenMapping(); + } + +} diff --git a/javaee.specs.support/src/org/netbeans/modules/javaee/specs/support/spi/JmsSupportImplementation.java b/javaee.specs.support/src/org/netbeans/modules/javaee/specs/support/spi/JmsSupportImplementation.java new file mode 100644 --- /dev/null +++ b/javaee.specs.support/src/org/netbeans/modules/javaee/specs/support/spi/JmsSupportImplementation.java @@ -0,0 +1,92 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, 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-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2013 Sun Microsystems, Inc. + */ +package org.netbeans.modules.javaee.specs.support.spi; + +import org.netbeans.api.annotations.common.CheckForNull; +import org.netbeans.api.annotations.common.NonNull; + +/** + * Defines server specific JMS support. + * + * @author Martin Fousek + * @since 1.13 + */ +public interface JmsSupportImplementation { + + /** + * Gets mapping information for @MessageDriven bean. + * + * @return server specific mapping + */ + @NonNull + MessageDrivenMapping getMessageDrivenMapping(); + + + /** + * Holds information about mapping MessageDriven bean to the destination location in case of lower than JavaEE7 + * target platform. For JavaEE7 project is generated "destinationLookup" activation config property by default + * since it's compatible and portable way defined by the specification. + */ + public interface MessageDrivenMapping { + + /** + * Whether can be used 'mappedName' attribute of the @MessageDriven annotation to specify the destination. + * In another words, whether server supports mappedName attribute. + * + * @return {@code true} if the mappedName can be used and generated, {@code false} otherwise + */ + boolean useMappedName(); + + /** + * Activation config property to generate into the 'activationConfig' attribute of the @MessageDriven + * annotation. Can be {@code null} in case that no @ActivationConfigProperty is supported. + *

+ * This property will be used for projects targeting JavaEE6 or lower EE platform. + * + * @return property name if any, {@code null} otherwise + */ + @CheckForNull + String activationConfigProperty(); + + } + +}