Search in sources :

Example 1 with AlignmentType

use of eu.esdihumboldt.hale.io.oml.internal.model.generated.oml.AlignmentType in project hale by halestudio.

the class OmlRdfGenerator method write.

/**
 * Stores alignment to xml
 *
 * @param alignment , to be stored
 * @param xmlPath , path to the xml-file
 * @throws JAXBException
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public void write(IAlignment alignment, String xmlPath) throws JAXBException {
    // 1. convert OML Alignment to the jaxb generated AlignmentType
    AlignmentType aType = getAlignment(alignment);
    // 2. marshall AlignmentType to xml
    JAXBContext jc = JAXBContext.newInstance(ALIGNMENT_CONTEXT, ObjectFactory.class.getClassLoader());
    Marshaller m = jc.createMarshaller();
    configurePrefixMapper(m);
    // make the output indented. It looks nicer on screen.
    // this is a JAXB standard property, so it should work with any JAXB
    // impl.
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://knowledgeweb.semanticweb.org/heterogeneity/alignment align.xsd");
    m.marshal(new JAXBElement(new QName("http://knowledgeweb.semanticweb.org/heterogeneity/alignment", "Alignment", "align"), AlignmentType.class, aType), new File(xmlPath));
/*
		 * try { URLConnection connection = new URL("file", null,
		 * xmlPath).openConnection(); connection.setDoOutput(true);
		 * 
		 * m.marshal(new JAXBElement(new
		 * QName("http://knowledgeweb.semanticweb.org/heterogeneity/alignment",
		 * "Alignment", "align"), AlignmentType.class, aType),
		 * connection.getOutputStream()); } catch (MalformedURLException e) { //
		 * TODO Auto-generated catch block e.printStackTrace(); } catch
		 * (IOException e) { // TODO Auto-generated catch block
		 * e.printStackTrace(); }
		 */
}
Also used : AlignmentType(eu.esdihumboldt.hale.io.oml.internal.model.generated.oml.AlignmentType) Marshaller(javax.xml.bind.Marshaller) ObjectFactory(eu.esdihumboldt.hale.io.oml.internal.model.generated.oml.ObjectFactory) QName(javax.xml.namespace.QName) JAXBContext(javax.xml.bind.JAXBContext) JAXBElement(javax.xml.bind.JAXBElement) File(java.io.File)

Example 2 with AlignmentType

use of eu.esdihumboldt.hale.io.oml.internal.model.generated.oml.AlignmentType in project hale by halestudio.

the class OmlRdfReader method read.

/**
 * Unmarshalls oml-mapping to the HUMBOLDT Alignment.
 *
 * @param rdfFile path to the oml-mapping file
 * @return Alignment object
 */
public Alignment read(URL rdfFile) {
    // 1. unmarshal rdf
    JAXBContext jc;
    JAXBElement<AlignmentType> root = null;
    try {
        jc = JAXBContext.newInstance(ALIGNMENT_CONTEXT, ObjectFactory.class.getClassLoader());
        Unmarshaller u = jc.createUnmarshaller();
        // it will debug problems while unmarshalling
        u.setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler());
        root = u.unmarshal(new StreamSource(rdfFile.openStream()), AlignmentType.class);
    /*
			 * root = u.unmarshal(new StreamSource(new File(rdfFile)),
			 * AlignmentType.class);
			 */
    } catch (Exception e) {
        throw new IllegalStateException("Failed to read alignment", e);
    }
    AlignmentType genAlignment = root.getValue();
    // 2. create humboldt alignment object and fulfill the required fields
    Alignment al = new Alignment();
    // set about
    al.setAbout(new About(UUID.randomUUID()));
    // set level
    if (genAlignment.getLevel() != null) {
        al.setLevel(genAlignment.getLevel());
    }
    // set map with cells
    if (genAlignment.getMap() != null) {
        al.setMap(getMap(genAlignment.getMap()));
    }
    // set schema1,2 containing information about ontologies1,2
    if (genAlignment.getOnto1() != null && genAlignment.getOnto1().getOntology() != null) {
        al.setSchema1(getSchema(genAlignment.getOnto1().getOntology()));
    }
    if (genAlignment.getOnto2() != null && genAlignment.getOnto2().getOntology() != null) {
        al.setSchema2(getSchema(genAlignment.getOnto2().getOntology()));
    }
    // set Value Class
    if (genAlignment.getValueClass() != null) {
        al.setValueClass(getValueClass(genAlignment.getValueClass()));
    }
    return al;
}
Also used : AlignmentType(eu.esdihumboldt.hale.io.oml.internal.model.generated.oml.AlignmentType) Alignment(eu.esdihumboldt.hale.io.oml.internal.goml.align.Alignment) StreamSource(javax.xml.transform.stream.StreamSource) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) About(eu.esdihumboldt.hale.io.oml.internal.goml.rdf.About) IAbout(eu.esdihumboldt.hale.io.oml.internal.model.rdf.IAbout)

Aggregations

AlignmentType (eu.esdihumboldt.hale.io.oml.internal.model.generated.oml.AlignmentType)2 JAXBContext (javax.xml.bind.JAXBContext)2 Alignment (eu.esdihumboldt.hale.io.oml.internal.goml.align.Alignment)1 About (eu.esdihumboldt.hale.io.oml.internal.goml.rdf.About)1 ObjectFactory (eu.esdihumboldt.hale.io.oml.internal.model.generated.oml.ObjectFactory)1 IAbout (eu.esdihumboldt.hale.io.oml.internal.model.rdf.IAbout)1 File (java.io.File)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 JAXBElement (javax.xml.bind.JAXBElement)1 Marshaller (javax.xml.bind.Marshaller)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 QName (javax.xml.namespace.QName)1 StreamSource (javax.xml.transform.stream.StreamSource)1