Add two more gases.
[dive.git] / src / net / ametros / dive / parser / XMLParser.java
blob7a7a0673a1c6a37feb02f3bda58632d484e312b2
1 /* Ametros Dive Computer
2 * Copyright (C) 2010 Geoff Johnstone
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.ametros.dive.parser;
20 import net.ametros.dive.data.Dives;
22 import java.io.File;
23 import javax.xml.XMLConstants;
24 import javax.xml.bind.JAXBContext;
25 import javax.xml.bind.Unmarshaller;
26 import javax.xml.validation.Schema;
27 import javax.xml.validation.SchemaFactory;
30 /** Parser for ADC XML dive plans. */
31 public class XMLParser implements Parser
33 private static final SchemaFactory sf =
34 SchemaFactory.newInstance (XMLConstants.W3C_XML_SCHEMA_NS_URI);
36 private final Schema schema;
37 private final JAXBContext jc;
40 public XMLParser() throws Exception
42 schema = sf.newSchema (Dives.class.getResource ("/dives.xsd"));
43 jc = JAXBContext.newInstance ("net.ametros.dive.data");
47 public Dives parse (File file) throws Exception
49 final Unmarshaller u = jc.createUnmarshaller();
50 u.setSchema (schema);
52 return (Dives)u.unmarshal (file);