1 8 package com.mvnforum.jaxb.db.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 import com.sun.xml.bind.util.ValidationEventLocatorExImpl; 20 21 26 public class Util { 27 30 public static void handlePrintConversionException( 31 Object caller, Exception e, XMLSerializer serializer ) throws SAXException { 32 33 if( e instanceof SAXException ) 34 throw (SAXException )e; 38 39 String message = e.getMessage(); 40 if(message==null) { 41 message = e.toString(); 42 } 43 44 ValidationEvent ve = new PrintConversionEventImpl( 45 ValidationEvent.ERROR, message, 46 new ValidationEventLocatorImpl(caller), e ); 47 serializer.reportError(ve); 48 } 49 50 53 public static void handleTypeMismatchError( XMLSerializer serializer, 54 Object parentObject, String fieldName, Object childObject ) throws AbortSerializationException { 55 56 ValidationEvent ve = new ValidationEventImpl( 57 ValidationEvent.ERROR, Messages.format(Messages.ERR_TYPE_MISMATCH, 59 getUserFriendlyTypeName(parentObject), 60 fieldName, 61 getUserFriendlyTypeName(childObject) ), 62 new ValidationEventLocatorExImpl(parentObject,fieldName) ); 63 64 serializer.reportError(ve); 65 } 66 67 private static String getUserFriendlyTypeName( Object o ) { 68 if( o instanceof ValidatableObject ) 69 return ((ValidatableObject)o).getPrimaryInterface().getName(); 70 else 71 return o.getClass().getName(); 72 } 73 } 74 | Popular Tags |