FileDocCategorySizeDatePackage
ValidationTest2.javaAPI DocExample1384Sun Jul 07 09:50:12 BST 2002javajaxb

ValidationTest2.java

package javajaxb;

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

// Generated Classes
import javajaxb.generated.movies.*;

public class ValidationTest2 {

    public static void main(String[] args) {
        if (args.length != 1) {
            System.out.println("Usage: java javajaxb.ValidationTest2 " +
                "[XML movie database filename]");
            return;
        }

        try {
            File xmlFile = new File(args[0]);
            FileInputStream inputStream = new FileInputStream(xmlFile);

            // Read in movies database
            Movies movies = Movies.unmarshal(inputStream);

            /* ******* SETTING INVALID DATA *********** */
            List movieList = movies.getMovie();
            Movie movie = (Movie)movieList.get(0);
            Cast cast = movie.getCast();
            List actorList = cast.getActor();
            Actor actor = (Actor)actorList.get(0);
            actor.setHeadliner("illegalValue");

            // Create output stream
            File file = new File("output.xml");
            FileOutputStream outputStream = new FileOutputStream(file);

            // Marshal back out
            movies.marshal(outputStream);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}