01: package newprocess.validation;
02:
03: import org.eclipse.emf.ecore.EObject;
04: import org.eclipse.jdt.core.JavaConventions;
05:
06: /**
07: *
08: * perform validations on the process itself
09: * @author sh
10: *
11: */
12: public class ProcessValidatorImpl implements ProcessValidator {
13:
14: public static final ProcessValidatorImpl INSTANCE = new ProcessValidatorImpl();
15:
16: public boolean validate(EObject obj) {
17: if (!(obj instanceof newprocess.Process))
18: return false;
19: newprocess.Process proc = (newprocess.Process) obj;
20: if (!validateName(proc) || !validateImplementation(proc)
21: || !validateSubject(proc))
22: return false;
23: return true;
24: }
25:
26: public boolean validateName(newprocess.Process proc) {
27: if ((proc).getName() == null || (proc).getName() == "")
28: return false;
29: return true;
30: }
31:
32: public boolean validateImplementation(newprocess.Process proc) {
33: if (ImplementationValidator.INSTANCE.validate(proc))
34: return true;
35: return false;
36: }
37:
38: /**
39: * a subject has to exist and to be a valid fully identifier
40: * @param proc
41: * @return
42: */
43: public boolean validateSubject(newprocess.Process proc) {
44: String subj = proc.getSubject();
45: if (subj == null || subj == "")
46: return false;
47: if (!JavaConventions.validatePackageName(subj, null, null)
48: .isOK())
49: return false;
50: return true;
51: }
52:
53: /**
54: * a namespace can exist and if, has to be a fully indentifier
55: * @param proc
56: * @return
57: */
58: public boolean validateNamespace(newprocess.Process proc) {
59: String ns = proc.getNamespace();
60: if (!JavaConventions.validatePackageName(ns, null, null).isOK())
61: return false;
62: return true;
63: }
64:
65: } // ProcessValidator
|