Source code: com/sample/addressbook/controller/contact/validation/ContactValidation.java
1 /*
2 * ContactValidation.java
3 *
4 * Copyright (c) 2001, 2002 Aendvari, Ltd. All Rights Reserved.
5 *
6 */
7
8 package com.sample.addressbook.controller.contact.validation;
9
10 import java.util.Iterator;
11 import java.util.Collection;
12
13 import com.aendvari.common.model.xalan.*;
14 import com.aendvari.common.model.*;
15
16 import com.aendvari.griffin.validation.*;
17 import com.aendvari.griffin.validation.validators.simple.*;
18
19 import com.aendvari.common.notices.*;
20 import com.aendvari.common.util.*;
21
22
23 /**
24 * This class provides the validation routine for managing a contact.
25 *
26 * @author Scott Milne
27 *
28 */
29
30 public class ContactValidation
31 {
32 /**
33 * Execute the validation on the form data.
34 *
35 * @param formNode A {@link ModelNode} instance
36 * pointing to the form to which
37 * to extract the form data.
38 *
39 */
40
41 public static Notices validate( ModelNode formNode )
42 {
43 Notices errorMessages = null;
44
45 // typically, the only reason and Exception will be thrown is if
46 // a property validation method or the configuration reading fails
47 try
48 {
49 // create a new validation, loading in the validation descriptor we want to use
50 Validation validation = new Validation(
51 new com.aendvari.common.model.xalan.XalanModelTreeFactory(),
52 ContactDatasetDescriptor.class
53 );
54
55 // create our error handler
56 ContactErrorHandler errorHandler = new ContactErrorHandler();
57
58 // build the list of pre-defined handlers
59 ValidationHandler[] handlers = {
60 new ValidationHandler("contactErrorHandler", errorHandler )
61 };
62
63 // execute the validation
64 validation.validate( formNode, handlers );
65
66 // get the messages from the error handler
67 errorMessages = errorHandler.getErrorMessages();
68 }
69 // typically, the only reason and Exception will be thrown is if
70 // a property validation method or the configuration reading fails
71 catch( Exception exception )
72 {
73 exception.printStackTrace();
74 }
75
76 // return it
77 return errorMessages;
78 }
79 }
80