Search in sources :

Example 1 with InvalidVCIDException

use of cbit.vcell.biomodel.meta.VCID.InvalidVCIDException in project vcell by virtualcell.

the class XMLMetaDataReader method readFromElement.

@SuppressWarnings("unchecked")
public static void readFromElement(VCMetaData metaData, IdentifiableProvider identifiableProvider, Element metadataElement) throws XmlParseException {
    Element bindingElement = metadataElement.getChild(XMLMetaData.URI_BINDING_LIST_TAG, VCMetaData.nsVCML);
    if (bindingElement != null) {
        // read binding
        List<Element> entryElements = bindingElement.getChildren(XMLMetaData.URI_BINDING_TAG, VCMetaData.nsVCML);
        for (Iterator<Element> iterator = entryElements.iterator(); iterator.hasNext(); ) {
            Element entryElement = iterator.next();
            try {
                String uri = entryElement.getAttributeValue(XMLMetaData.URI_ATTR_TAG);
                String vcidString = entryElement.getAttributeValue(XMLMetaData.VCID_ATTR_TAG);
                // make new entry based on URI
                // create VCID
                VCID vcid = VCID.fromString(vcidString);
                // lookup Identifiable object using VCID ... add to entry.
                metaData.getRegistry().newEntry(metaData.getRdfData(), identifiableProvider.getIdentifiableObject(vcid), uri);
            } catch (VCID.InvalidVCIDException e) {
                e.printStackTrace();
                throw new XmlParseException(e);
            }
        }
    }
    Element rdfElement = metadataElement.getChild(XMLRDF.tagRDF, XMLRDF.nsRDF);
    if (rdfElement != null) {
        // read RDF
        try {
            metaData.addToModelFromElement(rdfElement);
        } catch (RDFParseException e) {
            e.printStackTrace();
            throw new XmlParseException(e.getMessage());
        } catch (RDFHandlerException e) {
            e.printStackTrace();
            throw new XmlParseException(e.getMessage());
        } catch (IOException e) {
            e.printStackTrace();
            throw new XmlParseException(e.getMessage());
        }
    }
    Element nonRDFAnnotationListElement = metadataElement.getChild(XMLMetaData.NONRDF_ANNOTATION_LIST_TAG, VCMetaData.nsVCML);
    if (nonRDFAnnotationListElement != null) {
        List<Element> nonRDFAnnotationElements = nonRDFAnnotationListElement.getChildren(XMLMetaData.NONRDF_ANNOTATION_TAG, VCMetaData.nsVCML);
        for (Element nonRDFAnnotationElement : nonRDFAnnotationElements) {
            String vcidString = nonRDFAnnotationElement.getAttributeValue(XMLMetaData.VCID_ATTR_TAG);
            VCID vcid = null;
            try {
                vcid = VCID.fromString(vcidString);
            } catch (InvalidVCIDException e) {
                e.printStackTrace();
                throw new XmlParseException(e.getMessage());
            }
            Identifiable identifiable = identifiableProvider.getIdentifiableObject(vcid);
            if (identifiable != null) {
                // populate the annotation
                Element freeTextAnnotationElement = nonRDFAnnotationElement.getChild(XMLMetaData.FREETEXT_TAG, VCMetaData.nsVCML);
                if (freeTextAnnotationElement != null) {
                    String freeText = freeTextAnnotationElement.getText();
                    metaData.setFreeTextAnnotation(identifiable, freeText);
                }
                Element xhtmlNotesElement = nonRDFAnnotationElement.getChild(XMLMetaData.NOTES_TAG, VCMetaData.nsVCML);
                if (xhtmlNotesElement != null) {
                    metaData.setXhtmlNotes(identifiable, xhtmlNotesElement);
                }
                Element annotationListElement = nonRDFAnnotationElement.getChild(XMLMetaData.ANNOTATION_LIST_TAG, VCMetaData.nsVCML);
                if (annotationListElement != null) {
                    List<?> annotationContents = annotationListElement.getContent();
                    List<Element> annotationElements = new ArrayList<Element>();
                    for (int i = 0; i < annotationContents.size(); i++) {
                        if (annotationContents.get(i) instanceof Element) {
                            annotationElements.add((Element) annotationContents.get(i));
                        }
                    }
                    metaData.setXmlAnnotations(identifiable, annotationElements.toArray(new Element[annotationElements.size()]));
                }
            } else {
                System.err.println("Cannot find identifiable for vcid : " + vcidString);
            }
        }
    }
}
Also used : VCID(cbit.vcell.biomodel.meta.VCID) Element(org.jdom.Element) ArrayList(java.util.ArrayList) XmlParseException(cbit.vcell.xml.XmlParseException) IOException(java.io.IOException) InvalidVCIDException(cbit.vcell.biomodel.meta.VCID.InvalidVCIDException) Identifiable(org.vcell.util.document.Identifiable) RDFHandlerException(org.openrdf.rio.RDFHandlerException) InvalidVCIDException(cbit.vcell.biomodel.meta.VCID.InvalidVCIDException) RDFParseException(org.openrdf.rio.RDFParseException)

Aggregations

VCID (cbit.vcell.biomodel.meta.VCID)1 InvalidVCIDException (cbit.vcell.biomodel.meta.VCID.InvalidVCIDException)1 XmlParseException (cbit.vcell.xml.XmlParseException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Element (org.jdom.Element)1 RDFHandlerException (org.openrdf.rio.RDFHandlerException)1 RDFParseException (org.openrdf.rio.RDFParseException)1 Identifiable (org.vcell.util.document.Identifiable)1