Search in sources :

Example 1 with ObjectFactory

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;
}
Also used : Marshaller(javax.xml.bind.Marshaller) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Composite(org.eclipse.swt.widgets.Composite) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) Label(org.eclipse.swt.widgets.Label) JAXBContext(javax.xml.bind.JAXBContext) PropertyType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.PropertyType) ClassType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ClassType) Document(org.w3c.dom.Document) ObjectFactory(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ObjectFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder)

Example 2 with ObjectFactory

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();
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) ObjectFactory(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ObjectFactory) JAXBContext(javax.xml.bind.JAXBContext)

Example 3 with ObjectFactory

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();
    }
}
Also used : AlignmentType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.AlignmentType) DefaultIOReporter(eu.esdihumboldt.hale.common.core.io.report.impl.DefaultIOReporter) IOReporter(eu.esdihumboldt.hale.common.core.io.report.IOReporter) Marshaller(javax.xml.bind.Marshaller) DefaultIOReporter(eu.esdihumboldt.hale.common.core.io.report.impl.DefaultIOReporter) ObjectFactory(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ObjectFactory) CellType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.CellType) PathUpdate(eu.esdihumboldt.hale.common.core.io.PathUpdate) DefaultAlignment(eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment) JAXBContext(javax.xml.bind.JAXBContext) URI(java.net.URI) Locatable(eu.esdihumboldt.hale.common.core.io.supplier.Locatable)

Aggregations

ObjectFactory (eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ObjectFactory)3 JAXBContext (javax.xml.bind.JAXBContext)3 Marshaller (javax.xml.bind.Marshaller)3 AlignmentType (eu.esdihumboldt.hale.common.align.io.impl.internal.generated.AlignmentType)1 CellType (eu.esdihumboldt.hale.common.align.io.impl.internal.generated.CellType)1 ClassType (eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ClassType)1 PropertyType (eu.esdihumboldt.hale.common.align.io.impl.internal.generated.PropertyType)1 DefaultAlignment (eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment)1 PathUpdate (eu.esdihumboldt.hale.common.core.io.PathUpdate)1 IOReporter (eu.esdihumboldt.hale.common.core.io.report.IOReporter)1 DefaultIOReporter (eu.esdihumboldt.hale.common.core.io.report.impl.DefaultIOReporter)1 Locatable (eu.esdihumboldt.hale.common.core.io.supplier.Locatable)1 URI (java.net.URI)1 JAXBElement (javax.xml.bind.JAXBElement)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1