예제 #1
0
  /** {@inheritDoc} */
  @Override
  public SBOLDocument read(InputStream in) throws IOException, SBOLValidationException {
    try {
      Unmarshaller unmarshaller = JAXB.CONTEXT.createUnmarshaller();

      if (validate) {
        unmarshaller.setSchema(JAXB.SCHEMA);
      }

      SBOLDocument doc = (SBOLDocument) unmarshaller.unmarshal(in);

      doc.accept(new PrecedeReferenceFinder());
      doc.accept(new DuplicateRemover());

      if (validate) {
        new SBOLValidatorImpl().validateWithoutSchema(doc);
      }

      return doc;
    } catch (SBOLValidationException e) {
      throw e;
    } catch (UnmarshalException e) {
      if (e.getLinkedException() != null) {
        throw new SBOLValidationException(e.getLinkedException());
      } else {
        throw new SBOLValidationException(e);
      }
    } catch (Exception e) {
      throw new IOException(e);
    }
  }
예제 #2
0
  public static void main(String[] args) throws Exception {
    System.out.format("Create a very simple SBOL document%n%n");
    // create a DnaComponent and set some of its properties
    DnaComponent dnaComponent = SBOLFactory.createDnaComponent();
    dnaComponent.setURI(URI.create("http://example.com/MyDnaComponent"));
    dnaComponent.setDisplayId("MyDnaComponent");
    dnaComponent.setName("myDNA");
    dnaComponent.setDescription("This is a very simple example");

    // create an empty document populated with some SBOL objects
    SBOLDocument document = SBOLFactory.createDocument();
    // add the DnaComponent to this document
    document.addContent(dnaComponent);

    // write the contents of the document as an XML file to stdout
    System.out.format("Serialize the SBOL document in the official XML format:%n");
    SBOLFactory.write(document, System.out);

    // now serialize the contents into a buffer so we can read it back
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    SBOLFactory.write(document, buffer);
    // create a new document using the byte buffer as our input
    SBOLDocument newDocument = SBOLFactory.read(new ByteArrayInputStream(buffer.toByteArray()));

    // write the contents of the new document in amore human-readable format
    System.out.format("%nSerialize the SBOL document in a more readable presentation format:%n");
    new SBOLPrettyWriter().write(newDocument, System.out);
  }
예제 #3
0
 //	public static URI getTypeBySubpartType(subpart_type type)
 //	{
 //		switch(type)
 //		{
 //			case Terminator:return SequenceOntology.TERMINATOR;
 //			case Primers:return SequenceOntology.PRIMER_BINDING_SITE;
 //		}
 //		return SequenceOntology.CDS;
 //	}
 public xmlToSbol(String xml, String sbol) throws IOException {
   SBOLDocument document = createDocument(xml);
   System.out.println(
       "Created a new SBOL document with " + document.getContents().size() + " element(s)");
   FileOutputStream fileoutStream = new FileOutputStream(sbol);
   SBOLFactory.write(document, fileoutStream);
   fileoutStream.close();
 }
예제 #4
0
 /** Creates a document with a single DnaComponent. */
 public SBOLDocument createDocument(String xml) {
   SBOLDocument document = SBOLFactory.createDocument();
   document.addContent(createDnaComponent(xml, document));
   return document;
 }
예제 #5
0
 @Override
 public void visit(SBOLDocument doc) {
   super.visit(doc);
   removeDuplicates(doc.getContents());
 }