Class MSVValidator

  • All Implemented Interfaces:
    XMLSerializer, com.sun.msv.grammar.IDContextProvider2, org.relaxng.datatype.ValidationContext

    public class MSVValidator
    extends Object
    implements XMLSerializer, com.sun.msv.grammar.IDContextProvider2
    XMLSerializer that calls the native interface of MSV and performs validation. Used in a pair with a ValidationContext.
    Author:
    Kohsuke Kawaguchi
    • Field Detail

      • DUMMY_ELEMENT_NS

        public static final String DUMMY_ELEMENT_NS
        namespace URI of dummy elements. TODO: allocate one namespace URI for this.
        See Also:
        Constant Field Values
    • Method Detail

      • text

        public final void text​(String text,
                               String fieldName)
                        throws SAXException
        Description copied from interface: XMLSerializer
        Marshalls text.

        This method can be called (i) after the startAttribute method and (ii) before the endAttribute method, to marshal attribute values. If the method is called more than once, those texts are considered as separated by whitespaces. For example,

         c.startAttribute();
         c.text("abc");
         c.text("def");
         c.endAttribute("","foo");
         
        will generate foo="abc def".

        Similarly, this method can be called after the endAttributes method to marshal texts inside elements. The same rule about multiple invokations apply to this case, too. For example,

         c.startElement("","foo");
         c.endNamespaceDecls();
         c.endAttributes();
         c.text("abc");
         c.text("def");
           c.startElement("","bar");
           c.endAttributes();
           c.endElement();
         c.text("ghi");
         c.endElement();
         
        will generate <foo>abc def<bar/>ghi</foo>.
        Specified by:
        text in interface XMLSerializer
        Throws:
        SAXException
      • startAttribute

        public void startAttribute​(String uri,
                                   String local)
        Description copied from interface: XMLSerializer
        Starts marshalling of an attribute. The marshalling of an attribute will be done by
        1. call the startAttribute method
        2. call the text method (several times if necessary)
        3. call the endAttribute method
        No two attributes can be marshalled at the same time. Note that the whole attribute marshalling must be happened after the startElement method and before the endAttributes method.
        Specified by:
        startAttribute in interface XMLSerializer
      • childAsAttributes

        public void childAsAttributes​(com.sun.xml.bind.JAXBObject o,
                                      String fieldName)
                               throws SAXException
        Description copied from interface: XMLSerializer
        This method is called when an JAXBObject object is found while the marshaller is in the "attribute" mode (i.e. marshalling attributes of an element)
        Specified by:
        childAsAttributes in interface XMLSerializer
        fieldName - property name of the parent objeect from which 'o' comes. Used as a part of the error message in case anything goes wrong with 'o'.
        Throws:
        SAXException
      • childAsURIs

        public void childAsURIs​(com.sun.xml.bind.JAXBObject o,
                                String fieldName)
                         throws SAXException
        Description copied from interface: XMLSerializer
        This method is called when an JAXBObject object is found while the marshaller is in the "URI" mode.
        Specified by:
        childAsURIs in interface XMLSerializer
        fieldName - property name of the parent objeect from which 'o' comes. Used as a part of the error message in case anything goes wrong with 'o'.
        Throws:
        SAXException
      • childAsBody

        public void childAsBody​(com.sun.xml.bind.JAXBObject o,
                                String fieldName)
                         throws SAXException
        Description copied from interface: XMLSerializer
        This method is called when an JAXBObject object is found while the marshaller is in the "element" mode (i.e. marshalling a content model of an element)
        Specified by:
        childAsBody in interface XMLSerializer
        fieldName - property name of the parent objeect from which 'o' comes. Used as a part of the error message in case anything goes wrong with 'o'.
        Throws:
        SAXException
      • reportError

        public void reportError​(ValidationEvent e)
                         throws com.sun.xml.bind.serializer.AbortSerializationException
        Description copied from interface: XMLSerializer
        Errors detected by the XMLSerializable should be either thrown as SAXException or reported through this method. The callee should report an error to the client application and
        Specified by:
        reportError in interface XMLSerializer
        Throws:
        com.sun.xml.bind.serializer.AbortSerializationException
      • onID

        public String onID​(com.sun.xml.bind.marshaller.IdentifiableObject owner,
                           String value)
                    throws SAXException
        Description copied from interface: XMLSerializer
        Notifies the serializer that an ID value has just marshalled. The serializer may or may not check the consistency of ID/IDREFs and may throw a SAXException.
        Specified by:
        onID in interface XMLSerializer
        Parameters:
        owner - JAXB content object that posesses the ID.
        value - The value of the ID.
        Returns:
        Return the value parameter without any modification, so that the invocation of this method can be done transparently by a transducer.
        Throws:
        SAXException
      • onIDREF

        public String onIDREF​(com.sun.xml.bind.marshaller.IdentifiableObject value)
                       throws SAXException
        Description copied from interface: XMLSerializer
        Notifies the serializer that an IDREF value has just marshalled. The serializer may or may not check the consistency of ID/IDREFs and may throw a SAXException.
        Specified by:
        onIDREF in interface XMLSerializer
        Returns:
        Return the value parameter without any modification. so that the invocation of this method can be done transparently by a transducer.
        Throws:
        SAXException
      • getBaseUri

        public String getBaseUri()
        Specified by:
        getBaseUri in interface org.relaxng.datatype.ValidationContext
      • isUnparsedEntity

        public boolean isUnparsedEntity​(String entityName)
        Specified by:
        isUnparsedEntity in interface org.relaxng.datatype.ValidationContext
      • isNotation

        public boolean isNotation​(String notation)
        Specified by:
        isNotation in interface org.relaxng.datatype.ValidationContext
      • onID

        public void onID​(org.relaxng.datatype.Datatype dt,
                         com.sun.msv.verifier.regexp.StringToken s)
        Specified by:
        onID in interface com.sun.msv.grammar.IDContextProvider2
      • resolveNamespacePrefix

        public String resolveNamespacePrefix​(String prefix)
        Specified by:
        resolveNamespacePrefix in interface org.relaxng.datatype.ValidationContext