Search in sources :

Example 1 with PropertyType

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

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

the class FeatureChainingComplexTypeTest method testBackAndForth.

/**
 * Tests converting a feature chaining configuration to DOM and back.
 */
@Test
public void testBackAndForth() {
    FeatureChaining testConf = new FeatureChaining();
    TypeDefinition fakeType = new DefaultTypeDefinition(new QName(AppSchemaIO.APP_SCHEMA_NAMESPACE, "FakeType"));
    PropertyDefinition fakeProperty0 = new DefaultPropertyDefinition(new QName(AppSchemaIO.APP_SCHEMA_NAMESPACE, "fakeProperty0"), fakeType, new DefaultTypeDefinition(new QName("FakeNestedType0PropertyType")));
    PropertyDefinition fakeProperty1 = new DefaultPropertyDefinition(new QName(AppSchemaIO.APP_SCHEMA_NAMESPACE, "FakeNestedType0"), fakeType, new DefaultTypeDefinition(new QName("FakeNestedType0Type")));
    List<ChildContext> path0 = Arrays.asList(new ChildContext[] { new ChildContext(fakeProperty0), new ChildContext(fakeProperty1) });
    ChainConfiguration chain0 = new ChainConfiguration();
    chain0.setChainIndex(0);
    chain0.setPrevChainIndex(-1);
    chain0.setNestedTypeTarget(new PropertyEntityDefinition(fakeType, path0, SchemaSpaceID.TARGET, null));
    PropertyDefinition fakeProperty2 = new DefaultPropertyDefinition(new QName(AppSchemaIO.APP_SCHEMA_NAMESPACE, "fakeProperty1"), fakeType, new DefaultTypeDefinition(new QName("FakeNestedType1PropertyType")));
    PropertyDefinition fakeProperty3 = new DefaultPropertyDefinition(new QName(AppSchemaIO.APP_SCHEMA_NAMESPACE, "FakeNestedType1"), fakeType, new DefaultTypeDefinition(new QName("FakeNestedType1Type")));
    List<ChildContext> path1 = Arrays.asList(new ChildContext[] { new ChildContext(fakeProperty0), new ChildContext(fakeProperty1), new ChildContext(fakeProperty2), new ChildContext(fakeProperty3) });
    ChainConfiguration chain1 = new ChainConfiguration();
    chain1.setChainIndex(1);
    chain1.setPrevChainIndex(0);
    chain1.setNestedTypeTarget(new PropertyEntityDefinition(fakeType, path1, SchemaSpaceID.TARGET, null));
    chain1.setMappingName("fakeMapping");
    testConf.putChain("test-join", 0, chain0);
    testConf.putChain("test-join", 1, chain1);
    // convert to DOM
    Element fragment = HaleIO.getComplexElement(testConf);
    // convert back
    FeatureChaining converted = HaleIO.getComplexValue(fragment, FeatureChaining.class, null);
    assertNotNull(converted);
    assertFalse(converted.equals(testConf));
    Map<String, JoinConfiguration> joins = converted.getJoins();
    assertNotNull(joins);
    assertEquals(1, joins.size());
    JoinConfiguration join = joins.get("test-join");
    assertNotNull(join);
    assertEquals(2, join.getChains().size());
    ChainConfiguration convChain0 = join.getChain(0);
    assertNotNull(convChain0);
    assertEquals(0, convChain0.getChainIndex());
    assertEquals(-1, convChain0.getPrevChainIndex());
    assertTrue(convChain0.getMappingName() == null);
    PropertyType convPropertyType0 = convChain0.getJaxbNestedTypeTarget();
    assertNotNull(convPropertyType0);
    assertEquals("FakeType", convPropertyType0.getType().getName());
    assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType0.getType().getNs());
    assertEquals(2, convPropertyType0.getChild().size());
    assertEquals("fakeProperty0", convPropertyType0.getChild().get(0).getName());
    assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType0.getChild().get(0).getNs());
    assertEquals("FakeNestedType0", convPropertyType0.getChild().get(1).getName());
    assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType0.getChild().get(1).getNs());
    ChainConfiguration convChain1 = join.getChain(1);
    assertNotNull(convChain1);
    assertEquals(1, convChain1.getChainIndex());
    assertEquals(0, convChain1.getPrevChainIndex());
    assertEquals("fakeMapping", convChain1.getMappingName());
    PropertyType convPropertyType1 = convChain1.getJaxbNestedTypeTarget();
    assertNotNull(convPropertyType1);
    assertEquals("FakeType", convPropertyType1.getType().getName());
    assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType1.getType().getNs());
    assertEquals(4, convPropertyType1.getChild().size());
    assertEquals("fakeProperty0", convPropertyType1.getChild().get(0).getName());
    assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType1.getChild().get(0).getNs());
    assertEquals("FakeNestedType0", convPropertyType1.getChild().get(1).getName());
    assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType1.getChild().get(1).getNs());
    assertEquals("fakeProperty1", convPropertyType1.getChild().get(2).getName());
    assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType1.getChild().get(2).getNs());
    assertEquals("FakeNestedType1", convPropertyType1.getChild().get(3).getName());
    assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType1.getChild().get(3).getNs());
}
Also used : DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) PropertyType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.PropertyType) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) Test(org.junit.Test)

Example 3 with PropertyType

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

the class FeatureChainingComplexType method fromDOM.

/**
 * @see eu.esdihumboldt.hale.common.core.io.ComplexValueType#fromDOM(org.w3c.dom.Element,
 *      java.lang.Object)
 */
@Override
public FeatureChaining fromDOM(Element fragment, Void context) {
    FeatureChaining value = new FeatureChaining();
    if (fragment != null) {
        NodeList joinElList = fragment.getElementsByTagNameNS(APP_SCHEMA_NAMESPACE, "join");
        for (int i = 0; i < joinElList.getLength(); i++) {
            Element joinEl = (Element) joinElList.item(i);
            JoinConfiguration joinConf = new JoinConfiguration();
            joinConf.setJoinCellId(joinEl.getAttribute("id"));
            value.joins.put(joinConf.joinCellId, joinConf);
            NodeList chainElList = joinEl.getElementsByTagName("chain");
            for (int j = 0; j < chainElList.getLength(); j++) {
                Element chainEl = (Element) chainElList.item(j);
                ChainConfiguration chainConf = new ChainConfiguration();
                chainConf.setChainIndex(Integer.valueOf(chainEl.getAttribute("index")));
                chainConf.setPrevChainIndex(Integer.valueOf(chainEl.getAttribute("prevChainIndex")));
                Element nestedTypeTargetEl = getFirstElementByTagName(chainEl, "property", "http://www.esdi-humboldt.eu/hale/alignment");
                // I can't resolve the property entity definition here,
                // 'cause I've no target schema index available to perform
                // the resolution: I'll do it later, during the export
                PropertyType propertyType = propertyTypeFromDOM(nestedTypeTargetEl);
                chainConf.setJaxbNestedTypeTarget(propertyType);
                Element mappingNameEl = getFirstElementByTagName(chainEl, "mapping");
                if (mappingNameEl != null) {
                    String mappingName = mappingNameEl.getAttribute("name");
                    chainConf.setMappingName(mappingName);
                }
                joinConf.chains.put(chainConf.chainIndex, chainConf);
            }
        }
    }
    return value;
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) PropertyType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.PropertyType)

Example 4 with PropertyType

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

the class AppSchemaMappingUtils method propertyTypeFromDOM.

/**
 * Converts the given element to a JAXB property type. If any exception
 * occurs <code>null</code> is returned.
 *
 * @param fragment the fragment to convert
 * @return the property type or <code>null</code>
 */
public static PropertyType propertyTypeFromDOM(Element fragment) {
    try {
        JAXBContext jc = JAXBContext.newInstance(JaxbAlignmentIO.ALIGNMENT_CONTEXT, PropertyType.class.getClassLoader());
        Unmarshaller u = jc.createUnmarshaller();
        // it will debug problems while unmarshalling
        u.setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler());
        JAXBElement<PropertyType> root = u.unmarshal(fragment, PropertyType.class);
        return root.getValue();
    } catch (Exception e) {
        return null;
    }
}
Also used : JAXBContext(javax.xml.bind.JAXBContext) PropertyType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.PropertyType) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 5 with PropertyType

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

the class FeatureChainingComplexTypeTest method testRead.

/**
 * Test reading a feature chaining configuration from XML.
 *
 * @throws Exception if an error occurs during the test
 */
@Test
public void testRead() throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    DocumentBuilder builder = factory.newDocumentBuilder();
    Element root = builder.parse(getClass().getResourceAsStream(TEST_DATA)).getDocumentElement();
    // read
    FeatureChaining featureChaining = HaleIO.getComplexValue(root, FeatureChaining.class, null);
    assertNotNull(featureChaining);
    Map<String, JoinConfiguration> joins = featureChaining.getJoins();
    assertNotNull(joins);
    assertEquals(1, joins.size());
    JoinConfiguration join = joins.get("Cd4e57fb5-a411-4721-a29a-19343b853a12");
    assertNotNull(join);
    Map<Integer, ChainConfiguration> chains = join.getChains();
    assertNotNull(chains);
    assertEquals(5, chains.size());
    ChainConfiguration chain0 = chains.get(0);
    assertEquals(0, chain0.getChainIndex());
    assertEquals(-1, chain0.getPrevChainIndex());
    assertTrue(chain0.getMappingName() == null);
    PropertyType target0 = chain0.getJaxbNestedTypeTarget();
    assertNotNull(target0);
    assertEquals(GEOLOGIC_UNIT_TYPE, target0.getType().getName());
    assertEquals(GEOSCIML_NS, target0.getType().getNs());
    assertNotNull(target0.getChild());
    assertEquals(2, target0.getChild().size());
    assertEquals("composition", target0.getChild().get(0).getName());
    assertEquals(GEOSCIML_NS, target0.getChild().get(0).getNs());
    assertEquals("CompositionPart", target0.getChild().get(1).getName());
    assertEquals(GEOSCIML_NS, target0.getChild().get(1).getNs());
    ChainConfiguration chain1 = chains.get(1);
    assertEquals(1, chain1.getChainIndex());
    assertEquals(-1, chain1.getPrevChainIndex());
    assertTrue(chain1.getMappingName() == null);
    PropertyType target1 = chain1.getJaxbNestedTypeTarget();
    assertNotNull(target1);
    assertEquals(GEOLOGIC_UNIT_TYPE, target1.getType().getName());
    assertEquals(GEOSCIML_NS, target1.getType().getNs());
    assertNotNull(target1.getChild());
    assertEquals(3, target1.getChild().size());
    assertEquals("occurrence", target1.getChild().get(0).getName());
    assertEquals(GEOSCIML_NS, target1.getChild().get(0).getNs());
    assertEquals("choice", target1.getChild().get(1).getName());
    assertEquals("urn:cgi:xmlns:CGI:GeoSciML:2.0/MappedFeature", target1.getChild().get(1).getNs());
    assertEquals("MappedFeature", target1.getChild().get(2).getName());
    assertEquals(GEOSCIML_NS, target1.getChild().get(2).getNs());
    ChainConfiguration chain2 = chains.get(2);
    assertEquals(2, chain2.getChainIndex());
    assertEquals(-1, chain2.getPrevChainIndex());
    assertTrue(chain2.getMappingName() == null);
    PropertyType target2 = chain2.getJaxbNestedTypeTarget();
    assertNotNull(target2);
    assertEquals(GEOLOGIC_UNIT_TYPE, target2.getType().getName());
    assertEquals(GEOSCIML_NS, target2.getType().getNs());
    assertNotNull(target2.getChild());
    assertEquals(3, target2.getChild().size());
    assertEquals("geologicHistory", target2.getChild().get(0).getName());
    assertEquals(GEOSCIML_NS, target2.getChild().get(0).getNs());
    assertEquals("choice", target2.getChild().get(1).getName());
    assertEquals("urn:cgi:xmlns:CGI:GeoSciML:2.0/GeologicEvent", target2.getChild().get(1).getNs());
    assertEquals("GeologicEvent", target2.getChild().get(2).getName());
    assertEquals(GEOSCIML_NS, target2.getChild().get(2).getNs());
    ChainConfiguration chain3 = chains.get(3);
    assertEquals(3, chain3.getChainIndex());
    assertEquals(2, chain3.getPrevChainIndex());
    assertEquals("c41266fa-ca85-46bb-b93f-e38d9abec0c7", chain3.getMappingName());
    PropertyType target3 = chain3.getJaxbNestedTypeTarget();
    assertNotNull(target3);
    assertEquals(GEOLOGIC_UNIT_TYPE, target3.getType().getName());
    assertEquals(GEOSCIML_NS, target3.getType().getNs());
    assertNotNull(target3.getChild());
    assertEquals(5, target3.getChild().size());
    assertEquals("geologicHistory", target3.getChild().get(0).getName());
    assertEquals(GEOSCIML_NS, target3.getChild().get(0).getNs());
    assertEquals("choice", target3.getChild().get(1).getName());
    assertEquals("urn:cgi:xmlns:CGI:GeoSciML:2.0/GeologicEvent", target3.getChild().get(1).getNs());
    assertEquals("GeologicEvent", target3.getChild().get(2).getName());
    assertEquals(GEOSCIML_NS, target3.getChild().get(2).getNs());
    assertEquals("eventProcess", target3.getChild().get(3).getName());
    assertEquals(GEOSCIML_NS, target3.getChild().get(3).getNs());
    assertEquals("CGI_TermValue", target3.getChild().get(4).getName());
    assertEquals(GEOSCIML_NS, target3.getChild().get(4).getNs());
    ChainConfiguration chain4 = chains.get(4);
    assertEquals(4, chain4.getChainIndex());
    assertEquals(2, chain4.getPrevChainIndex());
    assertEquals("cbb4baa5-79d9-4012-95d8-d1574628761b", chain4.getMappingName());
    PropertyType target4 = chain4.getJaxbNestedTypeTarget();
    assertNotNull(target4);
    assertEquals(GEOLOGIC_UNIT_TYPE, target4.getType().getName());
    assertEquals(GEOSCIML_NS, target4.getType().getNs());
    assertNotNull(target4.getChild());
    assertEquals(5, target4.getChild().size());
    assertEquals("geologicHistory", target4.getChild().get(0).getName());
    assertEquals(GEOSCIML_NS, target4.getChild().get(0).getNs());
    assertEquals("choice", target4.getChild().get(1).getName());
    assertEquals("urn:cgi:xmlns:CGI:GeoSciML:2.0/GeologicEvent", target4.getChild().get(1).getNs());
    assertEquals("GeologicEvent", target4.getChild().get(2).getName());
    assertEquals(GEOSCIML_NS, target4.getChild().get(2).getNs());
    assertEquals("eventEnvironment", target4.getChild().get(3).getName());
    assertEquals(GEOSCIML_NS, target4.getChild().get(3).getNs());
    assertEquals("CGI_TermValue", target4.getChild().get(4).getName());
    assertEquals(GEOSCIML_NS, target4.getChild().get(4).getNs());
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) PropertyType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.PropertyType) Test(org.junit.Test)

Aggregations

PropertyType (eu.esdihumboldt.hale.common.align.io.impl.internal.generated.PropertyType)6 Element (org.w3c.dom.Element)4 JAXBContext (javax.xml.bind.JAXBContext)3 Unmarshaller (javax.xml.bind.Unmarshaller)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 Test (org.junit.Test)2 ClassType (eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ClassType)1 ObjectFactory (eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ObjectFactory)1 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)1 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)1 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)1 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)1 DefaultPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition)1 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)1 JAXBElement (javax.xml.bind.JAXBElement)1 Marshaller (javax.xml.bind.Marshaller)1 QName (javax.xml.namespace.QName)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1