[119311] Create Default Session Bean option
diff --git a/plugins/org.eclipse.jst.jee.ejb/META-INF/MANIFEST.MF b/plugins/org.eclipse.jst.jee.ejb/META-INF/MANIFEST.MF
index cde7e40..eb5bf4b 100644
--- a/plugins/org.eclipse.jst.jee.ejb/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.jst.jee.ejb/META-INF/MANIFEST.MF
@@ -22,7 +22,8 @@
org.eclipse.emf.ecore.xmi;bundle-version="[2.2.0,3.0.0)",
org.eclipse.jst.j2ee.ejb;bundle-version="[1.1.0,1.2.0)",
org.eclipse.wst.common.emf;bundle-version="[1.1.0,2.0.0)",
- org.eclipse.wst.common.emfworkbench.integration;bundle-version="[1.1.0,2.0.0)"
+ org.eclipse.wst.common.emfworkbench.integration;bundle-version="[1.1.0,2.0.0)",
+ org.eclipse.wst.validation;bundle-version="[1.2.0,2.0.0)"
Eclipse-LazyStart: true
Bundle-Localization: plugin
Bundle-Vendor: %Bundle-Vendor.0
diff --git a/plugins/org.eclipse.jst.jee.ejb/ejb/org/eclipse/jst/jee/ejb/validation/internal/Messages.java b/plugins/org.eclipse.jst.jee.ejb/ejb/org/eclipse/jst/jee/ejb/validation/internal/Messages.java
new file mode 100644
index 0000000..6e41d72
--- /dev/null
+++ b/plugins/org.eclipse.jst.jee.ejb/ejb/org/eclipse/jst/jee/ejb/validation/internal/Messages.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.jee.ejb.validation.internal;
+
+import org.eclipse.osgi.util.NLS;
+
+
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.jst.jee.ejb.validation.internal.messages"; //$NON-NLS-1$
+
+
+ private Messages() {
+ // Do not instantiate
+ }
+
+ public static String NO_BEANS_ERROR;
+ public static String NO_BEANS_ERROR_LOCATION;
+
+ static {
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+}
diff --git a/plugins/org.eclipse.jst.jee.ejb/ejb/org/eclipse/jst/jee/ejb/validation/internal/UIEJB3Validator.java b/plugins/org.eclipse.jst.jee.ejb/ejb/org/eclipse/jst/jee/ejb/validation/internal/UIEJB3Validator.java
new file mode 100644
index 0000000..a145ae6
--- /dev/null
+++ b/plugins/org.eclipse.jst.jee.ejb/ejb/org/eclipse/jst/jee/ejb/validation/internal/UIEJB3Validator.java
@@ -0,0 +1,81 @@
+package org.eclipse.jst.jee.ejb.validation.internal;
+
+import java.text.MessageFormat;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jst.j2ee.model.ModelProviderManager;
+import org.eclipse.jst.j2ee.project.JavaEEProjectUtilities;
+import org.eclipse.jst.javaee.ejb.EJBJar;
+import org.eclipse.jst.javaee.ejb.EnterpriseBeans;
+import org.eclipse.jst.jee.ejb.Activator;
+import org.eclipse.wst.validation.AbstractValidator;
+import org.eclipse.wst.validation.ValidationEvent;
+import org.eclipse.wst.validation.ValidationResult;
+import org.eclipse.wst.validation.ValidationState;
+import org.eclipse.wst.validation.Validator;
+import org.eclipse.wst.validation.ValidatorMessage;
+import org.eclipse.wst.validation.internal.MarkerManager;
+import org.eclipse.wst.validation.internal.ValManager;
+import org.eclipse.wst.validation.internal.ValOperation;
+
+@SuppressWarnings("restriction")
+public class UIEJB3Validator extends AbstractValidator {
+
+ public static String ID = "org.eclipse.jst.jee.ejb3.validator"; //$NON-NLS-1$
+ public static String MARKER_ID_NO_BEANS = "org.eclipse.jst.jee.ejb3.nobeans"; //$NON-NLS-1$
+
+ @Override
+ public void validationStarting(IProject project, ValidationState state, IProgressMonitor monitor){
+ Validator v = ValManager.getDefault().getValidator(UIEJB3Validator.ID, project);
+ if (project != null)
+ ValManager.getDefault().validate(v, new ValOperation(), project, IResourceDelta.NO_CHANGE, new NullProgressMonitor(), null);
+ }
+
+ @Override
+ public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
+ if ((resource == null) || !IProject.class.isInstance(resource))
+ return null;
+ IProject proj = (IProject)resource;
+ try {
+ MarkerManager.getDefault().clearMarker(proj, getParent());
+ } catch (CoreException e) {
+ Activator.logError(e);
+ }
+ if (!JavaEEProjectUtilities.isEJBProject(proj))
+ return null;
+ EJBJar ejbJar = (EJBJar)ModelProviderManager.getModelProvider(proj).getModelObject();
+ EnterpriseBeans ebs = ejbJar.getEnterpriseBeans();
+ if (ebs.getSessionBeans().size() + ebs.getMessageDrivenBeans().size() == 0) {
+ ValidationResult vRes = new ValidationResult();
+ ValidatorMessage vMsg = createValidatorMessage(Messages.NO_BEANS_ERROR, proj, IMarker.SEVERITY_ERROR, IMarker.PRIORITY_HIGH);
+ vRes.add(vMsg);
+ return vRes;
+ }
+ return null;
+ }
+
+ @Override
+ public ValidationResult validate(ValidationEvent event, ValidationState state, IProgressMonitor monitor){
+ IResource res = event.getResource();
+ return validate(res, 0, state, monitor);
+ }
+
+ private static ValidatorMessage createValidatorMessage(String txt,
+ IResource res,
+ int severity,
+ int priority) {
+ ValidatorMessage msg = ValidatorMessage.create(txt, res);
+ msg.setAttribute(IMarker.SEVERITY, severity);
+ msg.setAttribute(IMarker.PRIORITY, priority);
+ msg.setAttribute(IMarker.LOCATION, MessageFormat.format(Messages.NO_BEANS_ERROR_LOCATION, new Object[] { res.getName() }));
+ msg.setType(MARKER_ID_NO_BEANS);
+ return msg;
+ }
+
+}
diff --git a/plugins/org.eclipse.jst.jee.ejb/ejb/org/eclipse/jst/jee/ejb/validation/internal/messages.properties b/plugins/org.eclipse.jst.jee.ejb/ejb/org/eclipse/jst/jee/ejb/validation/internal/messages.properties
new file mode 100644
index 0000000..8cc1f5d
--- /dev/null
+++ b/plugins/org.eclipse.jst.jee.ejb/ejb/org/eclipse/jst/jee/ejb/validation/internal/messages.properties
@@ -0,0 +1,2 @@
+NO_BEANS_ERROR=An EJB module must contain one or more enterprise beans.
+NO_BEANS_ERROR_LOCATION={0} project
diff --git a/plugins/org.eclipse.jst.jee.ejb/plugin.properties b/plugins/org.eclipse.jst.jee.ejb/plugin.properties
index cfcd596..9b1a896 100644
--- a/plugins/org.eclipse.jst.jee.ejb/plugin.properties
+++ b/plugins/org.eclipse.jst.jee.ejb/plugin.properties
@@ -10,4 +10,7 @@
###############################################################################
# properties file for org.eclipse.jst.jee.ejb
Bundle-Name.0 = JEE Ejb Plug-in
-Bundle-Vendor.0 = Eclipse.org
\ No newline at end of file
+Bundle-Vendor.0 = Eclipse.org
+org.eclipse.jst.jee.ejb3.nobeans.marker.type = EJB Problem
+org.eclipse.jst.jee.ejb3.validator.name = EJB 3.x Validator
+org.eclipse.jst.jee.ejb3.nobeansmessage.label = No enterprise bean in the EJB project
\ No newline at end of file
diff --git a/plugins/org.eclipse.jst.jee.ejb/plugin.xml b/plugins/org.eclipse.jst.jee.ejb/plugin.xml
index 9b9a806..5a71d0f 100644
--- a/plugins/org.eclipse.jst.jee.ejb/plugin.xml
+++ b/plugins/org.eclipse.jst.jee.ejb/plugin.xml
@@ -13,5 +13,38 @@
<facet id="jst.ejb" versions="3.0,3.1"/>
</provider>
- </extension>
+ </extension>
+ <extension
+ id="org.eclipse.jst.jee.ejb3.validator"
+ name="%org.eclipse.jst.jee.ejb3.validator.name"
+ point="org.eclipse.wst.validation.validatorV2">
+ <validator
+ build="true"
+ class="org.eclipse.jst.jee.ejb.validation.internal.UIEJB3Validator"
+ manual="true"
+ markerId="org.eclipse.jst.jee.ejb3.nobeans">
+ <include>
+ <rules>
+ <facet
+ id="jst.ejb"
+ version="3.0,3.1">
+ </facet>
+ </rules>
+ </include>
+ <messageCategory
+ id="org.eclipse.jst.jee.ejb3.nobeansmessage"
+ label="%org.eclipse.jst.jee.ejb3.nobeansmessage.label"
+ severity="error">
+ </messageCategory>
+ </validator>
+ </extension>
+ <extension
+ id="org.eclipse.jst.jee.ejb3.nobeans"
+ name="%org.eclipse.jst.jee.ejb3.nobeans.marker.type"
+ point="org.eclipse.core.resources.markers">
+ <super
+ type="org.eclipse.wst.validation.problemmarker">
+ </super>
+ </extension>
+
</plugin>