Harvard University Library - Library Digital Initiative
  Home 
  METS 
  JAXB 
  Toolkit 
  Procedural Construction 
  Validation 
  Marshalling / Unmarshalling 
  Implementation 
  Papers and Presentations 
 
  Printer-Friendly Version of Site 

  Harvard University Library 
 
  Office for Information Systems 
 
  Library Digital Initiative 

METS Java Toolkit / The Toolkit
Draft Version 1.0 (alpha) 2002/03/15

The METS toolkit consists of an implementation of the javax.xml.bind and javax.xml.marshal packages (org.mets.xml.bind and org.mets.xml.marshal, respectively) and the METS API package org.mets.xml.mets following the JAXB binding framework API for schema-derived classes.

In general, each element defined in the METS schema maps to a public class:

public class Element
{
  public Element ();
  ...
}

with public type-specific accessor and mutator methods for all element attributes:

public type getAttr ();      // Scalar-valued attribute
public void setAttr (type value);

public List getAttr  ();     // List-valued attribute
public void List.add (type value);
...

and content model:

public List getContent ();
public void List.add   (Element content);
...

List-valued attributes are represented as ordered lists of objects stored in an ArrayList object, which implements the List interface. Thus, to add a value to list-valued attribute, first retrieve the list and then use one of the standard List mutator methods to add the child to the list:

Element element = new Element ();
...
List list = element.getAttr ();
list.add (type value);

Similarly, child elements are represented in the content model as an ordered list of objects. To add a repeatable child element to its parent's content model, first retrieve the list and then use one of the standard mutator methods to add the child to the list:

Parent parent = new Parent ();
...
Child child = new Child ();  // Instantiate child element
List list = parent.getContent (); // Parent content model
list.add (child);            // Add child to content model

The Mets class encapsulating the root <mets> element provides public methods for validation:

public void validate ();

and marshalling to and from instance documents:

public void marshal   (OutputStream os);
public void unmarshal (InputStream  in);

To encapsulate arbitrary metadata elements, possibly namespace-qualified, defined external to the METS specification, the toolkit provides a generic element class:

public class Any
{
  public Any (String name);
  public Any (String namespace, String name);

  public String getNamespace ();
  public String getName  ();
  public String getQName ();
  ...
}

with a public accessor and mutator methods for ID attributes:

public String getID ();
public void   setID (String id);

a public list-valued accessor method for all other attributes:

public List getAttributes ();
public void List.add (Object value);
...

and a public list-valued accessor method for its content model:

public List getContent ();
public void List.add (Element content);
...

A generic attribute class is provided to support type-indendent manipulation of attributes, possibly namespace-qualified:

public class Attribute
{
  public Attribute (String name, Object value);
  public Attribute (String namespace, String name,
                    Object value);
  public String getNamespace ();
  public String getName  ();
  public String getQName ();
  public Object getValue ();
}

Note that the generic element class does not perform any local validation on its attributes or content; global validation is performed for ID uniqueness.

The toolkit explicitly defines the default namespace to be the METS namespace, http://www.loc.gov/METS/.

The XMLScanner class used for unmarshalling is built using the token-level interface of XP.


Stephen Abrams
Harvard University Library, Office for Information Systems
1280 Massachusetts Avenue, Suite 404
Cambridge, MA 02138
stephen_abrams@harvard.edu
Copyright © 2002 by the President and Fellows of Harvard College.
This information about the METS Java Toolkit is provided for evaluation purposes only.

The METS specification was developed as an initiative of the Digital Library Federation and is maintained by the Network Development and MARC Standards Office of the Library of Congress.
The toolkit is compliant with the JAXB API specification, copyright © 2001 Sun Microsystems, Inc.
The toolkit uses the XP parser, copyright © 1997,1998 James Clark.