1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.struts.flow.core.source.impl.validity;
18
19 import java.util.Iterator;
20 import java.util.List;
21
22 import org.apache.struts.flow.core.source.SourceValidity;
23
24 /***
25 * A validation object using a List.
26 *
27 * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
28 * @version CVS $Revision: 1.4 $ $Date: 2004/02/28 11:47:17 $
29 */
30 public final class AggregatedValidity
31 extends AbstractAggregatedValidity
32 implements SourceValidity
33 {
34 /***
35 * Check if the component is still valid.
36 * If <code>0</code> is returned the isValid(SourceValidity) must be
37 * called afterwards!
38 * If -1 is returned, the component is not valid anymore and if +1
39 * is returnd, the component is valid.
40 */
41 public int isValid()
42 {
43 for( final Iterator i = m_list.iterator(); i.hasNext(); )
44 {
45 final int v = ( (SourceValidity)i.next() ).isValid();
46 if( v < 1 )
47 {
48 return v;
49 }
50 }
51 return 1;
52 }
53
54 public int isValid( final SourceValidity validity )
55 {
56 if( validity instanceof AggregatedValidity )
57 {
58 final AggregatedValidity other = (AggregatedValidity)validity;
59 final List otherList = other.m_list;
60 if( m_list.size() != otherList.size() )
61 {
62 return -1;
63 }
64
65 for( final Iterator i = m_list.iterator(), j = otherList.iterator(); i.hasNext(); )
66 {
67 final SourceValidity srcA = (SourceValidity)i.next();
68 final SourceValidity srcB = (SourceValidity)j.next();
69 int result = srcA.isValid();
70 if ( result == -1)
71 {
72 return -1;
73 }
74 if ( result == 0 )
75 {
76 result = srcA.isValid( srcB );
77 if ( result < 1)
78 {
79 return result;
80 }
81 }
82 }
83 return 1;
84 }
85 return -1;
86 }
87
88 }
89