Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/aendvari/griffin/validation/dataset/Dataset.java


1   /*
2    * Dataset.java
3    *
4    * Copyright (c) 2001, 2002 Aendvari, Ltd. All Rights Reserved.
5    *
6    * See the file LICENSE for terms of use.
7    *
8    */
9   
10  package com.aendvari.griffin.validation.dataset;
11  
12  import java.io.*;
13  import java.util.*;
14  import java.beans.*;
15  
16  import java.lang.reflect.*;
17  import java.lang.NoSuchMethodException;
18  import java.lang.IllegalAccessException;
19  
20  import com.aendvari.common.util.MultiHashMap;
21  import com.aendvari.common.model.*;
22  
23  import com.aendvari.griffin.validation.*;
24  import com.aendvari.griffin.validation.validator.*;
25  
26  
27  /**
28   * <p>Defines a {@link com.aendvari.griffin.validation.dataset.Dataset}.</p>
29   *
30   * <p>A <code>Dataset</code> defines a group of {@link Property} objects (usually describing a form POST).
31   * Each will be used to execute a their described validator methods.</p>
32   *
33   * @author  Scott Milne
34   *
35   */
36  
37  public class Dataset
38  {
39    /* Variables */
40  
41    /** The list of {@link Property} objects. */
42    private ArrayList properties;
43  
44  
45    /* Constructors. */
46  
47  
48    /**
49     * Constructs an empty <code>Dataset</code> instance.
50     *
51     */
52  
53    public Dataset()
54    {
55      properties = new ArrayList();
56    }
57  
58    /**
59     * Get the list of properties for this dataset.
60     *
61     * @return                  Collection of {@link Property} objects.
62     *
63     */
64  
65    public Collection getProperties()
66    {
67      return properties;
68    }
69  
70    /**
71     * Set the list of properties for this dataset.
72     *
73     * @param    setProperties        A Collection of {@link Property} objects.
74     *
75     */
76  
77    public void setProperties( Collection setProperties )
78    {
79      properties = new ArrayList(setProperties);
80    }
81  
82    /**
83     * Add a property to the list of properties for this dataset.
84     *
85     * @param    property          A {@link Property} object.
86     *
87     */
88  
89    public void addProperty( Property property )
90    {
91      properties.add(property);
92    }
93  
94    /**
95     * Executes all validate methods on each {@link Property} of each {@link Dataset}
96     *
97     * @param    datasetNode          The {@link ModelNode} of which to extract the data to be validated from.
98     * @param    validators          A <code>MultiHashMap</code> of {@link Validator} instances.
99     * @param    handlers          A <code>HashMap</code> of {@link ValidationHandler} instances.
100    *
101    */
102 
103   public void executeValidation( ModelNode datasetNode, MultiHashMap validators, HashMap handlers )
104     throws Exception
105   {
106     // for each property
107     Iterator propertyIterator = properties.iterator();
108 
109     while ( propertyIterator.hasNext() )
110     {
111       Property property = (Property)propertyIterator.next();
112 
113       property.executeValidation( datasetNode, validators, handlers );
114     }
115   }
116 
117   /**
118    * Convert this object into a String representation.
119    *
120    */
121 
122   public String toString()
123   {
124     String data = "Dataset [";
125     data += "properties="+properties;
126     data += "]";
127     return data;
128   }
129 }
130