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
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenkimport javax.xml.bind.DatatypeConverter;
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenkimport javax.xml.bind.PropertyException;
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenkimport javax.xml.bind.ValidationEvent;
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenkimport javax.xml.bind.ValidationEventHandler;
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenkimport javax.xml.bind.ValidationException;
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenkimport javax.xml.bind.Validator;
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenkimport javax.xml.bind.helpers.DefaultValidationEventHandler;
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport org.xml.sax.SAXException;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenkimport com.sun.xml.bind.DatatypeConverterImpl;
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenkimport com.sun.xml.bind.validator.Messages;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk/*
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk TODO:
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk reorganize classes into appropriate packages.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk to reflect the fact that some of the classes in
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk the marshaller package are used for both marshalling
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk and validation.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk In particular, the MarshallingContext interface should be
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk renamed. It is not only for marshalling.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk (something like "Serializer", maybe).
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk*/
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk/**
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Validator implementation of JAXB RI.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkpublic class ValidatorImpl implements Validator
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk{
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /** Validation errors will be reported to this object. */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk private ValidationEventHandler eventHandler =
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk new DefaultValidationEventHandler();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk final DefaultJAXBContextImpl jaxbContext;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk public ValidatorImpl( DefaultJAXBContextImpl c ) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // initialize datatype converter with ours
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk DatatypeConverter.setDatatypeConverter(DatatypeConverterImpl.theInstance);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk jaxbContext = c;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /**
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * We need to know whether an validation error was detected or not.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * For this purpose, we set up the validation so that this interceptor
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * will "intercept" errors before the application receives it.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk private static class EventInterceptor implements ValidationEventHandler {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk EventInterceptor( ValidationEventHandler _next ) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk this.next = _next;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk private boolean hadError = false;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk public boolean hadError() { return hadError; }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /** event will be passed to this component. */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk private final ValidationEventHandler next;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk public boolean handleEvent( ValidationEvent e ) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk hadError = true;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk boolean result;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if( next!=null ) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // pass it to the application
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk try {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk result = next.handleEvent(e);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } catch( RuntimeException re ) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // if the client event handler causes a RuntimeException,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // then we have to return false
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk result = false;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } else {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // if no error handler was specified, there is no point
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // in continuing the validation.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk result = false;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return result;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk };
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk public boolean validateRoot( Object o ) throws ValidationException {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if( o == null ) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk throw new IllegalArgumentException(
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Messages.format( Messages.MUST_NOT_BE_NULL, "rootObj" ) );
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return validate(o,true);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk public boolean validate( Object o ) throws ValidationException {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if( o == null ) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk throw new IllegalArgumentException(
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Messages.format( Messages.MUST_NOT_BE_NULL, "subrootObj" ) );
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return validate(o,false);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk private boolean validate( Object o, boolean validateId )
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk throws ValidationException {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk try {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk //ValidatableObject vo = Util.toValidatableObject(o);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk ValidatableObject vo = jaxbContext.getGrammarInfo().castToValidatableObject(o);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if(vo==null)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk throw new ValidationException(
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Messages.format( Messages.NOT_VALIDATABLE ) );
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk EventInterceptor ei = new EventInterceptor(eventHandler);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk ValidationContext context = new ValidationContext(jaxbContext,ei,validateId);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk context.validate(vo);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk context.reconcileIDs();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return !ei.hadError();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } catch( SAXException e ) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // we need a consistent mechanism to convert SAXException into JAXBException
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Exception nested = e.getException();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if( nested != null ) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk throw new ValidationException( nested );
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } else {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk throw new ValidationException( e );
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk //return false;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk public ValidationEventHandler getEventHandler() {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return eventHandler;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk public void setEventHandler( ValidationEventHandler handler ) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if( handler == null ) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk eventHandler = new DefaultValidationEventHandler();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } else {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk eventHandler = handler;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /**
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * There are no required properties, so simply throw an exception. Other
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * providers may have support for properties on Validator, but the RI doesn't
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk public void setProperty( String name, Object value )
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk throws PropertyException {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if( name == null ) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk throw new IllegalArgumentException(
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Messages.format( Messages.MUST_NOT_BE_NULL, "name" ) );
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk throw new PropertyException(name, value);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /**
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * There are no required properties, so simply throw an exception. Other
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * providers may have support for properties on Validator, but the RI doesn't
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk public Object getProperty( String name )
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk throws PropertyException {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if( name == null ) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk throw new IllegalArgumentException(
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Messages.format( Messages.MUST_NOT_BE_NULL, "name" ) );
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk throw new PropertyException(name);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk}