// Path: elmo/src/main/java/org/openprovenance/elmo/XMLLiteral.java
// public class XMLLiteral {
//     private static DocumentBuilder builder;
// 
//     private static Transformer transformer;
// 
//     private String xml;
// 
//     public XMLLiteral(String xml) {
//         this.xml = xml;
//     }
// 
//     public XMLLiteral(Document document) {
//         this.xml = serialize(document);
//     }
// 
//     public Document getDocument() {
//         return deserialize(xml);
//     }
// 
//     @Override
// 		public String toString() {
//         return xml;
//     }
// 
//     private String serialize(Document object) {
//         Source source = new DOMSource(object);
//         CharArrayWriter writer = new CharArrayWriter();
//         Result result = new StreamResult(writer);
//         try {
//             if (transformer == null) {
//                 transformer = TransformerFactory.newInstance()
//                     .newTransformer();
//             }
//             transformer.transform(source, result);
//         } catch (Exception e) {
//             throw new ElmoConversionException(e);
//         }
//         return writer.toString();
//     }
// 
//     private Document deserialize(String xml) {
//         try {
//             char[] charArray = xml.toCharArray();
//             CharArrayReader reader = new CharArrayReader(charArray);
//             try {
//                 if (builder == null) {
//                     DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
//                     dbf.setNamespaceAware(true);
//                     builder = dbf.newDocumentBuilder();
//                 }
//                 return builder.parse(new InputSource(reader));
//             } finally {
//                 reader.close();
//             }
//         } catch (Exception e) {
//             throw new ElmoConversionException(e);
//         }
//     }
// 
// }
// 
// Path: opm/src/main/java/org/openprovenance/model/Annotable.java
// public interface Annotable extends Identifiable {
//     public List<JAXBElement<? extends EmbeddedAnnotation>>  getAnnotation();
// } 
// 
// Path: opm/src/main/java/org/openprovenance/model/HasAccounts.java
// public interface HasAccounts {
//     List<AccountRef> getAccount();
// } 
// 
// Path: opm/src/main/java/org/openprovenance/model/Identifiable.java
// public interface Identifiable {
//     public void setId(String s);
//     public String getId();
// } 


import java.net.URI;
import java.util.Collection;
import java.util.Set;
import java.util.List;
import java.util.LinkedList;
import java.util.HashSet;
import java.util.Hashtable;
import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.openrdf.elmo.ElmoManager;
import org.openprovenance.elmo.XMLLiteral;
import org.openprovenance.model.Account;
import org.openprovenance.model.AccountRef;
import org.openprovenance.model.Agent;
import org.openprovenance.model.Annotable;
import org.openprovenance.model.Annotation;
import org.openprovenance.model.Artifact;
import org.openprovenance.model.EmbeddedAnnotation;
import org.openprovenance.model.HasAccounts;
import org.openprovenance.model.Identifiable;
import org.openprovenance.model.Label;
import org.openprovenance.model.OPMGraph;
import org.openprovenance.model.Process;
import org.openprovenance.model.Property;
import org.openprovenance.model.Type;
import org.openprovenance.model.Used;
import org.openprovenance.model.Value;
import org.openprovenance.model.WasControlledBy;
import org.openprovenance.model.WasDerivedFrom;
import org.openprovenance.model.WasGeneratedBy;
import org.openprovenance.model.WasTriggeredBy;
import org.openprovenance.rdf.AnnotationOrEdgeOrNode;
import org.openrdf.elmo.Entity;
        QName qname=((Entity)a).getQName();
        RdfWasTriggeredBy wtb=new RdfWasTriggeredBy(manager,qname);
        org.openprovenance.rdf.Node cause=a.getCause();
        org.openprovenance.rdf.Node effect=a.getEffect();
        wtb.setNodes(newProcessRef(processRegister.get(((Entity)cause).getQName())),
                     newProcessRef(processRegister.get(((Entity)effect).getQName())));
        addAccounts((org.openprovenance.rdf.AnnotationOrEdgeOrNode)a,wtb.getAccount());
        processAnnotations(a,wtb);
        return wtb;
    }

    public void processAnnotations(org.openprovenance.rdf.Annotable a, Annotable res) {
        for (org.openprovenance.rdf.Annotation ann: a.getAnnotations()) {
            addAnnotation(res,newEmbeddedAnnotation(ann));
        }
        for (String label: a.getLabels()) {
            super.addAnnotation(res,newLabel(label));
        }
        for (URI pname: a.getPnames()) {
            super.addAnnotation(res,newPName(pname.toString()));
        }
        for (String profile: a.getProfiles()) {
            super.addAnnotation(res,newProfile(profile));
        }
        for (URI type: a.getTypes()) {
            super.addAnnotation(res,newType(type.toString()));
        }
        if (a instanceof org.openprovenance.rdf.Artifact) {
            org.openprovenance.rdf.Artifact aa=(org.openprovenance.rdf.Artifact) a;
            for (org.openprovenance.rdf.AValue av: aa.getAvalues()) {
// Path: elmo/src/main/java/org/openprovenance/elmo/XMLLiteral.java
// public class XMLLiteral {
//     private static DocumentBuilder builder;
// 
//     private static Transformer transformer;
// 
//     private String xml;
// 
//     public XMLLiteral(String xml) {
//         this.xml = xml;
//     }
// 
//     public XMLLiteral(Document document) {
//         this.xml = serialize(document);
//     }
// 
//     public Document getDocument() {
//         return deserialize(xml);
//     }
// 
//     @Override
// 		public String toString() {
//         return xml;
//     }
// 
//     private String serialize(Document object) {
//         Source source = new DOMSource(object);
//         CharArrayWriter writer = new CharArrayWriter();
//         Result result = new StreamResult(writer);
//         try {
//             if (transformer == null) {
//                 transformer = TransformerFactory.newInstance()
//                     .newTransformer();
//             }
//             transformer.transform(source, result);
//         } catch (Exception e) {
//             throw new ElmoConversionException(e);
//         }
//         return writer.toString();
//     }
// 
//     private Document deserialize(String xml) {
//         try {
//             char[] charArray = xml.toCharArray();
//             CharArrayReader reader = new CharArrayReader(charArray);
//             try {
//                 if (builder == null) {
//                     DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
//                     dbf.setNamespaceAware(true);
//                     builder = dbf.newDocumentBuilder();
//                 }
//                 return builder.parse(new InputSource(reader));
//             } finally {
//                 reader.close();
//             }
//         } catch (Exception e) {
//             throw new ElmoConversionException(e);
//         }
//     }
// 
// }
// 
// Path: opm/src/main/java/org/openprovenance/model/Annotable.java
// public interface Annotable extends Identifiable {
//     public List<JAXBElement<? extends EmbeddedAnnotation>>  getAnnotation();
// } 
// 
// Path: opm/src/main/java/org/openprovenance/model/HasAccounts.java
// public interface HasAccounts {
//     List<AccountRef> getAccount();
// } 
// 
// Path: opm/src/main/java/org/openprovenance/model/Identifiable.java
// public interface Identifiable {
//     public void setId(String s);
//     public String getId();
// } 


// Path: elmo/src/main/java/org/openprovenance/elmo/RdfOPMFactory.java
import java.net.URI;
import java.util.Collection;
import java.util.Set;
import java.util.List;
import java.util.LinkedList;
import java.util.HashSet;
import java.util.Hashtable;
import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.openrdf.elmo.ElmoManager;
import org.openprovenance.elmo.XMLLiteral;
import org.openprovenance.model.Account;
import org.openprovenance.model.AccountRef;
import org.openprovenance.model.Agent;
import org.openprovenance.model.Annotable;
import org.openprovenance.model.Annotation;
import org.openprovenance.model.Artifact;
import org.openprovenance.model.EmbeddedAnnotation;
import org.openprovenance.model.HasAccounts;
import org.openprovenance.model.Identifiable;
import org.openprovenance.model.Label;
import org.openprovenance.model.OPMGraph;
import org.openprovenance.model.Process;
import org.openprovenance.model.Property;
import org.openprovenance.model.Type;
import org.openprovenance.model.Used;
import org.openprovenance.model.Value;
import org.openprovenance.model.WasControlledBy;
import org.openprovenance.model.WasDerivedFrom;
import org.openprovenance.model.WasGeneratedBy;
import org.openprovenance.model.WasTriggeredBy;
import org.openprovenance.rdf.AnnotationOrEdgeOrNode;
import org.openrdf.elmo.Entity;

        QName qname=((Entity)a).getQName();
        RdfWasTriggeredBy wtb=new RdfWasTriggeredBy(manager,qname);
        org.openprovenance.rdf.Node cause=a.getCause();
        org.openprovenance.rdf.Node effect=a.getEffect();
        wtb.setNodes(newProcessRef(processRegister.get(((Entity)cause).getQName())),
                     newProcessRef(processRegister.get(((Entity)effect).getQName())));
        addAccounts((org.openprovenance.rdf.AnnotationOrEdgeOrNode)a,wtb.getAccount());
        processAnnotations(a,wtb);
        return wtb;
    }

    public void processAnnotations(org.openprovenance.rdf.Annotable a, Annotable res) {
        for (org.openprovenance.rdf.Annotation ann: a.getAnnotations()) {
            addAnnotation(res,newEmbeddedAnnotation(ann));
        }
        for (String label: a.getLabels()) {
            super.addAnnotation(res,newLabel(label));
        }
        for (URI pname: a.getPnames()) {
            super.addAnnotation(res,newPName(pname.toString()));
        }
        for (String profile: a.getProfiles()) {
            super.addAnnotation(res,newProfile(profile));
        }
        for (URI type: a.getTypes()) {
            super.addAnnotation(res,newType(type.toString()));
        }
        if (a instanceof org.openprovenance.rdf.Artifact) {
            org.openprovenance.rdf.Artifact aa=(org.openprovenance.rdf.Artifact) a;
            for (org.openprovenance.rdf.AValue av: aa.getAvalues()) {
                if (av.getContent() instanceof XMLLiteral) {