View Javadoc

1   //
2   // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v1.0.3-b18-fcs 
3   // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
4   // Any modifications to this file will be lost upon recompilation of the source schema. 
5   // Generated on: 2004.12.16 at 07:09:42 EST 
6   //
7   
8   package net.sf.jour.config.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  /***
21   * 
22   * @author
23   *     Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
24   */
25  public class Util {
26      /***
27       * Reports a print conversion error while marshalling.
28       */
29      public static void handlePrintConversionException(
30          Object caller, Exception e, XMLSerializer serializer ) throws SAXException {
31          
32          if( e instanceof SAXException )
33              // assume this exception is not from application.
34              // (e.g., when a marshaller aborts the processing, this exception
35              //        will be thrown) 
36              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      /***
45       * Reports that the type of an object in a property is unexpected.  
46       */
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, // maybe it should be a fatal error.
52              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  }