Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jakarta EE Entitiy and EJB support #6129

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions enterprise/j2ee.ejbcore/licenseinfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
<file>src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB30StatefulEjbClass.template</file>
<file>src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB30StatelessEjbClass.template</file>
<file>src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB31SingletonEjbClass.template</file>
<file>src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB40StatelessEjbClass.template</file>
<file>src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB40StatefulEjbClass.template</file>
<file>src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB40SessionLocal.template</file>
<file>src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB40SessionRemote.template</file>
<file>src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB40MessageDrivenBean.template</file>
<file>src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB40SingletonEjbClass.template</file>
<file>src/org/netbeans/modules/j2ee/ejbcore/resources/CachingServiceLocator.template</file>
<file>src/org/netbeans/modules/j2ee/ejbcore/resources/ServiceLocator.template</file>
<license ref="Apache-2.0-ASF" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Signature file v4.1
#Version 1.71
#Version 1.72

CLSS public abstract java.awt.Component
cons protected init()
Expand Down Expand Up @@ -656,7 +656,7 @@ supr java.lang.Object
hfds key,value

CLSS public final org.netbeans.modules.j2ee.ejbcore.api.codegeneration.SessionGenerator
cons protected init(java.lang.String,org.openide.filesystems.FileObject,boolean,boolean,java.lang.String,boolean,boolean,boolean,org.netbeans.modules.j2ee.ejbcore.ejb.wizard.session.TimerOptions,boolean,boolean,boolean)
cons protected init(java.lang.String,org.openide.filesystems.FileObject,boolean,boolean,java.lang.String,org.netbeans.api.j2ee.core.Profile,boolean,boolean,org.netbeans.modules.j2ee.ejbcore.ejb.wizard.session.TimerOptions,boolean,boolean,boolean)
fld public final static java.lang.String ANNOTATION_LOCAL_BEAN = "javax.ejb.LocalBean"
fld public final static java.lang.String EJB21_EJBCLASS = "Templates/J2EE/EJB21/SessionEjbClass.java"
fld public final static java.lang.String EJB21_LOCAL = "Templates/J2EE/EJB21/SessionLocal.java"
Expand All @@ -668,15 +668,20 @@ fld public final static java.lang.String EJB30_REMOTE = "Templates/J2EE/EJB30/Se
fld public final static java.lang.String EJB30_STATEFUL_EJBCLASS = "Templates/J2EE/EJB30/StatefulEjbClass.java"
fld public final static java.lang.String EJB30_STATELESS_EJBCLASS = "Templates/J2EE/EJB30/StatelessEjbClass.java"
fld public final static java.lang.String EJB31_SINGLETON_EJBCLASS = "Templates/J2EE/EJB31/SingletonEjbClass.java"
fld public final static java.lang.String EJB40_LOCAL = "Templates/J2EE/EJB40/SessionLocal.java"
fld public final static java.lang.String EJB40_REMOTE = "Templates/J2EE/EJB40/SessionRemote.java"
fld public final static java.lang.String EJB40_SINGLETON_EJBCLASS = "Templates/J2EE/EJB40/SingletonEjbClass.java"
fld public final static java.lang.String EJB40_STATEFUL_EJBCLASS = "Templates/J2EE/EJB40/StatefulEjbClass.java"
fld public final static java.lang.String EJB40_STATELESS_EJBCLASS = "Templates/J2EE/EJB40/StatelessEjbClass.java"
fld public final static java.lang.String TEMPLATE_PROPERTY_INTERFACES = "interfaces"
fld public final static java.lang.String TEMPLATE_PROPERTY_LOCAL_BEAN = "annotationLocalBean"
meth public org.openide.filesystems.FileObject generate() throws java.io.IOException
meth public static java.lang.String getScheduleAnnotationValue(org.netbeans.modules.j2ee.ejbcore.ejb.wizard.session.TimerOptions,boolean)
meth public static org.netbeans.modules.j2ee.ejbcore.api.codegeneration.SessionGenerator create(java.lang.String,org.openide.filesystems.FileObject,boolean,boolean,java.lang.String,boolean,boolean,boolean,org.netbeans.modules.j2ee.ejbcore.ejb.wizard.session.TimerOptions,boolean,boolean)
meth public static org.netbeans.modules.j2ee.ejbcore.api.codegeneration.SessionGenerator create(java.lang.String,org.openide.filesystems.FileObject,boolean,boolean,java.lang.String,org.netbeans.api.j2ee.core.Profile,boolean,boolean,org.netbeans.modules.j2ee.ejbcore.ejb.wizard.session.TimerOptions,boolean,boolean)
meth public static org.openide.filesystems.FileObject createRemoteInterfacePackage(org.netbeans.api.project.Project,java.lang.String,org.openide.filesystems.FileObject) throws java.io.IOException
meth public void initRemoteInterfacePackage(org.netbeans.api.project.Project,java.lang.String,org.openide.filesystems.FileObject) throws java.io.IOException
supr java.lang.Object
hfds displayName,ejbClassName,ejbName,ejbNameOptions,hasLocal,hasRemote,isSimplified,isXmlBased,localHomeName,localName,packageName,packageNameWithDot,pkg,remoteHomeName,remoteName,remotePkg,sessionType,templateParameters
hfds displayName,ejbClassName,ejbName,ejbNameOptions,enterpriseProfile,hasLocal,hasRemote,isXmlBased,localHomeName,localName,packageName,packageNameWithDot,pkg,remoteHomeName,remoteName,remotePkg,sessionType,templateParameters

CLSS public abstract org.netbeans.modules.j2ee.ejbcore.api.methodcontroller.AbstractMethodController
cons public init(java.lang.String,org.netbeans.modules.j2ee.metadata.model.api.MetadataModel<org.netbeans.modules.j2ee.dd.api.ejb.EjbJarMetadata>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@
import org.netbeans.modules.j2ee.core.api.support.java.GenerationUtils;
import org.netbeans.modules.j2ee.ejbcore.EjbGenerationUtil;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.lang.model.element.Modifier;
import org.netbeans.api.j2ee.core.Profile;
import org.netbeans.api.java.classpath.ClassPath;
import org.netbeans.api.java.classpath.JavaClassPathConstants;
import org.netbeans.api.java.project.JavaProjectConstants;
Expand All @@ -42,18 +40,12 @@
import org.netbeans.api.project.libraries.Library;
import org.netbeans.api.project.libraries.LibraryManager;
import org.netbeans.modules.j2ee.common.J2eeProjectCapabilities;
import org.netbeans.modules.j2ee.core.api.support.java.method.MethodModel;
import org.netbeans.modules.j2ee.dd.api.ejb.AssemblyDescriptor;
import org.netbeans.modules.j2ee.dd.api.ejb.ContainerTransaction;
import org.netbeans.modules.j2ee.ejbcore.action.BusinessMethodGenerator;
import org.netbeans.modules.j2ee.ejbcore.ejb.wizard.session.TimerOptions;
import org.netbeans.modules.j2ee.ejbcore.naming.EJBNameOptions;
import org.openide.cookies.EditorCookie;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.loaders.DataObject;
import org.openide.loaders.DataObjectNotFoundException;
import org.openide.util.RequestProcessor;

/**
* Generator of Session EJBs for EJB 2.1 and 3.0
Expand All @@ -73,6 +65,12 @@ public final class SessionGenerator {
public static final String EJB30_LOCAL = "Templates/J2EE/EJB30/SessionLocal.java"; // NOI18N
public static final String EJB30_REMOTE = "Templates/J2EE/EJB30/SessionRemote.java"; // NOI18N

public static final String EJB40_STATELESS_EJBCLASS = "Templates/J2EE/EJB40/StatelessEjbClass.java"; // NOI18N
public static final String EJB40_STATEFUL_EJBCLASS = "Templates/J2EE/EJB40/StatefulEjbClass.java"; // NOI18N
public static final String EJB40_LOCAL = "Templates/J2EE/EJB40/SessionLocal.java"; // NOI18N
public static final String EJB40_REMOTE = "Templates/J2EE/EJB40/SessionRemote.java"; // NOI18N
public static final String EJB40_SINGLETON_EJBCLASS = "Templates/J2EE/EJB40/SingletonEjbClass.java"; // NOI18N

public static final String EJB31_SINGLETON_EJBCLASS = "Templates/J2EE/EJB31/SingletonEjbClass.java"; // NOI18N

public static final String ANNOTATION_LOCAL_BEAN = "javax.ejb.LocalBean";
Expand All @@ -86,7 +84,7 @@ public final class SessionGenerator {
private final boolean hasRemote;
private final boolean hasLocal;
private final String sessionType;
private final boolean isSimplified;
private final Profile enterpriseProfile;
// private final boolean hasBusinessInterface;
private final boolean isXmlBased;

Expand All @@ -106,21 +104,21 @@ public final class SessionGenerator {
private final Map<String, Object> templateParameters;

public static SessionGenerator create(String wizardTargetName, FileObject pkg, boolean hasRemote, boolean hasLocal,
String sessionType, boolean isSimplified, boolean hasBusinessInterface, boolean isXmlBased,
String sessionType, Profile enterpriseProfile, boolean hasBusinessInterface, boolean isXmlBased,
TimerOptions timerOptions, boolean exposeTimer, boolean nonPersistentTimer) {
return new SessionGenerator(wizardTargetName, pkg, hasRemote, hasLocal, sessionType, isSimplified,
return new SessionGenerator(wizardTargetName, pkg, hasRemote, hasLocal, sessionType, enterpriseProfile,
hasBusinessInterface, isXmlBased, timerOptions, exposeTimer, nonPersistentTimer, false);
}

protected SessionGenerator(String wizardTargetName, FileObject pkg, boolean hasRemote, boolean hasLocal,
String sessionType, boolean isSimplified, boolean hasBusinessInterface, boolean isXmlBased,
String sessionType, Profile enterpriseProfile, boolean hasBusinessInterface, boolean isXmlBased,
TimerOptions timerOptions, boolean exposeTimer, boolean nonPersistentTimer, boolean isTest) {
this.pkg = pkg;
this.remotePkg = pkg;
this.hasRemote = hasRemote;
this.hasLocal = hasLocal;
this.sessionType = sessionType;
this.isSimplified = isSimplified;
this.enterpriseProfile = enterpriseProfile;
// this.hasBusinessInterface = hasBusinessInterface;
this.isXmlBased = isXmlBased;
this.ejbNameOptions = new EJBNameOptions();
Expand Down Expand Up @@ -187,7 +185,17 @@ public static FileObject createRemoteInterfacePackage(Project projectForRemoteIn

public FileObject generate() throws IOException {
FileObject resultFileObject = null;
if (isSimplified) {
if (enterpriseProfile.isAtLeast(Profile.JAKARTA_EE_9_WEB)) {
resultFileObject = generateEJB40Classes();

//put these lines in a common function at the appropriate place after EA1
//something like public EjbJar getEjbJar()
//This method will be used whereever we construct/get DD object graph to ensure
//corresponding config listners attached to it.
Project project = FileOwnerQuery.getOwner(pkg);
J2eeModuleProvider j2eeModuleProvider = project.getLookup().lookup(J2eeModuleProvider.class);
j2eeModuleProvider.getConfigSupport().ensureConfigurationReady();
} else if (enterpriseProfile.isAtLeast(Profile.JAVA_EE_5)) {
resultFileObject = generateEJB30Classes();

//put these lines in a common function at the appropriate place after EA1
Expand Down Expand Up @@ -269,6 +277,39 @@ private FileObject generateEJB30Classes() throws IOException {
return ejbClassFO;
}

private FileObject generateEJB40Classes() throws IOException {
String ejbClassTemplateName = "";
if (sessionType.equals(Session.SESSION_TYPE_STATELESS)){
ejbClassTemplateName = EJB40_STATELESS_EJBCLASS;
} else if (sessionType.equals(Session.SESSION_TYPE_STATEFUL)){
ejbClassTemplateName = EJB40_STATEFUL_EJBCLASS;
} else if (sessionType.equals(Session.SESSION_TYPE_SINGLETON)){
ejbClassTemplateName = EJB40_SINGLETON_EJBCLASS;
} else{
assert false;
}

if (hasLocal && hasRemote){
this.templateParameters.put(TEMPLATE_PROPERTY_INTERFACES, remoteName + ", " + localName); //NOI18N
} else if (hasLocal){
this.templateParameters.put(TEMPLATE_PROPERTY_INTERFACES, localName);
} else if (hasRemote){
this.templateParameters.put(TEMPLATE_PROPERTY_INTERFACES, remoteName);
} else {
this.templateParameters.put(TEMPLATE_PROPERTY_LOCAL_BEAN, Boolean.TRUE.toString());
}

final FileObject ejbClassFO = GenerationUtils.createClass(ejbClassTemplateName, pkg, ejbClassName, null, templateParameters);
if (hasRemote) {
GenerationUtils.createClass(EJB40_REMOTE, remotePkg, remoteName, null, templateParameters);
}
if (hasLocal) {
GenerationUtils.createClass(EJB40_LOCAL, pkg, localName, null, templateParameters);
}

return ejbClassFO;
}

private void generateEJB21Xml() throws IOException {
org.netbeans.modules.j2ee.api.ejbjar.EjbJar ejbModule = org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJar(pkg);
FileObject ddFO = ejbModule.getDeploymentDescriptor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,7 @@ public boolean isValid() {
}

WebModule wm = WebModule.getWebModule(project.getProjectDirectory());
if (wm != null && (wm.getJ2eeProfile() == Profile.JAVA_EE_6_FULL || wm.getJ2eeProfile() == Profile.JAVA_EE_6_WEB
|| wm.getJ2eeProfile() == Profile.JAVA_EE_7_FULL || wm.getJ2eeProfile() == Profile.JAVA_EE_7_WEB
|| wm.getJ2eeProfile() == Profile.JAVA_EE_8_FULL || wm.getJ2eeProfile() == Profile.JAVA_EE_8_WEB
|| wm.getJ2eeProfile() == Profile.JAKARTA_EE_8_FULL || wm.getJ2eeProfile() == Profile.JAKARTA_EE_8_WEB
|| wm.getJ2eeProfile() == Profile.JAKARTA_EE_9_WEB || wm.getJ2eeProfile() == Profile.JAKARTA_EE_9_FULL
|| wm.getJ2eeProfile() == Profile.JAKARTA_EE_9_1_WEB || wm.getJ2eeProfile() == Profile.JAKARTA_EE_9_1_FULL
|| wm.getJ2eeProfile() == Profile.JAKARTA_EE_10_WEB || wm.getJ2eeProfile() == Profile.JAKARTA_EE_10_FULL)) {
if (wm != null && (wm.getJ2eeProfile().isAtLeast(Profile.JAVA_EE_6_WEB))) {
// check that server is EJB lite sufficient
EjbSupport ejbSupport = EjbSupport.getInstance(j2eePlatform);
if (!ejbSupport.isEjb31LiteSupported(j2eePlatform)) {
Expand Down Expand Up @@ -93,8 +87,12 @@ public boolean isValid() {
*/
private static boolean isSessionBeanCodeGenerationAlowed(Project project) {
ClassPath classpath = ClassPath.getClassPath(project.getProjectDirectory(), ClassPath.COMPILE);
return !(classpath.findResource("javax/ejb/Stateless.class") == null //NOI18N
return !(classpath.findResource("jakarta/ejb/Stateless.class") == null //NOI18N
|| classpath.findResource("jakarta/ejb/Stateful.class") == null //NOI18N
|| classpath.findResource("jakarta/ejb/Singleton.class") == null //NOI18N
|| //NOI18N
!(classpath.findResource("javax/ejb/Stateless.class") == null //NOI18N
|| classpath.findResource("javax/ejb/Stateful.class") == null //NOI18N
|| classpath.findResource("javax/ejb/Singleton.class") == null); //NOI18N
|| classpath.findResource("javax/ejb/Singleton.class") == null)); //NOI18N
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,14 @@ public Set instantiate () {
EjbJar ejbModule = EjbJar.getEjbJar(pkg);
// TODO: UI - add checkbox for Java EE 5 to create also EJB 2.1 style EJBs
Profile profile = ejbModule.getJ2eeProfile();
boolean isSimplified = Profile.JAVA_EE_5.equals(profile) || Profile.JAVA_EE_6_FULL.equals(profile) || Profile.JAVA_EE_6_WEB.equals(profile)
|| Profile.JAVA_EE_7_FULL.equals(profile) || Profile.JAVA_EE_7_WEB.equals(profile)
|| Profile.JAVA_EE_8_FULL.equals(profile) || Profile.JAVA_EE_8_WEB.equals(profile)
|| Profile.JAKARTA_EE_8_FULL.equals(profile) || Profile.JAKARTA_EE_8_WEB.equals(profile)
|| Profile.JAKARTA_EE_9_FULL.equals(profile) || Profile.JAKARTA_EE_9_WEB.equals(profile)
|| Profile.JAKARTA_EE_9_1_FULL.equals(profile) || Profile.JAKARTA_EE_9_1_WEB.equals(profile)
|| Profile.JAKARTA_EE_10_FULL.equals(profile) || Profile.JAKARTA_EE_10_WEB.equals(profile);
boolean isSimplified = profile.isAtLeast(Profile.JAVA_EE_5);
SessionGenerator sessionGenerator = SessionGenerator.create(
Templates.getTargetName(wiz),
pkg,
ejbPanel.hasRemote(),
ejbPanel.hasLocal(),
ejbPanel.getSessionType(),
isSimplified,
profile,
true, // TODO: UI - add checkbox for creation of business interface
!isSimplified, // TODO: UI - add checkbox for option XML (not annotation) usage
ejbPanel.getTimerOptions(),
Expand Down
Loading