5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk//
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v1.0.6-b27-fcs
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk// Any modifications to this file will be lost upon recompilation of the source schema.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk// Generated on: 2012.06.11 at 10:34:07 AM PDT
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk//
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkpackage com.sun.identity.saml2.jaxb.assertion.impl.runtime;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport javax.xml.bind.ValidationEvent;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport javax.xml.bind.helpers.PrintConversionEventImpl;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport javax.xml.bind.helpers.ValidationEventImpl;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport javax.xml.bind.helpers.ValidationEventLocatorImpl;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenkimport org.xml.sax.SAXException;
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenkimport com.sun.xml.bind.Messages;
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenkimport com.sun.xml.bind.serializer.AbortSerializationException;
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenkimport com.sun.xml.bind.util.ValidationEventLocatorExImpl;
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk/**
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * @author
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkpublic class Util {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /**
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Reports a print conversion error while marshalling.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk public static void handlePrintConversionException(
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Object caller, Exception e, XMLSerializer serializer ) throws SAXException {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if( e instanceof SAXException )
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // assume this exception is not from application.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // (e.g., when a marshaller aborts the processing, this exception
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // will be thrown)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk throw (SAXException)e;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk String message = e.getMessage();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if(message==null) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk message = e.toString();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk ValidationEvent ve = new PrintConversionEventImpl(
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk ValidationEvent.ERROR, message,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk new ValidationEventLocatorImpl(caller), e );
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk serializer.reportError(ve);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /**
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Reports that the type of an object in a property is unexpected.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk public static void handleTypeMismatchError( XMLSerializer serializer,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Object parentObject, String fieldName, Object childObject ) throws AbortSerializationException {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk ValidationEvent ve = new ValidationEventImpl(
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk ValidationEvent.ERROR, // maybe it should be a fatal error.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Messages.format(Messages.ERR_TYPE_MISMATCH,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk getUserFriendlyTypeName(parentObject),
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk fieldName,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk getUserFriendlyTypeName(childObject) ),
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk new ValidationEventLocatorExImpl(parentObject,fieldName) );
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk serializer.reportError(ve);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk private static String getUserFriendlyTypeName( Object o ) {
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk if( o instanceof ValidatableObject )
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return ((ValidatableObject)o).getPrimaryInterface().getName();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk else
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return o.getClass().getName();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk}