Class Marshalling

java.lang.Object
org.audiveris.proxymusic.util.Marshalling

public abstract class Marshalling extends Object
Class Marshalling gathers static methods to marshal and to un-marshal ScorePartwise or Opus java objects to/from an output/input stream in UTF8 encoding and using MusicXML format.

Several tricks are used to work around namespaces during marshalling and un-marshalling since MusicXML does not support them (MusicXML uses prefixed attribute names such as xlink:href, although it never binds the xlink prefix to its proper namespace URI).

No access to a DTD (local or remote) is made during the un-marshalling which ignores DTDs.

The method getContext(Class) is publicly visible so as to allow an asynchronous elaboration of the JAXB context, which can be an expensive operation because of the large number of Java classes in the ScorePartwise hierarchy.

Author:
Hervé Bitteur
  • Method Details

    • getContext

      public static javax.xml.bind.JAXBContext getContext(Class classe) throws javax.xml.bind.JAXBException
      Get access to (and elaborate if not yet done) the needed JAXB context. This method can be called any time.
      Parameters:
      classe - the desired class
      Returns:
      the ready to use JAXB context
      Throws:
      javax.xml.bind.JAXBException - if anything goes wrong
    • marshal

      public static void marshal(ScorePartwise scorePartwise, OutputStream os, boolean injectSignature, Integer indentation) throws Marshalling.MarshallingException
      Marshal the provided ScorePartwise instance to an OutputStream.
      Parameters:
      scorePartwise - the root scorePartwise element
      os - the output stream (not closed by this method)
      injectSignature - false if ProxyMusic encoder must not be referenced
      indentation - formatting indentation value, null for no formatting. When formatting, a comment line is inserted before parts and measures
      Throws:
      Marshalling.MarshallingException - global exception (use getCause() for original exception)
    • marshal

      public static void marshal(Opus opus, OutputStream os) throws Marshalling.MarshallingException
      Marshal the provided Opus instance to an OutputStream.
      Parameters:
      opus - the root opus element
      os - the output stream (not closed by this method)
      Throws:
      Marshalling.MarshallingException - global exception (use getCause() for original exception)
    • marshal

      public static void marshal(ScorePartwise scorePartwise, Node node, boolean injectSignature) throws Marshalling.MarshallingException
      Marshal the provided ScorePartwise instance directly to a DOM node.
      Parameters:
      scorePartwise - the root element
      node - the DOM node where elements must be added
      injectSignature - false if ProxyMusic encoder must not be referenced
      Throws:
      Marshalling.MarshallingException - global exception (use getCause() for original exception)
    • unmarshal

      public static Object unmarshal(InputStream is) throws Marshalling.UnmarshallingException
      Un-marshal a ScorePartwise instance or an Opus instance from an InputStream.

      Nota: The URLs of MusicXML DTD are specifically ignored by this method.

      Parameters:
      is - the input stream
      Returns:
      the root element (either Opus or ScorePartwise object)
      Throws:
      Marshalling.UnmarshallingException - global exception (use getCause() for original exception)