1 17 package org.apache.excalibur.source.impl.validity; 18 19 import java.io.IOException ; 20 import java.util.ArrayList ; 21 import java.util.Iterator ; 22 import java.util.ListIterator ; 23 24 import org.apache.excalibur.source.SourceValidity; 25 26 35 public final class DeferredAggregatedValidity 36 extends AbstractAggregatedValidity 37 implements SourceValidity 38 { 39 40 public void add( final DeferredValidity validity ) 41 { 42 m_list.add( validity ); 43 } 44 45 52 public int isValid() 53 { 54 for( final ListIterator i = m_list.listIterator(); i.hasNext(); ) 55 { 56 final Object o = i.next(); 57 final SourceValidity validity; 58 if (o instanceof SourceValidity) { 59 validity = (SourceValidity)o; 60 } else { 61 validity = ((DeferredValidity)o).getValidity(); 62 i.set(validity); 63 } 64 final int v = validity.isValid(); 65 if( v < 1 ) 66 { 67 return v; 68 } 69 } 70 return 1; 71 } 72 73 public int isValid( final SourceValidity validity ) 74 { 75 AbstractAggregatedValidity aggregatedValidity = null; 76 77 if (validity instanceof AbstractAggregatedValidity) 78 { 79 aggregatedValidity = (AbstractAggregatedValidity)validity; 80 } 81 82 if ( null != aggregatedValidity) 83 { 84 ArrayList otherList = aggregatedValidity.m_list; 85 if( m_list.size() != otherList.size() ) 86 { 87 return -1; 88 } 89 90 for(int i=0; i < m_list.size(); i++) { 91 final SourceValidity srcA = this.getValidity(i); 92 int result = srcA.isValid(); 93 if ( result == -1) 94 { 95 return -1; 96 } 97 if ( result == 0 ) 98 { 99 final SourceValidity srcB = aggregatedValidity.getValidity(i); 100 result = srcA.isValid( srcB ); 101 if ( result < 1) 102 { 103 return result; 104 } 105 } 106 } 107 return 1; 108 } 109 return -1; 110 } 111 112 public String toString() 113 { 114 final StringBuffer sb = new StringBuffer ( "SourceValidity " ); 115 for( final Iterator i = m_list.iterator(); i.hasNext(); ) 116 { 117 sb.append( i.next() ); 118 if( i.hasNext() ) sb.append( ':' ); 119 } 120 return sb.toString(); 121 } 122 123 SourceValidity getValidity(final int index) 124 { 125 final Object o = m_list.get(index); 126 final SourceValidity validity; 127 if (o instanceof SourceValidity) { 128 validity = (SourceValidity)o; 129 } else { 130 validity = ((DeferredValidity)o).getValidity(); 131 m_list.set(index, validity); 132 } 133 return validity; 134 } 135 136 private void writeObject(java.io.ObjectOutputStream out) 137 throws IOException 138 { 139 for(int i=0; i<m_list.size();i++) { 141 this.getValidity(i); 142 } 143 out.defaultWriteObject(); 144 } 145 146 } 147 148 | Popular Tags |