KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mvnforum > jaxb > db > impl > runtime > Util


1 //
2
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v1.0.5-b16-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.12.17 at 09:43:27 AM GMT+07:00
6
//
7

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 JavaDoc;
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 JavaDoc caller, Exception JavaDoc e, XMLSerializer serializer ) throws SAXException JavaDoc {
32         
33         if( e instanceof SAXException JavaDoc )
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 JavaDoc)e;
38         
39         String JavaDoc 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 JavaDoc parentObject, String JavaDoc fieldName, Object JavaDoc 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 JavaDoc getUserFriendlyTypeName( Object JavaDoc o ) {
68         if( o instanceof ValidatableObject )
69             return ((ValidatableObject)o).getPrimaryInterface().getName();
70         else
71             return o.getClass().getName();
72     }
73 }
74
Popular Tags