01: /**
02: *
03: */package newprocess.validation;
04:
05: import java.util.Iterator;
06:
07: import newprocess.Message;
08:
09: import org.eclipse.emf.common.util.EList;
10: import org.eclipse.emf.ecore.EObject;
11:
12: /**
13: * @author sh
14: *
15: */
16: public class MessageValidatorImpl implements MessageValidator {
17:
18: // singleton
19: public static final MessageValidatorImpl INSTANCE = new MessageValidatorImpl();
20:
21: public boolean validate(EObject obj) {
22: if (!(obj instanceof Message))
23: return false;
24: Message msg = (Message) obj;
25: if (!validateName(msg))
26: return false;
27: return true;
28: }
29:
30: public boolean validateName(Message msg) {
31: String msgName = msg.getName();
32: if (msgName == null || msgName == "")
33: return false;
34:
35: // uniqueness check
36: EList<Message> messages = ((newprocess.Process) msg
37: .eContainer()).getHasMessages();
38: for (Iterator<Message> iterator = messages.iterator(); iterator
39: .hasNext();) {
40: Message message = (Message) iterator.next();
41: if (message == msg)
42: continue;
43: String curName = message.getName();
44: if (curName != null && curName.equals(msgName))
45: return false;
46: }
47: return true;
48: }
49: }
|