Added
Link Here
|
1 |
package org.eclipse.jst.jee.ejb.validation.internal; |
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.resources.IResourceDelta; |
9 |
import org.eclipse.core.runtime.CoreException; |
10 |
import org.eclipse.core.runtime.IProgressMonitor; |
11 |
import org.eclipse.core.runtime.NullProgressMonitor; |
12 |
import org.eclipse.jst.j2ee.model.ModelProviderManager; |
13 |
import org.eclipse.jst.j2ee.project.JavaEEProjectUtilities; |
14 |
import org.eclipse.jst.javaee.ejb.EJBJar; |
15 |
import org.eclipse.jst.javaee.ejb.EnterpriseBeans; |
16 |
import org.eclipse.jst.jee.ejb.Activator; |
17 |
import org.eclipse.wst.validation.AbstractValidator; |
18 |
import org.eclipse.wst.validation.ValidationEvent; |
19 |
import org.eclipse.wst.validation.ValidationResult; |
20 |
import org.eclipse.wst.validation.ValidationState; |
21 |
import org.eclipse.wst.validation.Validator; |
22 |
import org.eclipse.wst.validation.ValidatorMessage; |
23 |
import org.eclipse.wst.validation.internal.MarkerManager; |
24 |
import org.eclipse.wst.validation.internal.ValManager; |
25 |
import org.eclipse.wst.validation.internal.ValOperation; |
26 |
|
27 |
@SuppressWarnings("restriction") |
28 |
public class UIEJB3Validator extends AbstractValidator { |
29 |
|
30 |
public static String ID = "org.eclipse.jst.jee.ejb3.validator"; //$NON-NLS-1$ |
31 |
public static String MARKER_ID_NO_BEANS = "org.eclipse.jst.jee.ejb3.nobeans"; //$NON-NLS-1$ |
32 |
|
33 |
@Override |
34 |
public void validationStarting(IProject project, ValidationState state, IProgressMonitor monitor){ |
35 |
Validator v = ValManager.getDefault().getValidator(UIEJB3Validator.ID, project); |
36 |
if (project != null) |
37 |
ValManager.getDefault().validate(v, new ValOperation(), project, IResourceDelta.NO_CHANGE, new NullProgressMonitor(), null); |
38 |
} |
39 |
|
40 |
@Override |
41 |
public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) { |
42 |
if ((resource == null) || !IProject.class.isInstance(resource)) |
43 |
return null; |
44 |
IProject proj = (IProject)resource; |
45 |
try { |
46 |
MarkerManager.getDefault().clearMarker(proj, getParent()); |
47 |
} catch (CoreException e) { |
48 |
Activator.logError(e); |
49 |
} |
50 |
if (!JavaEEProjectUtilities.isEJBProject(proj)) |
51 |
return null; |
52 |
EJBJar ejbJar = (EJBJar)ModelProviderManager.getModelProvider(proj).getModelObject(); |
53 |
EnterpriseBeans ebs = ejbJar.getEnterpriseBeans(); |
54 |
if (ebs.getSessionBeans().size() + ebs.getMessageDrivenBeans().size() == 0) { |
55 |
ValidationResult vRes = new ValidationResult(); |
56 |
ValidatorMessage vMsg = createValidatorMessage(Messages.NO_BEANS_ERROR, proj, IMarker.SEVERITY_ERROR, IMarker.PRIORITY_HIGH); |
57 |
vRes.add(vMsg); |
58 |
return vRes; |
59 |
} |
60 |
return null; |
61 |
} |
62 |
|
63 |
@Override |
64 |
public ValidationResult validate(ValidationEvent event, ValidationState state, IProgressMonitor monitor){ |
65 |
IResource res = event.getResource(); |
66 |
return validate(res, 0, state, monitor); |
67 |
} |
68 |
|
69 |
private static ValidatorMessage createValidatorMessage(String txt, |
70 |
IResource res, |
71 |
int severity, |
72 |
int priority) { |
73 |
ValidatorMessage msg = ValidatorMessage.create(txt, res); |
74 |
msg.setAttribute(IMarker.SEVERITY, severity); |
75 |
msg.setAttribute(IMarker.PRIORITY, priority); |
76 |
msg.setAttribute(IMarker.LOCATION, MessageFormat.format(Messages.NO_BEANS_ERROR_LOCATION, new Object[] { res.getName() })); |
77 |
msg.setType(MARKER_ID_NO_BEANS); |
78 |
return msg; |
79 |
} |
80 |
|
81 |
} |