Search in sources :

Example 1 with ClassType

use of eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ClassType 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 ClassType

use of eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ClassType in project hale by halestudio.

the class DOMEntityDefinitionHelper method typeFromDOM.

/**
 * Converts the given element to a type entity definition. If any exception
 * occurs <code>null</code> is returned.
 *
 * @param fragment the fragment to convert
 * @param types the type index to use for unmarshalling
 * @param ssid the schema space to use for unmarshalling
 * @return the type entity definition or <code>null</code>
 */
public static TypeEntityDefinition typeFromDOM(Element fragment, TypeIndex types, SchemaSpaceID ssid) {
    try {
        JAXBContext jc = JAXBContext.newInstance(JaxbAlignmentIO.ALIGNMENT_CONTEXT, ClassType.class.getClassLoader());
        Unmarshaller u = jc.createUnmarshaller();
        // it will debug problems while unmarshalling
        u.setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler());
        JAXBElement<ClassType> root = u.unmarshal(fragment, ClassType.class);
        return resolver.resolveType(root.getValue(), types, ssid).getDefinition();
    } catch (Exception e) {
        return null;
    }
}
Also used : JAXBContext(javax.xml.bind.JAXBContext) ClassType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ClassType) Unmarshaller(javax.xml.bind.Unmarshaller)

Aggregations

ClassType (eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ClassType)2 JAXBContext (javax.xml.bind.JAXBContext)2 ObjectFactory (eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ObjectFactory)1 PropertyType (eu.esdihumboldt.hale.common.align.io.impl.internal.generated.PropertyType)1 JAXBElement (javax.xml.bind.JAXBElement)1 Marshaller (javax.xml.bind.Marshaller)1 Unmarshaller (javax.xml.bind.Unmarshaller)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