1 package com.sun.tools.xjc.runtime; 2 3 import javax.xml.bind.ValidationEvent; 4 import javax.xml.bind.helpers.PrintConversionEventImpl; 5 import javax.xml.bind.helpers.ValidationEventImpl; 6 import javax.xml.bind.helpers.ValidationEventLocatorImpl; 7 8 import org.xml.sax.SAXException ; 9 10 import com.sun.xml.bind.Messages; 11 import com.sun.xml.bind.serializer.AbortSerializationException; 12 import com.sun.xml.bind.util.ValidationEventLocatorExImpl; 13 14 19 public class Util { 20 24 public static void handlePrintConversionException( 25 Object caller, Exception e, XMLSerializer serializer ) throws SAXException { 26 27 if( e instanceof SAXException ) 28 throw (SAXException )e; 32 33 String message = e.getMessage(); 34 if(message==null) { 35 message = e.toString(); 36 } 37 38 ValidationEvent ve = new PrintConversionEventImpl( 39 ValidationEvent.ERROR, message, 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 ValidationEventLocatorExImpl(parentObject,fieldName) ); 57 58 serializer.reportError(ve); 59 } 60 61 private static String getUserFriendlyTypeName( Object o ) { 62 if( o instanceof ValidatableObject ) 64 return ((ValidatableObject)o).getPrimaryInterface().getName(); 65 else 66 return o.getClass().getName(); 68 } 69 } 71 | Popular Tags |