View Javadoc

1   //
2   // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v1.0.6-01/24/2006 06:15 PM(kohsuke)-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: 2012.10.03 at 04:27:47 AM CEST 
6   //
7   
8   package org.jdtaus.mojo.resource.model.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  /**
22   * 
23   * @author
24   *     Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
25   */
26  public class Util {
27      /**
28       * Reports a print conversion error while marshalling.
29       */
30      public static void handlePrintConversionException(
31          Object caller, Exception e, XMLSerializer serializer ) throws SAXException {
32          
33          if( e instanceof SAXException )
34              // assume this exception is not from application.
35              // (e.g., when a marshaller aborts the processing, this exception
36              //        will be thrown) 
37              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      /**
51       * Reports that the type of an object in a property is unexpected.  
52       */
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, // maybe it should be a fatal error.
58              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  }