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