4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v1.0.6-b27-fcs
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk// Any modifications to this file will be lost upon recompilation of the source schema.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk// Generated on: 2012.06.11 at 10:33:54 AM PDT
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenkpackage com.sun.identity.federation.jaxb.entityconfig.impl.runtime;
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenkimport com.sun.xml.bind.marshaller.IdentifiableObject;
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenkimport com.sun.xml.bind.serializer.AbortSerializationException;
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * XMLSerializer that calls the native interface of MSV and performs validation.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * Used in a pair with a ValidationContext.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * @author Kohsuke Kawaguchi
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenkpublic class MSVValidator implements XMLSerializer, IDContextProvider2
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk /** Current acceptor in use. */
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk /** Context object that coordinates the entire validation effort. */
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk /** The object which we are validating. */
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * Acceptor stack. Whenever an element is found, the current acceptor is
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * pushed to the stack and new one is created.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * LightStack is a light-weight stack implementation
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk private final LightStack stack = new LightStack();
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk public NamespaceContext2 getNamespaceContext() {
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * To use this class, call the static validate method.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk private MSVValidator( DefaultJAXBContextImpl _jaxbCtx, ValidationContext _ctxt, ValidatableObject vo ) {
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk acceptor = vo.createRawValidator().createAcceptor();
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * Validates the specified object and reports any error to the context.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk public static void validate( DefaultJAXBContextImpl jaxbCtx, ValidationContext context, ValidatableObject vo )
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk new MSVValidator(jaxbCtx,context,vo)._validate();
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // sometimes when a conversion between Java object and
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // lexical value fails, it may throw an exception like
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // NullPointerException or NumberFormatException.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // catch them and report them as an error.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk /** performs the validation to the object specified in the constructor. */
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // validate attributes
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // validate content model
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // some elements are missing
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // report error
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk public void endNamespaceDecls() throws SAXException {
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk context.getNamespaceContext().endNamespaceDecls();
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk public void endAttributes() throws SAXException {
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // some required attributes are missing.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // report a validation error
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // Note that we don't know which property of this object
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // causes this error.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk currentElementUri,currentElementLocalName,currentElementLocalName,
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk /** stores text reported by the text method. */
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk public final void text( String text, String fieldName ) throws SAXException {
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk public void reportMissingObjectError(String fieldName) throws SAXException {
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk reportError(Util.createMissingObjectError(target,fieldName));
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // used to keep attribute names until the endAttribute method is called.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk public void startAttribute( String uri, String local ) {
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // we will do the processing at the end element
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk public void endAttribute() throws SAXException {
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk if(!acceptor.onAttribute2( attNamespaceUri, attLocalName,
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk attLocalName /* we don't have QName, so just use the local name */,
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // either the name was incorrect (which is quite unlikely),
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // or the value was wrong.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // report an error
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk acceptor.onAttribute2( attNamespaceUri, attLocalName, attLocalName,
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk private void writePendingText() throws SAXException {
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // assert(textBuf!=null);
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk if(!acceptor.onText2( buf.toString(), this, null, null )) {
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // this text is invalid.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // report an error
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk acceptor.onText2( buf.toString(), this, ref, null );
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk public void startElement( String uri, String local ) throws SAXException {
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk StartTagInfo sti = new StartTagInfo(uri,local,local,emptyAttributes,this);
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // we pass in an empty attributes, as there is just no way for us to
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // properly re-construct attributes. Fortunately, I know MSV is not using
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // attribute values, so this would work, but nevertheless this code is
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // ugly. This is one of the problems of the "middle" approach.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk Acceptor child = acceptor.createChildAcceptor( sti, null );
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // this element is invalid. probably, so this object is invalid
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // report an error
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk child = acceptor.createChildAcceptor( sti, ref );
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // some required elements are missing
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // report error
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // pop the acceptor
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // some required elements are missing.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // report an error
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk acceptor.stepForward( child, ref ); // force recovery and obtain an error message.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk public void childAsAttributes( JAXBObject o, String fieldName ) throws SAXException {
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // do nothing
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // either the onMarshallableObjectInElement method
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // or the onMarshallableObjectInAttributeBody method will be
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // called for every content tree objects.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // so we don't need to validate an object within this method.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk public void childAsURIs( JAXBObject o, String fieldName ) throws SAXException {
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk /** An empty <code>Attributes</code> object. */
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk private static final AttributesImpl emptyAttributes = new AttributesImpl();
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk /** namespace URI of dummy elements. TODO: allocate one namespace URI for this. */
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk public void childAsBody( JAXBObject o, String fieldName ) throws SAXException {
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk //final ValidatableObject vo = Util.toValidatableObject(o);
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk final ValidatableObject vo = jaxbContext.getGrammarInfo().castToValidatableObject(o);
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk if( insideAttribute ) childAsAttributeBody(vo,fieldName);
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk private void childAsElementBody( Object o, ValidatableObject vo ) throws SAXException {
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk String intfName = vo.getPrimaryInterface().getName();
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // if the object implements the RIElement interface,
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // add a marker attribute to the dummy element.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // For example, if the object is org.acme.impl.FooImpl,
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // the dummy element will look like
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // <{DUMMY_ELEMENT_NS}org.acme.Foo
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // {<URI of this element>}:<local name of this element>="" />
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // This extra attribute is used to validate wildcards.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk// AttributesImpl atts;
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk// if(o instanceof RIElement) {
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk// RIElement rie = (RIElement)o;
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk// atts = new AttributesImpl();
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk// atts.addAttribute(
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk// rie.____jaxb_ri____getNamespaceURI(),
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk// rie.____jaxb_ri____getLocalName(),
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk// rie.____jaxb_ri____getLocalName(), // use local name as qname
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk// ""); // we don't care about the attribute value
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk// atts = emptyAttributes;
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // feed a dummy element to the acceptor.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk Acceptor child = acceptor.createChildAcceptor(sti,null);
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // some required elements were missing. report errors
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk if(o instanceof RIElement) {
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // this object is not a valid member of the wildcard
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk Messages.format( Messages.INCORRECT_CHILD_FOR_WILDCARD,
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // this can't be possible, as the dummy element was
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // generated by XJC.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // we need a separate validator instance to validate a child object
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk private void childAsAttributeBody( ValidatableObject vo, String fieldName ) throws SAXException {
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk Dirty quick hack. When we split a schema into fragments, basically
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk every chlid object needs a place holder in the fragment
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk (so that the parent schema fragment can correctly validate that the
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk child objects are at their supposed places.)
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk For example, cconsider the following schema:
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk <ref name="bar"/>
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk </oneOrMore>
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk </attribute>
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk In our algorithm, the corresponding schema fragment will be:
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk <value>\u0000full.class.name.of.BarImpl</value>
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk </oneOrMore>
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk </attribute>
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk If we find a child object inside an attribute
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk (that's why we are in this method BTW),
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk we generate a class name (with a special marker \u0000).
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // put a class name with a special marker \u0000. This char is an invalid
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // XML char, so sensible datatypes should reject this (although many
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // datatype implementations will accept it in actuality)
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk text("\u0000"+vo.getPrimaryInterface().getName(),fieldName);
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // validate a child object
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk public void reportError( ValidationEvent e ) throws AbortSerializationException {
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk// ID/IDREF validation
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk public String onID( IdentifiableObject owner, String value ) throws SAXException {
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk public String onIDREF( IdentifiableObject value ) throws SAXException {
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk return context.onIDREF(target,value.____jaxb____getId());
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk// ValidationContext implementation. Used by MSV to obtain
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk// contextual information related to validation.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk public boolean isUnparsedEntity( String entityName ) {
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // abandon the validation of ENTITY type.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk return true;
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // abandon the validation of NOTATION type.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk return true;
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk public void onID( Datatype dt, StringToken s ) {
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // ID/IDREF validation will be done by ourselves.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // so we will not rely on the validator to perform this check.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // because we will use multiple instances of validators, so
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // they cannot check global consistency.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk // see onID/onIDREF of the ValidationContext.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk public String resolveNamespacePrefix( String prefix ) {