Package org.audiveris.proxymusic.util
Class Marshalling
java.lang.Object
org.audiveris.proxymusic.util.Marshalling
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classGlobal exception for formatting.static classGlobal exception for marshalling.static classGlobal exception for un-marshalling. -
Method Summary
Modifier and TypeMethodDescriptionstatic javax.xml.bind.JAXBContextgetContext(Class classe) Get access to (and elaborate if not yet done) the needed JAXB context.static voidmarshal(Opus opus, OutputStream os) Marshal the provided Opus instance to an OutputStream.static voidmarshal(ScorePartwise scorePartwise, OutputStream os, boolean injectSignature, Integer indentation) Marshal the provided ScorePartwise instance to an OutputStream.static voidmarshal(ScorePartwise scorePartwise, Node node, boolean injectSignature) Marshal the provided ScorePartwise instance directly to a DOM node.static Objectunmarshal(InputStream is) Un-marshal a ScorePartwise instance or an Opus instance from an InputStream.
-
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 elementos- the output stream (not closed by this method)injectSignature- false if ProxyMusic encoder must not be referencedindentation- 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
Marshal the provided Opus instance to an OutputStream.- Parameters:
opus- the root opus elementos- 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 elementnode- the DOM node where elements must be addedinjectSignature- false if ProxyMusic encoder must not be referenced- Throws:
Marshalling.MarshallingException- global exception (use getCause() for original exception)
-
unmarshal
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)
-