be.ac.ulg.montefiore.run.totem.util.jaxb.runtime
Class MSVValidator

java.lang.Object
  extended by be.ac.ulg.montefiore.run.totem.util.jaxb.runtime.MSVValidator
All Implemented Interfaces:
XMLSerializer, com.sun.msv.grammar.IDContextProvider2, org.relaxng.datatype.ValidationContext

public class MSVValidator
extends java.lang.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 Summary
static java.lang.String DUMMY_ELEMENT_NS
          namespace URI of dummy elements.
 
Method Summary
 void childAsAttributes(com.sun.xml.bind.JAXBObject o, java.lang.String fieldName)
          This method is called when an JAXBObject object is found while the marshaller is in the "attribute" mode (i.e.
 void childAsBody(com.sun.xml.bind.JAXBObject o, java.lang.String fieldName)
          This method is called when an JAXBObject object is found while the marshaller is in the "element" mode (i.e.
 void childAsURIs(com.sun.xml.bind.JAXBObject o, java.lang.String fieldName)
          This method is called when an JAXBObject object is found while the marshaller is in the "URI" mode.
 void endAttribute()
           
 void endAttributes()
          Switches to the mode to marshal child texts/elements.
 void endElement()
          Ends marshalling of an element.
 void endNamespaceDecls()
          Switches to the mode to marshal attribute values.
 java.lang.String getBaseUri()
           
 NamespaceContext2 getNamespaceContext()
          Obtains a namespace context object, which is used to declare/obtain namespace bindings.
 boolean isNotation(java.lang.String notation)
           
 boolean isUnparsedEntity(java.lang.String entityName)
           
 void onID(org.relaxng.datatype.Datatype dt, com.sun.msv.verifier.regexp.StringToken s)
           
 java.lang.String onID(com.sun.xml.bind.marshaller.IdentifiableObject owner, java.lang.String value)
          Notifies the serializer that an ID value has just marshalled.
 java.lang.String onIDREF(com.sun.xml.bind.marshaller.IdentifiableObject value)
          Notifies the serializer that an IDREF value has just marshalled.
 void reportError(javax.xml.bind.ValidationEvent e)
          Errors detected by the XMLSerializable should be either thrown as SAXException or reported through this method.
 void reportMissingObjectError(java.lang.String fieldName)
           
 java.lang.String resolveNamespacePrefix(java.lang.String prefix)
           
 void startAttribute(java.lang.String uri, java.lang.String local)
          Starts marshalling of an attribute.
 void startElement(java.lang.String uri, java.lang.String local)
          Starts marshalling of an element.
 void text(java.lang.String text, java.lang.String fieldName)
          Marshalls text.
static void validate(DefaultJAXBContextImpl jaxbCtx, be.ac.ulg.montefiore.run.totem.util.jaxb.runtime.ValidationContext context, ValidatableObject vo)
          Validates the specified object and reports any error to the context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DUMMY_ELEMENT_NS

public static final java.lang.String DUMMY_ELEMENT_NS
namespace URI of dummy elements. TODO: allocate one namespace URI for this.

See Also:
Constant Field Values
Method Detail

getNamespaceContext

public NamespaceContext2 getNamespaceContext()
Description copied from interface: XMLSerializer
Obtains a namespace context object, which is used to declare/obtain namespace bindings.

Specified by:
getNamespaceContext in interface XMLSerializer

validate

public static void validate(DefaultJAXBContextImpl jaxbCtx,
                            be.ac.ulg.montefiore.run.totem.util.jaxb.runtime.ValidationContext context,
                            ValidatableObject vo)
                     throws org.xml.sax.SAXException
Validates the specified object and reports any error to the context.

Throws:
org.xml.sax.SAXException

endNamespaceDecls

public void endNamespaceDecls()
                       throws org.xml.sax.SAXException
Description copied from interface: XMLSerializer
Switches to the mode to marshal attribute values. This method has to be called after the 1st pass is completed.

Specified by:
endNamespaceDecls in interface XMLSerializer
Throws:
org.xml.sax.SAXException

endAttributes

public void endAttributes()
                   throws org.xml.sax.SAXException
Description copied from interface: XMLSerializer
Switches to the mode to marshal child texts/elements. This method has to be called after the 2nd pass is completed.

Specified by:
endAttributes in interface XMLSerializer
Throws:
org.xml.sax.SAXException

text

public final void text(java.lang.String text,
                       java.lang.String fieldName)
                throws org.xml.sax.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:
org.xml.sax.SAXException

reportMissingObjectError

public void reportMissingObjectError(java.lang.String fieldName)
                              throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

startAttribute

public void startAttribute(java.lang.String uri,
                           java.lang.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

endAttribute

public void endAttribute()
                  throws org.xml.sax.SAXException
Specified by:
endAttribute in interface XMLSerializer
Throws:
org.xml.sax.SAXException

startElement

public void startElement(java.lang.String uri,
                         java.lang.String local)
                  throws org.xml.sax.SAXException
Description copied from interface: XMLSerializer
Starts marshalling of an element. Calling this method will push the internal state into the internal stack.

Specified by:
startElement in interface XMLSerializer
Throws:
org.xml.sax.SAXException

endElement

public void endElement()
                throws org.xml.sax.SAXException
Description copied from interface: XMLSerializer
Ends marshalling of an element. Pops the internal stack.

Specified by:
endElement in interface XMLSerializer
Throws:
org.xml.sax.SAXException

childAsAttributes

public void childAsAttributes(com.sun.xml.bind.JAXBObject o,
                              java.lang.String fieldName)
                       throws org.xml.sax.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:
org.xml.sax.SAXException

childAsURIs

public void childAsURIs(com.sun.xml.bind.JAXBObject o,
                        java.lang.String fieldName)
                 throws org.xml.sax.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:
org.xml.sax.SAXException

childAsBody

public void childAsBody(com.sun.xml.bind.JAXBObject o,
                        java.lang.String fieldName)
                 throws org.xml.sax.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:
org.xml.sax.SAXException

reportError

public void reportError(javax.xml.bind.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 java.lang.String onID(com.sun.xml.bind.marshaller.IdentifiableObject owner,
                             java.lang.String value)
                      throws org.xml.sax.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:
org.xml.sax.SAXException

onIDREF

public java.lang.String onIDREF(com.sun.xml.bind.marshaller.IdentifiableObject value)
                         throws org.xml.sax.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:
org.xml.sax.SAXException

getBaseUri

public java.lang.String getBaseUri()
Specified by:
getBaseUri in interface org.relaxng.datatype.ValidationContext

isUnparsedEntity

public boolean isUnparsedEntity(java.lang.String entityName)
Specified by:
isUnparsedEntity in interface org.relaxng.datatype.ValidationContext

isNotation

public boolean isNotation(java.lang.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 java.lang.String resolveNamespacePrefix(java.lang.String prefix)
Specified by:
resolveNamespacePrefix in interface org.relaxng.datatype.ValidationContext


Copyright © 2004-2007 Research Unit in Networking, All Rights Reserved.