01: //
02: // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v1.0.4-b18-fcs
03: // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
04: // Any modifications to this file will be lost upon recompilation of the source schema.
05: // Generated on: 2005.03.04 at 10:20:40 PST
06: //
07:
08: package com.nabhinc.portal.config.impl.runtime;
09:
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(Object caller,
31: 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(
54: XMLSerializer serializer, Object parentObject,
55: String fieldName, Object childObject)
56: throws AbortSerializationException {
57:
58: ValidationEvent ve = new ValidationEventImpl(
59: ValidationEvent.ERROR, // maybe it should be a fatal error.
60: Messages
61: .format(Messages.ERR_TYPE_MISMATCH,
62: getUserFriendlyTypeName(parentObject),
63: fieldName,
64: getUserFriendlyTypeName(childObject)),
65: new ValidationEventLocatorExImpl(parentObject,
66: fieldName));
67:
68: serializer.reportError(ve);
69: }
70:
71: private static String getUserFriendlyTypeName(Object o) {
72: if (o instanceof ValidatableObject)
73: return ((ValidatableObject) o).getPrimaryInterface()
74: .getName();
75: else
76: return o.getClass().getName();
77: }
78: }
|