2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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.Reader;
26 import java.util.Vector;
28 import org.exolab.castor.mapping.Mapping;
29 import org.exolab.castor.xml.Unmarshaller;
40 public Vector getEntries()
49 public void setEntries(Vector entries)
51 this.entries = entries;
57 public Vector getErrors()
66 public void setErrors(Vector errors)
72 * Parse an EmblXML file into an EmblFile object
75 * @return parsed EmblXML or null if exceptions were raised
77 public static EmblFile getEmblFile(File file)
83 return EmblFile.getEmblFile(new FileReader(file));
86 System.err.println("Exception whilst reading EMBLfile from " + file);
87 e.printStackTrace(System.err);
92 public static EmblFile getEmblFile(Reader file)
94 EmblFile record = new EmblFile();
97 // 1. Load the mapping information from the file
98 Mapping map = new Mapping(record.getClass().getClassLoader());
99 java.net.URL url = record.getClass().getResource("/embl_mapping.xml");
100 map.loadMapping(url);
102 // 2. Unmarshal the data
103 Unmarshaller unmar = new Unmarshaller(record);
106 // uncomment to DEBUG EMBLFile reading
107 if (((String) jalview.bin.Cache.getDefault(
108 jalview.bin.Cache.CASTORLOGLEVEL, "debug"))
109 .equalsIgnoreCase("DEBUG"))
110 unmar.setDebug(jalview.bin.Cache.log.isDebugEnabled());
111 } catch (Exception e)
115 unmar.setIgnoreExtraElements(true);
116 unmar.setMapping(map);
118 record = (EmblFile) unmar.unmarshal(file);
119 } catch (Exception e)
121 e.printStackTrace(System.err);
128 public static void main(String args[])
131 if (args.length == 1)
133 mf = new File(args[0]);
138 "C:\\Documents and Settings\\JimP\\workspace-3.2\\Jalview Release\\schemas\\embleRecordV1.1.xml");
140 EmblFile myfile = EmblFile.getEmblFile(mf);
141 if (myfile != null && myfile.entries != null
142 && myfile.entries.size() > 0)
143 System.out.println(myfile.entries.size() + " Records read. (" + mf