1 8 package com.sun.japex.testsuite.impl.runtime; 9 10 import javax.xml.bind.ValidationEvent; 11 import javax.xml.bind.helpers.PrintConversionEventImpl; 12 import javax.xml.bind.helpers.ValidationEventImpl; 13 import javax.xml.bind.helpers.ValidationEventLocatorImpl; 14 15 import org.xml.sax.SAXException ; 16 17 import com.sun.xml.bind.Messages; 18 import com.sun.xml.bind.serializer.AbortSerializationException; 19 20 25 public class Util { 26 29 public static void handlePrintConversionException( 30 Object caller, Exception e, XMLSerializer serializer ) throws SAXException { 31 32 if( e instanceof SAXException ) 33 throw (SAXException )e; 37 38 ValidationEvent ve = new PrintConversionEventImpl( 39 ValidationEvent.ERROR, e.getMessage(), 40 new ValidationEventLocatorImpl(caller), e ); 41 serializer.reportError(ve); 42 } 43 44 47 public static void handleTypeMismatchError( XMLSerializer serializer, 48 Object parentObject, String fieldName, Object childObject ) throws AbortSerializationException { 49 50 ValidationEvent ve = new ValidationEventImpl( 51 ValidationEvent.ERROR, Messages.format(Messages.ERR_TYPE_MISMATCH, 53 getUserFriendlyTypeName(parentObject), 54 fieldName, 55 getUserFriendlyTypeName(childObject) ), 56 new ValidationEventLocatorImpl(parentObject) ); 57 58 serializer.reportError(ve); 59 } 60 61 private static String getUserFriendlyTypeName( Object o ) { 62 if( o instanceof ValidatableObject ) 63 return ((ValidatableObject)o).getPrimaryInterface().getName(); 64 else 65 return o.getClass().getName(); 66 } 67 } 68 | Popular Tags |