KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > japex > testsuite > impl > runtime > Util


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: 2005.06.14 at 12:02:17 PDT
6
//
7

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 JavaDoc;
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 JavaDoc caller, Exception JavaDoc e, XMLSerializer serializer ) throws SAXException JavaDoc {
31         
32         if( e instanceof SAXException JavaDoc )
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 JavaDoc)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 JavaDoc parentObject, String JavaDoc fieldName, Object JavaDoc 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 JavaDoc getUserFriendlyTypeName( Object JavaDoc o ) {
62         if( o instanceof ValidatableObject )
63             return ((ValidatableObject)o).getPrimaryInterface().getName();
64         else
65             return o.getClass().getName();
66     }
67 }
68
Popular Tags