View Javadoc
1   /*
2    * #%L
3    * Nuiton Validator
4    * %%
5    * Copyright (C) 2013 - 2014 Code Lutin, Tony Chemit
6    * %%
7    * This program is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU Lesser General Public License as 
9    * published by the Free Software Foundation, either version 3 of the 
10   * License, or (at your option) any later version.
11   * 
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Lesser Public License for more details.
16   * 
17   * You should have received a copy of the GNU General Lesser Public 
18   * License along with this program.  If not, see
19   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
20   * #L%
21   */
22  package org.nuiton.validator;
23  
24  import java.io.Serializable;
25  import java.util.Collections;
26  import java.util.Map;
27  import java.util.Set;
28  
29  /**
30   * Represents the model of a {@link NuitonValidator}.
31   *
32   * This model describing properties of a validator :
33   * <ul>
34   * <li>{@link #type} : the type of object which can be validated by the validator</li>
35   * <li>{@link #context} : the context of validation, if no context is required then the context is {@code null}.
36   * <li>{@link #scopes} : the scopes of validation (see {@link NuitonValidatorScope})</li>
37   * <li>{@link #fields} : the fields that can be validated by the validator</li>
38   * </ul>
39   *
40   * @author Tony Chemit - chemit@codelutin.com
41   * @since 2.0
42   */
43  public class NuitonValidatorModel<O> implements Serializable {
44  
45      private static final long serialVersionUID = 1L;
46  
47      /** Type of object to validate */
48      protected Class<O> type;
49  
50      /** Context of validation (can be {@code null}, for no context). */
51      protected String context;
52  
53      /** Set of scopes that can be validated for the type and context */
54      protected Set<NuitonValidatorScope> scopes;
55  
56      /** Set of fields that can be validated for the type and context */
57      protected Map<NuitonValidatorScope, String[]> fields;
58  
59      public NuitonValidatorModel(Class<O> type,
60                                  String context,
61                                  Set<NuitonValidatorScope> scopes,
62                                  Map<NuitonValidatorScope, String[]> fields) {
63          this.type = type;
64          this.context = context;
65          this.scopes = Collections.unmodifiableSet(scopes);
66          this.fields = Collections.unmodifiableMap(fields);
67      }
68  
69      public Class<O> getType() {
70          return type;
71      }
72  
73      public String getContext() {
74          return context;
75      }
76  
77      public Set<NuitonValidatorScope> getScopes() {
78          return scopes;
79      }
80  
81      public Map<NuitonValidatorScope, String[]> getFields() {
82          return fields;
83      }
84  }