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 java.util.HashMap;
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenkimport java.util.HashSet;
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenkimport java.util.Iterator;
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenkimport java.util.Map;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport javax.xml.bind.ValidationEvent;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport javax.xml.bind.ValidationEventHandler;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport javax.xml.bind.helpers.NotIdentifiableEventImpl;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport javax.xml.bind.helpers.ValidationEventImpl;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport javax.xml.bind.helpers.ValidationEventLocatorImpl;
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenkimport org.xml.sax.SAXException;
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenkimport com.sun.xml.bind.ProxyGroup;
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenkimport com.sun.xml.bind.serializer.AbortSerializationException;
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenkimport com.sun.xml.bind.validator.Messages;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk/**
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Maintains information that needs to be stored across
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * validations of multiple objects.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Specifically, this object is responsible for:
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * <ol>
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * <li>detecting a cycle in a content tree by keeping track of
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * objects that were validated.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * <li>keeping an instance of NamespaceContextImpl, which is
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * shared by all MSVValidators.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * <li>keeping a reference to {@link ValidationErrorHandler}.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * MSVValidators should use this error handler to report any error.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * </ol>
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkclass ValidationContext
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk{
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk final DefaultJAXBContextImpl jaxbContext;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /**
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * @param validateID
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * if true, ID/IDREF validation will be performed.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk ValidationContext( DefaultJAXBContextImpl _context, ValidationEventHandler _eventHandler, boolean validateID ) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk this.jaxbContext = _context;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk this.eventHandler = _eventHandler;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk this.validateID = validateID;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk//
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk//
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk// detecting cycles.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk//
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk//
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /** Set of all validated objects. Used to detect a cycle. */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk private final IdentityHashSet validatedObjects = new IdentityHashSet();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /**
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Validates the sub-tree rooted at <code>vo</code> and reports
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * any errors/warnings to the error handler.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk public void validate( ValidatableObject vo ) throws SAXException {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if( validatedObjects.add(ProxyGroup.unwrap(vo)) ) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // setup a new validator for this object and validate it.
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk MSVValidator.validate(jaxbContext,this,vo);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } else {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // this object has already been validated once.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk reportEvent( vo, Messages.format( Messages.CYCLE_DETECTED ) );
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk//
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk//
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk// Keeping track of namespace bindings.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk//
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk//
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /** namespace context. */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk private final NamespaceContextImpl nsContext = new NamespaceContextImpl(null);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk public NamespaceContextImpl getNamespaceContext() { return nsContext; }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk//
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk//
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk// ID/IDREF validation
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk//
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk//
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /** ID/IDREF validation is done only when this flag is true. */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk private final boolean validateID;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk private final HashSet IDs = new HashSet();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk private final HashMap IDREFs = new HashMap();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk public String onID( XMLSerializable owner, String value ) throws SAXException {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if(!validateID) return value;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if(!IDs.add(value)) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // this ID value has already been used.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk //reportEvent(Util.toValidatableObject(owner),
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // Messages.format(Messages.DUPLICATE_ID,value));
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk reportEvent(jaxbContext.getGrammarInfo().castToValidatableObject(owner),
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Messages.format(Messages.DUPLICATE_ID,value));
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return value;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk public String onIDREF( XMLSerializable referer, String value ) throws SAXException {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if(!validateID) return value;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if(IDs.contains(value))
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return value; // this IDREF has the corresponding ID.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // remember the value to check the value later.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk IDREFs.put(value,referer);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return value;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /** Tests if all IDREFs have corresponding IDs. */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk protected void reconcileIDs() throws SAXException {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if(!validateID) return;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk for (Iterator itr = IDREFs.entrySet().iterator(); itr.hasNext();) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Map.Entry e = (Map.Entry) itr.next();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if(IDs.contains(e.getKey()))
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk continue; // OK.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // ID was not found.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk ValidatableObject source = (ValidatableObject)e.getValue();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk reportEvent(
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk source,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk new NotIdentifiableEventImpl(
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk ValidationEvent.ERROR,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Messages.format( Messages.ID_NOT_FOUND, e.getKey() ),
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk new ValidationEventLocatorImpl( source ) ) );
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk IDREFs.clear();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk//
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk//
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk// Keeping track of ValidationErrorHandler
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk//
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk//
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk private final ValidationEventHandler eventHandler;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /**
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Reports an error to the application.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk public void reportEvent(ValidatableObject source, String formattedMessage) throws AbortSerializationException {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk reportEvent(
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk source,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk new ValidationEventImpl( ValidationEvent.ERROR,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk formattedMessage,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk new ValidationEventLocatorImpl(source) ) );
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /**
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Reports an error to the client.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * This version should be used when an exception is thrown from sub-modules.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk public void reportEvent(ValidatableObject source, Exception nestedException ) throws AbortSerializationException {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk reportEvent(
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk source,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk new ValidationEventImpl( ValidationEvent.ERROR,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk nestedException.toString(),
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk new ValidationEventLocatorImpl(source),
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk nestedException ) );
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk public void reportEvent( ValidatableObject source, ValidationEvent event ) throws AbortSerializationException {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk boolean r;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk try {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk r = eventHandler.handleEvent( event );
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } catch( RuntimeException re ) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // if the client event handler causes a RuntimeException, then
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // we have to return false.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk r = false;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if(!r) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // throw an exception to abort validation
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk throw new AbortSerializationException( event.getMessage() );
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk}