Add xmlToMovies function to XmlHelper
This commit is contained in:
parent
b73bed091d
commit
03320279b9
@ -1,7 +1,7 @@
|
|||||||
package at.technikumwien.movies;
|
package at.technikumwien.movies;
|
||||||
|
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.*;
|
||||||
import javax.xml.bind.Marshaller;
|
import javax.xml.transform.stream.StreamSource;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -17,4 +17,18 @@ public class XmlHelper {
|
|||||||
marshaller.marshal(movies, System.out);
|
marshaller.marshal(movies, System.out);
|
||||||
marshaller.marshal(movies, new File(filename));
|
marshaller.marshal(movies, new File(filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<Movies> xmlToMovies(String filename) throws JAXBException {
|
||||||
|
JAXBContext jaxbContext = JAXBContext.newInstance(MovieList.class);
|
||||||
|
|
||||||
|
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
|
||||||
|
|
||||||
|
StreamSource streamSource = new StreamSource(new File(filename));
|
||||||
|
JAXBElement jaxElement = unmarshaller.unmarshal(streamSource, MovieList.class);
|
||||||
|
|
||||||
|
// TODO: Cast here shouldn't be necessary?
|
||||||
|
MovieList movieList = (MovieList) jaxElement.getValue();
|
||||||
|
|
||||||
|
return movieList.movies;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user