Added
Link Here
|
1 |
package org.eclipse.jst.jee.internal.ejb.workbench.validation; |
2 |
|
3 |
import java.text.MessageFormat; |
4 |
|
5 |
import org.eclipse.core.resources.IMarker; |
6 |
import org.eclipse.core.resources.IProject; |
7 |
import org.eclipse.core.resources.IResource; |
8 |
import org.eclipse.core.runtime.IProgressMonitor; |
9 |
import org.eclipse.jst.j2ee.model.ModelProviderManager; |
10 |
import org.eclipse.jst.j2ee.project.JavaEEProjectUtilities; |
11 |
import org.eclipse.jst.javaee.ejb.EJBJar; |
12 |
import org.eclipse.jst.javaee.ejb.EnterpriseBeans; |
13 |
import org.eclipse.jst.jee.model.internal.Messages; |
14 |
import org.eclipse.wst.validation.AbstractValidator; |
15 |
import org.eclipse.wst.validation.ValidationEvent; |
16 |
import org.eclipse.wst.validation.ValidationResult; |
17 |
import org.eclipse.wst.validation.ValidationState; |
18 |
import org.eclipse.wst.validation.ValidatorMessage; |
19 |
|
20 |
public class UIEJB3Validator extends AbstractValidator { |
21 |
|
22 |
public static String MARKER_ID_NO_BEANS = "org.eclipse.jst.jee.ejb3.nobeans"; //$NON-NLS-1$ |
23 |
|
24 |
@Override |
25 |
public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) { |
26 |
if ((resource == null) || !IProject.class.isInstance(resource)) |
27 |
return null; |
28 |
IProject proj = (IProject)resource; |
29 |
if (!JavaEEProjectUtilities.isEJBProject(proj)) |
30 |
return null; |
31 |
EJBJar ejbJar = (EJBJar)ModelProviderManager.getModelProvider(proj).getModelObject(); |
32 |
EnterpriseBeans ebs = ejbJar.getEnterpriseBeans(); |
33 |
if (ebs.getSessionBeans().size() + ebs.getMessageDrivenBeans().size() == 0) { |
34 |
ValidationResult vRes = new ValidationResult(); |
35 |
ValidatorMessage vMsg = createValidatorMessage(Messages.getString(Messages.UIEJB3Validator_NoBeansErrorMessage), proj, IMarker.SEVERITY_ERROR, IMarker.PRIORITY_HIGH); |
36 |
vRes.add(vMsg); |
37 |
return vRes; |
38 |
} |
39 |
return null; |
40 |
} |
41 |
|
42 |
@Override |
43 |
public ValidationResult validate(ValidationEvent event, ValidationState state, IProgressMonitor monitor){ |
44 |
IResource res = event.getResource(); |
45 |
return validate(res, 0, state, monitor); |
46 |
} |
47 |
|
48 |
static private ValidatorMessage createValidatorMessage(String txt, |
49 |
IResource res, |
50 |
int severity, |
51 |
int priority) { |
52 |
ValidatorMessage msg = ValidatorMessage.create(txt, res); |
53 |
msg.setAttribute(IMarker.SEVERITY, severity); |
54 |
msg.setAttribute(IMarker.PRIORITY, priority); |
55 |
msg.setAttribute(IMarker.MARKER, IMarker.BOOKMARK); |
56 |
msg.setAttribute(IMarker.LOCATION, MessageFormat.format(Messages.getString(Messages.UIEJB3Validator_NoBeansErrorLocation), |
57 |
new Object[] {res.getName()})); |
58 |
msg.setType(MARKER_ID_NO_BEANS); |
59 |
return msg; |
60 |
} |
61 |
|
62 |
} |