1 package org.codehaus.metaclass.io; 2 3 import org.xml.sax.helpers.AttributesImpl; 4 import org.jmock.Constraint; 5 6 class EqAttributesConstraint 7 implements Constraint 8 { 9 private final AttributesImpl _attributes; 10 11 EqAttributesConstraint( final AttributesImpl attributes ) 12 { 13 _attributes = attributes; 14 } 15 16 public boolean eval( Object object ) 17 { 18 System.out.println( "EqAttributesConstraint.eval(" + object + ")" ); 19 if( !( object instanceof AttributesImpl ) ) 20 { 21 System.out.println( "Bad Type!" ); 22 return false; 23 } 24 final AttributesImpl other = (AttributesImpl)object; 25 final int length = _attributes.getLength(); 26 if( other.getLength() != length ) 27 { 28 System.out.println( "Bad Length! " + other.getLength() + "!=" + length ); 29 return false; 30 } 31 for( int i = 0; i < length; i++ ) 32 { 33 final String qName = _attributes.getQName( i ); 34 final String value = _attributes.getValue( qName ); 35 final String otherValue = other.getValue( qName ); 36 if( !value.equals( otherValue ) ) 37 { 38 System.out.println( "Bad Value for " + qName + " " + value + "!=" + otherValue ); 39 return false; 40 } 41 } 42 return true; 43 } 44 }