-package jalview.datamodel.xdb.embl;\r
-\r
-\r
-import java.io.File;\r
-import java.io.FileReader;\r
-import java.io.Reader;\r
-import java.util.Vector;\r
-\r
-import org.exolab.castor.mapping.Mapping;\r
-import org.exolab.castor.xml.Unmarshaller;\r
-\r
-public class EmblFile {\r
- Vector entries;\r
- Vector errors;\r
- /**\r
- * @return the entries\r
- */\r
- public Vector getEntries() {\r
- return entries;\r
- }\r
- /**\r
- * @param entries the entries to set\r
- */\r
- public void setEntries(Vector entries) {\r
- this.entries = entries;\r
- }\r
- /**\r
- * @return the errors\r
- */\r
- public Vector getErrors() {\r
- return errors;\r
- }\r
- /**\r
- * @param errors the errors to set\r
- */\r
- public void setErrors(Vector errors) {\r
- this.errors = errors;\r
- }\r
- /**\r
- * Parse an EmblXML file into an EmblFile object\r
- * @param file\r
- * @return parsed EmblXML or null if exceptions were raised\r
- */\r
- public static EmblFile getEmblFile(File file)\r
- {\r
- if (file==null)\r
- return null;\r
- try {\r
- return EmblFile.getEmblFile(new FileReader(file));\r
- }\r
- catch (Exception e) {\r
- System.err.println("Exception whilst reading EMBLfile from "+file);\r
- e.printStackTrace(System.err);\r
- }\r
- return null;\r
- }\r
- public static EmblFile getEmblFile(Reader file) {\r
- EmblFile record = new EmblFile();\r
- try\r
- {\r
- // 1. Load the mapping information from the file\r
- Mapping map = new Mapping(record.getClass().getClassLoader());\r
- java.net.URL url = record.getClass().getResource("/embl_mapping.xml");\r
- map.loadMapping(url);\r
-\r
- // 2. Unmarshal the data\r
- Unmarshaller unmar = new Unmarshaller(record);\r
- try {\r
- // uncomment to DEBUG EMBLFile reading unmar.setDebug(jalview.bin.Cache.log.isDebugEnabled());\r
- } catch (Exception e) {};\r
- unmar.setIgnoreExtraElements(true);\r
- unmar.setMapping(map);\r
-\r
- record = (EmblFile) unmar.unmarshal(file);\r
- }\r
- catch (Exception e)\r
- {\r
- e.printStackTrace(System.err);\r
- record=null;\r
- }\r
-\r
-\r
- return record;\r
- }\r
- public static void main(String args[]) {\r
- EmblFile myfile = EmblFile.getEmblFile(new File("C:\\Documents and Settings\\JimP\\workspace-3.2\\Jalview Release\\schemas\\embleRecord.xml"));\r
- if (myfile!=null && myfile.entries!=null && myfile.entries.size()>0)\r
- System.out.println(myfile.entries.size()+" Records read.");\r
- }\r
-}\r
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9.0b1)
+ * Copyright (C) 2015 The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.datamodel.xdb.embl;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.PrintWriter;
+import java.io.Reader;
+import java.util.Vector;
+
+import org.exolab.castor.mapping.Mapping;
+import org.exolab.castor.xml.Unmarshaller;
+
+/**
+ * Data model for entries returned from an EMBL query, as marshalled by a Castor
+ * binding file
+ *
+ * For example: http://www.ebi.ac.uk/Tools/dbfetch/dbfetch/embl/x53828/emblxml
+ *
+ * @see embl_mapping.xml
+ */
+public class EmblFile
+{
+ Vector<EmblEntry> entries;
+
+ Vector<EmblError> errors;
+
+ /**
+ * @return the entries
+ */
+ public Vector<EmblEntry> getEntries()
+ {
+ return entries;
+ }
+
+ /**
+ * @param entries
+ * the entries to set
+ */
+ public void setEntries(Vector<EmblEntry> entries)
+ {
+ this.entries = entries;
+ }
+
+ /**
+ * @return the errors
+ */
+ public Vector<EmblError> getErrors()
+ {
+ return errors;
+ }
+
+ /**
+ * @param errors
+ * the errors to set
+ */
+ public void setErrors(Vector<EmblError> errors)
+ {
+ this.errors = errors;
+ }
+
+ /**
+ * Parse an EmblXML file into an EmblFile object
+ *
+ * @param file
+ * @return parsed EmblXML or null if exceptions were raised
+ */
+ public static EmblFile getEmblFile(File file)
+ {
+ if (file == null)
+ {
+ return null;
+ }
+ try
+ {
+ return EmblFile.getEmblFile(new FileReader(file));
+ } catch (Exception e)
+ {
+ System.err.println("Exception whilst reading EMBLfile from " + file);
+ e.printStackTrace(System.err);
+ }
+ return null;
+ }
+
+ public static EmblFile getEmblFile(Reader file)
+ {
+ EmblFile record = new EmblFile();
+ try
+ {
+ // 1. Load the mapping information from the file
+ Mapping map = new Mapping(record.getClass().getClassLoader());
+
+ java.net.URL url = record.getClass().getResource("/embl_mapping.xml");
+ map.loadMapping(url);
+
+ // 2. Unmarshal the data
+ Unmarshaller unmar = new Unmarshaller(record);
+ try
+ {
+ // uncomment to DEBUG EMBLFile reading
+ if (jalview.bin.Cache.getDefault(jalview.bin.Cache.CASTORLOGLEVEL,
+ "debug").equalsIgnoreCase("DEBUG"))
+ {
+ unmar.setDebug(jalview.bin.Cache.log.isDebugEnabled());
+ }
+ } catch (Exception e)
+ {
+ }
+ unmar.setIgnoreExtraElements(true);
+ unmar.setIgnoreExtraAttributes(true);
+ unmar.setMapping(map);
+ unmar.setLogWriter(new PrintWriter(System.out));
+ record = (EmblFile) unmar.unmarshal(file);
+ } catch (Exception e)
+ {
+ e.printStackTrace(System.err);
+ record = null;
+ }
+
+ return record;
+ }
+}