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(); }
*/
}
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;
}
Aggregations