package com.tutego.insel.xml.jaxb;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;

public class ClubMarshaller
{
  public static void main( String[] args ) throws Exception
  {
    DJ dj = new DJ();
    dj.setDjName( "John Peel" );
    
    Club club = new Club();
    club.setDj( dj );
    club.setNumberOfPersons( 1234 );

    JAXBContext context = JAXBContext.newInstance( Club.class );//, DJ.class );
    Marshaller m = context.createMarshaller();
    m.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE );
    m.marshal( club, System.out );

//    Writer w = null;
//    try
//    {
//      w = new FileWriter( "club-jaxb.xml" );
//      m.marshal( club, w );
//    }
//    finally
//    {
//      try { w.close(); } catch ( Exception e ) { } 
//    }

    // Unmarshaller um = context.createUnmarshaller();
    // Club club2 = (Club) um.unmarshal( new FileReader( "club-jaxb.xml" ) );
    // System.out.println( club2.getDj().getName() );
    // System.out.println( club2.getNumberOfPersons() );
  }
}
