KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > spoon > aval > annotations > jwsValImpl > ValidWebServiceBeanValidator


1 package spoon.aval.annotations.jwsValImpl;
2
3 import java.util.Set JavaDoc;
4
5 import spoon.aval.Validator;
6 import spoon.aval.annotations.jwsVal.ValidWebServiceBean;
7 import spoon.aval.processing.ValidationPoint;
8 import spoon.processing.Severity;
9 import spoon.reflect.declaration.CtClass;
10 import spoon.reflect.declaration.CtConstructor;
11 import spoon.reflect.declaration.ModifierKind;
12
13 public class ValidWebServiceBeanValidator implements
14         Validator<ValidWebServiceBean> {
15
16     public void check(ValidationPoint<ValidWebServiceBean> vp) {
17         if (vp.getProgramElement() instanceof CtClass) {
18             CtClass<?> wsBean = (CtClass<?>) vp.getProgramElement();
19             boolean isOuter = wsBean.getParent(CtClass.class) == null;
20             boolean isFinal = wsBean.hasModifier(ModifierKind.FINAL);
21             boolean hasDefautlConstructor = hasDefaultConstructor(wsBean);
22
23             if (!isOuter) {
24                 ValidationPoint.report(Severity.ERROR, wsBean,
25                         "A Web Service Bean should be an outer class");
26             }
27
28             if (isFinal) {
29                 ValidationPoint.report(Severity.ERROR, wsBean,
30                         "A Web Service Bean should not be a final class");
31             }
32
33             if (!hasDefautlConstructor) {
34                 ValidationPoint
35                         .report(Severity.ERROR, wsBean,
36                                 "A Web Service Bean should declare a public default constructor");
37             }
38
39         }
40     }
41
42     private boolean hasDefaultConstructor(CtClass<?> wsBean) {
43         Set JavaDoc<CtConstructor> constructors = wsBean.getConstructors();
44
45         for (CtConstructor cons : constructors) {
46             boolean isPublic = cons.hasModifier(ModifierKind.PUBLIC);
47             boolean hasParams = cons.getParameters().size() != 0;
48             if (isPublic && !hasParams) {
49                 return true;
50             }
51         }
52
53         return false;
54     }
55
56 }
57
Popular Tags