The Java bean object model
A Java bean is a class consisting of a zero-argument constructor and zero or more data members (attributes). Each attribute has an accompanying pair of get and set methods to manipulate attribute values.
The consistent form of a Java bean allows it to be used by a framework which expects bean classes to be in a predictable form. The framework used in the tasks application is the Hibernate object-relational mapping tool.
Mapping from schema to bean
Each tasks application Java bean is a mapping of some part of the MusicXML schema.
Once the schema has been mapped to Java beans, each bean entity then maps to a database table, and the bean attributes map to columns in the table using Hibernate annotations.
The process of mapping a schema to a Java objects here is a standard one.
In general, these mappings are:
Bean examples
measure and music-data
The measure element in the MusicXML schema is defined as:
The measure element maps to a Measure bean, and the attributeGroup measure-attributes map to a collection of bean attributes.
The Measure bean is thus defined as follows:
The music-data group referenced within the measure element definition is defined as a list of a choice subelements of the measure element.
The choice construct itself is an abstract superclass, while the individual elements within the choice are each concrete subclasses of the abstract class.
The MusicData class represents the choice element:
The note element (to take an example) is one of the choice options, and maps to the Note subclass [class MusicDataElement is a subclass of MusicData that includes optional-unique-id]:
metronome
A less straightforward example of a mapping of a choice is the metronome complexType.
When a choice has an unnamed sequence, I map the sequence to a bean subclass using a name that I feel represents the sequence.
The metronome complexType is defined as follows:
The Metronome abstract class is the mapping of the metronome complexType as a whole:
The Java beans BeatMetronome and NoteMetronome are concrete subclasses of Metronome, where each bean type is a mapping of one of the sequence elements in the choice.
The NoteMetronome bean is the mapping of the second sequence:
The BeatMetronome bean is the mapping of the first sequence, reproduced below:
The choice section within the sequence is mapped as abstract class MetronomeMark, with two concrete subclasses PerMinute and BeatUnit; BeatUnit represents the beat-unit/beat-unit-tied sequence.
The BeatMetronome sequence as a whole is then mapped as two MetronomeMark attributes: