1 package jalview.datamodel.xdb.embl;
\r
5 import java.io.FileReader;
\r
6 import java.io.Reader;
\r
7 import java.util.Vector;
\r
9 import org.exolab.castor.mapping.Mapping;
\r
10 import org.exolab.castor.xml.Unmarshaller;
\r
12 public class EmblFile {
\r
16 * @return the entries
\r
18 public Vector getEntries() {
\r
22 * @param entries the entries to set
\r
24 public void setEntries(Vector entries) {
\r
25 this.entries = entries;
\r
28 * @return the errors
\r
30 public Vector getErrors() {
\r
34 * @param errors the errors to set
\r
36 public void setErrors(Vector errors) {
\r
37 this.errors = errors;
\r
40 * Parse an EmblXML file into an EmblFile object
\r
42 * @return parsed EmblXML or null if exceptions were raised
\r
44 public static EmblFile getEmblFile(File file)
\r
49 return EmblFile.getEmblFile(new FileReader(file));
\r
51 catch (Exception e) {
\r
52 System.err.println("Exception whilst reading EMBLfile from "+file);
\r
53 e.printStackTrace(System.err);
\r
57 public static EmblFile getEmblFile(Reader file) {
\r
58 EmblFile record = new EmblFile();
\r
61 // 1. Load the mapping information from the file
\r
62 Mapping map = new Mapping(record.getClass().getClassLoader());
\r
63 java.net.URL url = record.getClass().getResource("/embl_mapping.xml");
\r
64 map.loadMapping(url);
\r
66 // 2. Unmarshal the data
\r
67 Unmarshaller unmar = new Unmarshaller(record);
\r
69 // uncomment to DEBUG EMBLFile reading unmar.setDebug(jalview.bin.Cache.log.isDebugEnabled());
\r
70 } catch (Exception e) {};
\r
71 unmar.setIgnoreExtraElements(true);
\r
72 unmar.setMapping(map);
\r
74 record = (EmblFile) unmar.unmarshal(file);
\r
78 e.printStackTrace(System.err);
\r
85 public static void main(String args[]) {
\r
86 EmblFile myfile = EmblFile.getEmblFile(new File("C:\\Documents and Settings\\JimP\\workspace-3.2\\Jalview Release\\schemas\\embleRecord.xml"));
\r
87 if (myfile!=null && myfile.entries!=null && myfile.entries.size()>0)
\r
88 System.out.println(myfile.entries.size()+" Records read.");
\r