KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > excalibur > source > impl > validity > AggregatedValidity


1 /*
2  * Copyright 2002-2004 The Apache Software Foundation
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12  * implied.
13  *
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.excalibur.source.impl.validity;
18
19 import java.util.Iterator JavaDoc;
20 import java.util.List JavaDoc;
21
22 import org.apache.excalibur.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 JavaDoc 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 JavaDoc otherList = other.m_list;
60             if( m_list.size() != otherList.size() )
61             {
62                 return -1;
63             }
64
65             for( final Iterator JavaDoc 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
90
Popular Tags