/* 
   usage : java generated/CreateList fileName
*/
package generated;

import java.util.List;
import java.io.FileOutputStream;

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

public class CreateList {

	public static void main (String[] args) throws Exception{
	
		String fileOut = args.length == 1 ? args[0] : "";
	
	// (1) Creating and filling in a new Studentlist object
	
		ObjectFactory of = new ObjectFactory(); 
		
		Studentlist newStudList = of.createStudentlist(); 
		
		List<Studentlist.Student> nsl =  newStudList.getStudent(); // empty
		
		// String[] names = {"Hélène", "André", "Noémie", "François"};
		String[] names = {"H\u00E9l\u00E8ne", "Andr\u00E9", "No\u00E9mie", "Fran\u00E7ois"};
		int[] marks = {12, 15, 17, 9};
		for( int i = 0; i < names.length; i++ ){
			Studentlist.Student stud = of.createStudentlistStudent();
			stud.setName (names[i]);
			stud.setMark(marks[i]);
			nsl.add(stud);
		}
		
	// (2) Serializing ("Marshalling") the Studentlist object into an XML file
	
		JAXBContext jc = JAXBContext.newInstance("generated");
      	Marshaller mrs = jc.createMarshaller();
      	mrs.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
      	if( fileOut.length() != 0 ){
      		mrs.marshal(newStudList, new FileOutputStream(fileOut));
      	}else{
      		mrs.marshal(newStudList, System.out);
      	}
		
	}//main
}// class CreateList
			