use of eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ObjectFactory in project hale by halestudio.
the class TextEntityTray method createContents.
/**
* @see org.eclipse.jface.dialogs.DialogTray#createContents(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createContents(Composite parent) {
Composite page = new Composite(parent, SWT.NONE);
GridLayoutFactory.fillDefaults().applyTo(page);
Label label = new Label(page, SWT.NONE);
ObjectFactory of = new ObjectFactory();
JAXBElement<?> element = null;
if (entity instanceof PropertyType) {
element = of.createProperty((PropertyType) entity);
} else if (entity instanceof ClassType) {
element = of.createClass((ClassType) entity);
}
String text;
if (element != null) {
try {
JAXBContext jc = JAXBContext.newInstance(JaxbAlignmentIO.ALIGNMENT_CONTEXT, ObjectFactory.class.getClassLoader());
Marshaller m = jc.createMarshaller();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
m.marshal(element, doc);
text = XmlUtil.serialize((Element) doc.getFirstChild());
} catch (Exception e) {
text = e.getLocalizedMessage();
}
} else {
text = "###";
}
label.setText(text);
return page;
}
use of eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ObjectFactory in project hale by halestudio.
the class JaxbAlignmentIO method save.
/**
* Save a default alignment to an output stream.
*
* @param alignment the alignment to save
* @param reporter the I/O reporter to report any errors to, may be
* <code>null</code>
* @param out the output stream
* @throws Exception if converting or writing the alignment fails
*/
public static void save(AlignmentType alignment, IOReporter reporter, OutputStream out) throws Exception {
JAXBContext jc = JAXBContext.newInstance(ALIGNMENT_CONTEXT, ObjectFactory.class.getClassLoader());
Marshaller m = jc.createMarshaller();
// Indent output
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
// set ecndoing
m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
// Specify the schema location
// m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
// "http://knowledgeweb.semanticweb.org/heterogeneity/alignment align.xsd");
ObjectFactory of = new ObjectFactory();
try {
m.marshal(of.createAlignment(alignment), out);
} finally {
out.flush();
out.close();
}
}
use of eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ObjectFactory in project hale by halestudio.
the class JaxbAlignmentIO method printCell.
/**
* Print a cell to an output stream (intended for tests/debugging).
*
* @param cell the cell to print
* @param out the output stream
* @throws Exception if an error occurs trying to print the cell
*/
public static void printCell(MutableCell cell, OutputStream out) throws Exception {
DefaultAlignment alignment = new DefaultAlignment();
alignment.addCell(cell);
IOReporter reporter = new DefaultIOReporter(new Locatable() {
@Override
public URI getLocation() {
return null;
}
}, "Print cell", null, false);
PathUpdate pathUpdate = new PathUpdate(null, null);
AlignmentType at = convert(alignment, reporter, pathUpdate);
CellType ct = (CellType) at.getCellOrModifier().get(0);
JAXBContext jc = JAXBContext.newInstance(ALIGNMENT_CONTEXT, ObjectFactory.class.getClassLoader());
Marshaller m = jc.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
ObjectFactory of = new ObjectFactory();
try {
m.marshal(of.createCell(ct), out);
} finally {
out.flush();
out.close();
}
}
Aggregations