2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.datamodel.xdb.embl;
24 import java.io.FileReader;
25 import java.io.PrintWriter;
26 import java.io.Reader;
27 import java.util.Vector;
29 import org.exolab.castor.mapping.Mapping;
30 import org.exolab.castor.xml.Unmarshaller;
33 * Data model for entries returned from an EMBL query, as marshalled by a Castor
36 * For example: http://www.ebi.ac.uk/Tools/dbfetch/dbfetch/embl/x53828/emblxml
38 * @see embl_mapping.xml
42 Vector<EmblEntry> entries;
44 Vector<EmblError> errors;
49 public Vector<EmblEntry> getEntries()
58 public void setEntries(Vector<EmblEntry> entries)
60 this.entries = entries;
66 public Vector<EmblError> getErrors()
75 public void setErrors(Vector<EmblError> errors)
81 * Parse an EmblXML file into an EmblFile object
84 * @return parsed EmblXML or null if exceptions were raised
86 public static EmblFile getEmblFile(File file)
94 return EmblFile.getEmblFile(new FileReader(file));
97 System.err.println("Exception whilst reading EMBLfile from " + file);
98 e.printStackTrace(System.err);
103 public static EmblFile getEmblFile(Reader file)
105 EmblFile record = new EmblFile();
108 // 1. Load the mapping information from the file
109 Mapping map = new Mapping(record.getClass().getClassLoader());
111 java.net.URL url = record.getClass().getResource("/embl_mapping.xml");
112 map.loadMapping(url);
114 // 2. Unmarshal the data
115 Unmarshaller unmar = new Unmarshaller(record);
118 // uncomment to DEBUG EMBLFile reading
119 if (jalview.bin.Cache.getDefault(jalview.bin.Cache.CASTORLOGLEVEL,
120 "debug").equalsIgnoreCase("DEBUG"))
122 unmar.setDebug(jalview.bin.Cache.log.isDebugEnabled());
124 } catch (Exception e)
127 unmar.setIgnoreExtraElements(true);
128 unmar.setIgnoreExtraAttributes(true);
129 unmar.setMapping(map);
130 unmar.setLogWriter(new PrintWriter(System.out));
131 record = (EmblFile) unmar.unmarshal(file);
132 } catch (Exception e)
134 e.printStackTrace(System.err);