diff --git a/ivy.xml b/ivy.xml
index 26b4130be..c2e06aa46 100644
--- a/ivy.xml
+++ b/ivy.xml
@@ -12,7 +12,5 @@
-
-
diff --git a/java/src/org/broadinstitute/sting/playground/samples/SampleXmlMarshaller.java b/java/src/org/broadinstitute/sting/playground/samples/SampleXmlMarshaller.java
index dfd4b0a3c..b3c302af9 100755
--- a/java/src/org/broadinstitute/sting/playground/samples/SampleXmlMarshaller.java
+++ b/java/src/org/broadinstitute/sting/playground/samples/SampleXmlMarshaller.java
@@ -1,12 +1,13 @@
package org.broadinstitute.sting.playground.samples;
-import org.exolab.castor.xml.*;
import org.apache.log4j.BasicConfigurator;
+import org.broadinstitute.sting.utils.StingException;
+import org.simpleframework.xml.Element;
+import org.simpleframework.xml.Root;
+import org.simpleframework.xml.Serializer;
+import org.simpleframework.xml.core.Persister;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.FileReader;
-import java.io.FileNotFoundException;
+import java.io.File;
/**
* Created by IntelliJ IDEA.
@@ -15,11 +16,18 @@ import java.io.FileNotFoundException;
* Time: 2:16:43 PM
* To change this template use File | Settings | File Templates.
*/
+
+@Root // this is a root output object for simpleXML
public class SampleXmlMarshaller {
public enum RMDType { HapMap };
+ @Element // simpleXML tag to say make it an element, you could also specifiy Attribute
private RMDType type;
+
+ @Element
private String fileVersion;
+
+ @Element
private String fileName;
public SampleXmlMarshaller() {
@@ -59,55 +67,59 @@ public class SampleXmlMarshaller {
return String.format("Type = %s, Name = %s, Version = %s%n", type, fileName, fileVersion );
}
- public static void main( String argv[] ) {
- if( argv.length == 0 || (!argv[0].equalsIgnoreCase("marshal") && !argv[0].equalsIgnoreCase("unmarshal")) ) {
- System.out.println( "USAGE: java org.broadinstitute.sting.playground.samples.SampleXmlMarshaller {marshal | unmarshal}");
- System.exit(-1);
+ public boolean equals(SampleXmlMarshaller other) {
+ if (other == null) { return false; }
+ if (other.getType() == this.getType() &&
+ other.getFileVersion().equals(this.getFileVersion()) &&
+ other.getFileName().equals(this.getFileName())) {
+ return true;
}
+ return false;
+ }
+
+ public static void main( String argv[] ) {
+ if (argv.length != 1) {
+ System.err.println("You must specify a filename for the XML output.");
+ System.err.println("\nUsage: SampleXmlMarshaller outputfile\n");
+ }
+ // our SampleXmlMarshallers
+ SampleXmlMarshaller startWith = new SampleXmlMarshaller(RMDType.HapMap, "testFile.xml", "0.1");
+ SampleXmlMarshaller endWith = null;
+
+ // where to read and write to
+ String writeTo = argv[0];
BasicConfigurator.configure();
- if( argv[0].equalsIgnoreCase("marshal") )
- marshal();
- else if( argv[0].equalsIgnoreCase("unmarshal") )
- unmarshal();
+ marshal(startWith, writeTo);
+ endWith = unmarshal(writeTo);
+
+ if (startWith.equals(endWith)) {
+ System.out.println("they're equal, check " + writeTo.toString() + " for the output");
+ } else {
+ System.out.println("they're NOT equal, check " + writeTo.toString() + " for the output. Something must of gone wrong");
+ }
+
}
- public static void marshal() {
- SampleXmlMarshaller descriptor = new SampleXmlMarshaller( RMDType.HapMap, "foo.hapmap", "1.0" );
- System.out.printf( "Marshalling descriptor = %s%n", descriptor );
+ public static void marshal(SampleXmlMarshaller sample, String filename) {
+ Serializer serializer = new Persister();
+ File out = new File(filename);
try {
- FileWriter writer = new FileWriter( "foo.xml" );
- Marshaller.marshal( descriptor, writer );
- }
- catch( IOException ex ) {
- System.out.println("Unable to open writer:" + ex);
- }
- catch( MarshalException ex ) {
- System.out.println("Unable to marshal data:" + ex);
- }
- catch( ValidationException ex ) {
- System.out.println("Unable to validate data: " + ex);
+ serializer.write(sample, out);
+ } catch (Exception e) {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
- public static void unmarshal() {
- SampleXmlMarshaller descriptor = null;
+ public static SampleXmlMarshaller unmarshal(String filename) {
+ Serializer serializer = new Persister();
+ File source = new File(filename);
try {
- FileReader reader = new FileReader( "foo.xml" );
- descriptor = (SampleXmlMarshaller)Unmarshaller.unmarshal( SampleXmlMarshaller.class, reader );
+ SampleXmlMarshaller example = serializer.read(SampleXmlMarshaller.class, source);
+ return example;
+ } catch (Exception e) {
+ throw new StingException("Failed to marshal the data to file " + filename,e);
}
- catch( FileNotFoundException ex ) {
- System.out.println("Unable to open reader:" + ex);
- }
- catch( MarshalException ex ) {
- System.out.println("Unable to unmarshal data:" + ex);
- }
- catch( ValidationException ex ) {
- System.out.println("Unable to validate data: " + ex);
- }
-
- System.out.printf( "Unmarshalled descriptor = %s%n", descriptor );
-
}
}