View Javadoc

1   //
2   // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v@@BUILD_VERSION@@ 
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.30 um 05:21:08 CEST 
6   //
7   
8   package de.nierbeck.timeTrack.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 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(Object caller,
30  			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  		String message = e.getMessage();
39  		if (message == null) {
40  			message = e.toString();
41  		}
42  
43  		ValidationEvent ve = new PrintConversionEventImpl(
44  				ValidationEvent.ERROR, message, new ValidationEventLocatorImpl(
45  						caller), e);
46  		serializer.reportError(ve);
47  	}
48  
49  	/***
50  	 * Reports that the type of an object in a property is unexpected.
51  	 */
52  	public static void handleTypeMismatchError(XMLSerializer serializer,
53  			Object parentObject, String fieldName, Object childObject)
54  			throws AbortSerializationException {
55  
56  		ValidationEvent ve = new ValidationEventImpl(ValidationEvent.ERROR, // maybe
57  				// it
58  				// should
59  				// be a
60  				// fatal
61  				// error.
62  				Messages.format(Messages.ERR_TYPE_MISMATCH,
63  						getUserFriendlyTypeName(parentObject), fieldName,
64  						getUserFriendlyTypeName(childObject)),
65  				new ValidationEventLocatorExImpl(parentObject, fieldName));
66  
67  		serializer.reportError(ve);
68  	}
69  
70  	private static String getUserFriendlyTypeName(Object o) {
71  		if (o instanceof ValidatableObject)
72  			return ((ValidatableObject) o).getPrimaryInterface().getName();
73  		else
74  			return o.getClass().getName();
75  	}
76  }